1
votes

I am trying to create an API and operations in azure API management using the swagger import feature, using a template derived from the doumentation at https://docs.microsoft.com/en-us/azure/templates/microsoft.apimanagement/2018-01-01/service/apis

Every time I deploy my API using my Azure Resource manager template to Azure API management I get the error 'path' must not be empty. What am I doing wrong? Path is definitely not empty!

For this example you can just use any valid swagger file contents such as at 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

1 Answers

4
votes

It seems the API management resource manager APIs are fussy about parameters when using the swagger import feature and the docs and error messages are a little lacking.

The secret is that the swagger file definition replaces most of the properties you would normally pass for an API in the template so you need a much reduced template, as below.

Hope this helps someone else!

{
    "$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"
            }
        }
    ]
}