0
votes

How do I deploy swagger from ARM Template to Azure API Management using the option "contentFormat": "swagger-json"

https://docs.microsoft.com/en-us/azure/templates/microsoft.apimanagement/2018-06-01-preview/service/apis

    "contentFormat": "swagger-json",
    "contentValue": "D:\\tempvsts\\APISwagger\\APISwagger\\swagger.json",

When I run this I get the following error

"message": "Parsing error(s): Unexpected character encountered while parsing value: D. Path '', line 0, position 0."

Please note I have used the below option and it works

"contentFormat": "swagger-link-json",

Full ARM template

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "ApimServiceName": {
      "type": "string"
    }
  },
  "variables": {
  },
  "resources": [
    {
      "type": "Microsoft.ApiManagement/service/apis",
      "name": "[concat(parameters('ApimServiceName'), '/animalAPI4')]",
      "apiVersion": "2018-06-01-preview",
      "scale": null,
      "properties": {
        "displayName": "HTTP animal API",
        "apiRevision": "1",
        "description": "API Management facade for a very handy and free online HTTP toolsds",
        "serviceUrl": "https://animailhttpbin.org",
        "path": "animals4",
        "contentFormat": "swagger-json",
        "contentValue": "D:\\tempvsts\\APISwagger\\APISwagger\\swagger.json",
        "apiVersionSet": {
          "id": "[concat(resourceId('Microsoft.ApiManagement/service', parameters('ApimServiceName')), '/api-version-sets/versionset-animal-api4')]"
        },
        "protocols": [
          "https"
        ],
        "authenticationSettings": null,
        "subscriptionKeyParameterNames": null,
        "apiVersion": "v1"
      },
      "dependsOn": [
      ]
    }

  ]
}
1
i would expect you to provide content value there, not just path on your local hdd, it wont work4c74356b41

1 Answers

2
votes

Like 4c74356b41 mentioned, the JSON content value as an escaped string has to be used.

Your swagger JSON would be something like this

{ "swagger":"2.0", ... }

So, it would go into your ARM template like this

{
  ...
  "contentFormat": "swagger-json",
  "contentValue": "{ \"swagger\":\"2.0\", ... }",
  ...
}