如何使用“ contentFormat”:“ swagger-json”将

时间:2019-04-09 01:05:40

标签: azure-resource-manager azure-api-management

如何使用选项“ contentFormat”:“ swagger-json”将swagger从ARM模板部署到Azure API管理

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",

运行此命令时,出现以下错误

  

“ message”:“解析错误:遇到意外字符   解析值:D.路径”,行0,位置0。”

请注意,我已经使用了以下选项,并且有效

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

完整的ARM模板

{
  "$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 个答案:

答案 0 :(得分:0)

就像提到的4c74356b41一样,必须使用JSON内容值作为转义字符串。

您不快的JSON就是这样

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

因此,它将像这样进入您的ARM模板

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