问题调用azurerm_api_management _api_operation与uri参数
我正在尝试导入API操作(使用Swagger JSON规格)。但是,它抱怨我的URI参数。我有点不知所措。
这是我的Terraform片段,带有Swagger/Open API规格:
resource "azurerm_api_management_api" "sample_api_v2" {
name = "sample-api-v2"
resource_group_name = data.azurerm_resource_group.rg_name
api_management_name = module.abc01.name
revision = "1"
display_name = "Sample Data API v2"
path = "Sample-data/v2"
protocols = ["https"]
version = "v2"
version_set_id = azurerm_api_management_api_version_set.sample-api-version-set.id
import {
content_format = "openapi+json"
content_value = <<JSON
{
"openapi": "3.0.1",
"info": {
"title": "Sample API v2",
"description": "Sample Data API v2",
"contact": {
"name": "John Smith",
"email": "[email protected]"
},
"version": "v2"
},
"servers": [
{
"url": "https://my-api.example.com/sample-api/v2"
}
],
"paths": {
"/businesses/{abn}": {
"get": {
"summary": "Get Businesses",
"description": "Retrieve the abn information of the business with the matching abn number",
"operationId": "get-business-by-abn",
"parameters": [
{
"name": "abn",
"in": "path",
"required": true,
"schema": {
"type": "number"
}
}
],
"responses": {
"200": {
"description": "ABN Found"
}
}
}
}
},
"components": {
"securitySchemes": {
"apiKeyQuery": {
"type": "apiKey",
"name": "subscription-key",
"in": "query"
}
}
},
"security": [
{
"apiKeyQuery": []
}
]
}
JSON
}
}
azurerm_api_management_api_operation block定义为:
resource "azurerm_api_management_api_operation" "get_business_by_abn_v2" {
operation_id = "get-business-by-abn"
api_name = azurerm_api_management_api.sample_api_v2.name
api_management_name = module.abc01.name
resource_group_name = data.azurerm_resource_group.rg_name
display_name = "Lookup business by ABN"
method = "GET"
url_template = "/businesses/{abn}"
description = "Lookup a business by ABN Number"
response {
status_code = 200
}
}
我遇到的错误是:我已经
: apimanagement.APIOperationClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"All template parameters used in the UriTemplate must be defined in the Operation, and vice-versa.","target":"templateParameters"}]
完成了以下操作:我已经完成了以下内容:
- 验证了规格
- 我已经在Swagger在线编辑器 明确定义了参数块以匹配路径:
{
"name": "abn",
"in": "path",
"required": true,
"schema": {
"type": "number"
}
}
我发现这仅在URI参数中发生。对于我带有查询参数的其他API,此问题不会发生。
谁能建议可能出了什么问题?谢谢。
i am trying to import an API operation (with Swagger JSON spec). However, its complaining of my URI parameter. I am a bit at loss as what its complaining about.
Here is my Terraform snippet with the swagger/Open API spec:
resource "azurerm_api_management_api" "sample_api_v2" {
name = "sample-api-v2"
resource_group_name = data.azurerm_resource_group.rg_name
api_management_name = module.abc01.name
revision = "1"
display_name = "Sample Data API v2"
path = "Sample-data/v2"
protocols = ["https"]
version = "v2"
version_set_id = azurerm_api_management_api_version_set.sample-api-version-set.id
import {
content_format = "openapi+json"
content_value = <<JSON
{
"openapi": "3.0.1",
"info": {
"title": "Sample API v2",
"description": "Sample Data API v2",
"contact": {
"name": "John Smith",
"email": "[email protected]"
},
"version": "v2"
},
"servers": [
{
"url": "https://my-api.example.com/sample-api/v2"
}
],
"paths": {
"/businesses/{abn}": {
"get": {
"summary": "Get Businesses",
"description": "Retrieve the abn information of the business with the matching abn number",
"operationId": "get-business-by-abn",
"parameters": [
{
"name": "abn",
"in": "path",
"required": true,
"schema": {
"type": "number"
}
}
],
"responses": {
"200": {
"description": "ABN Found"
}
}
}
}
},
"components": {
"securitySchemes": {
"apiKeyQuery": {
"type": "apiKey",
"name": "subscription-key",
"in": "query"
}
}
},
"security": [
{
"apiKeyQuery": []
}
]
}
JSON
}
}
The azurerm_api_management_api_operation
block is defined as:
resource "azurerm_api_management_api_operation" "get_business_by_abn_v2" {
operation_id = "get-business-by-abn"
api_name = azurerm_api_management_api.sample_api_v2.name
api_management_name = module.abc01.name
resource_group_name = data.azurerm_resource_group.rg_name
display_name = "Lookup business by ABN"
method = "GET"
url_template = "/businesses/{abn}"
description = "Lookup a business by ABN Number"
response {
status_code = 200
}
}
The error I am getting is:
: apimanagement.APIOperationClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"All template parameters used in the UriTemplate must be defined in the Operation, and vice-versa.","target":"templateParameters"}]
I have done the following:
- I have validated the Spec in Swagger online editor
- The parameters block is clearly defined to match the path:
{
"name": "abn",
"in": "path",
"required": true,
"schema": {
"type": "number"
}
}
I am finding this is only happening with URI params. For my other APIs with query parameters this problem doesn't happen.
Can anyone please suggest what might be going wrong? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它以URI参数显示您也必须在Terraform中指定:
请参阅下面的
template_parameter
块:在我的试验中&amp;错误,它不在乎是否指定查询参数。但是,必须在Open API规范和Terraform资源中通过
Template_Parameter
部分指定URI参数。It appears with URI params you must specify it in the Terraform as well:
Refer to the
template_parameter
block below:In my trial & error, it doesnt care if query params dont get specified. But URI params must be specified in both Open API specification and the Terraform resource via
template_parameter
section.