我正在尝试使用 swagger 导入功能在 azure API 管理中创建 API 和操作,并使用从 https://learn.microsoft.com/en-us/azure/templates/microsoft.apimanagement/2018-01-01/service/apis 的文档派生的模板。
每次我使用 Azure 资源管理器模板将 API 部署到 Azure API 管理时,都会收到错误“路径”不能为空
。我究竟做错了什么?路径绝对不为空!
对于此示例,您可以仅使用任何有效的 swagger 文件内容,例如 https://petstore.swagger.io/v2/swagger.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"apim_name": {
"type": "string"
},
"api_name": {
"type": "string"
},
"swagger_json": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.ApiManagement/service/apis",
"name": "[concat(parameters('apim_name'), '/' ,parameters('api_name'))]",
"apiVersion": "2018-06-01-preview",
"properties": {
"displayName": "Pet Store",
"description": "Cool api def",
"serviceUrl": "https://petstore.swagger.io/v2",
"path": "petstore",
"protocols": [
"https"
],
"authenticationSettings": {
"oAuth2": null,
"openid": null,
"subscriptionKeyRequired": true
},
"subscriptionKeyParameterNames": {
"header": "Ocp-Apim-Subscription-Key",
"query": "subscription-key"
},
"contentValue": "[parameters('swagger_json')]",
"contentFormat": "swagger-json"
}
}
]
}
最佳答案
在使用 swagger 导入功能时,API 管理资源管理器 API 似乎对参数很挑剔,并且文档和错误消息有点缺乏。
secret 在于,swagger 文件定义替换了您通常在模板中为 API 传递的大部分属性,因此您需要一个大大简化的模板,如下所示。
希望这对其他人有帮助!
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"apim_name": {
"type": "string"
},
"api_name": {
"type": "string"
},
"swagger_json": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.ApiManagement/service/apis",
"name": "[concat(parameters('apim_name'), '/' ,parameters('api_name'))]",
"apiVersion": "2018-06-01-preview",
"properties": {
"path": "petstore",
"contentValue": "[parameters('swagger_json')]",
"contentFormat": "swagger-json"
}
}
]
}
关于azure - 使用 swagger 将模板部署到 Azure API 管理失败,并显示 'path' 不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54463881/