挥舞到Azure API管理的模板部署失败,并且“路径”不能为空

时间:2019-01-31 15:25:25

标签: azure swagger azure-api-management

我正在尝试使用从https://docs.microsoft.com/en-us/azure/templates/microsoft.apimanagement/2018-01-01/service/apis处的加倍衍生而来的模板,使用招摇导入功能在azure API管理中创建API和操作。

每次我使用Azure资源管理器模板将API部署到Azure API管理时,都会收到错误'path' must not be empty。我究竟做错了什么?路径绝对不是空的!

在此示例中,您可以仅使用任何有效的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"
            }
        }
    ]
}

1 个答案:

答案 0 :(得分:3)

当使用swagger导入功能时,API管理资源管理器API似乎对参数非常挑剔,并且缺少文档和错误消息。

秘密在于,庞大的文件定义将替换通常为模板中的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"
            }
        }
    ]
}