azure - 使用 swagger 将模板部署到 Azure API 管理失败,并显示 'path' 不能为空

标签 azure swagger azure-api-management

我正在尝试使用 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/

相关文章:

android - java.lang.NoClassDefFoundError : org/apache/oltu/oauth2/client/request/OAuthClientRequest$TokenRequestBuilder

Azure APIM 在一个实例中设置多个环境

azure - 从 Azure 恢复应用服务

aws-lambda - 将 Swagger API 验证与无服务器框架结合使用

arrays - Azure CLI 列出具有关联公共(public) IP 的 VM

java - 如何根据yml文件生成resttemplate?

Azure APIM 策略改变有效负载主体

json - 如何使用 python 运行 Azure Log Analytics 查询 api?

sql-server - 弹性池的 VCore 扩展(例如从 2 到 4)与使用 VCore 创建新池 (4) 和移动数据库的延迟

c# - Azure Web 应用程序间歇性崩溃