如何使用“内容格式”将swagger从Arm模板部署到Azure API管理:“swagger-json”

问题描述 投票:0回答:1

如何使用“contentFormat”选项将swagger从ARM模板部署到Azure API Management:“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",

当我运行这个时,我得到以下错误

“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": [
      ]
    }

  ]
}
azure-resource-manager azure-api-management
1个回答
0
投票

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

你的招摇JSON就是这样的

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

所以,它会像这样进入你的ARM模板

{
  ...
  "contentFormat": "swagger-json",
  "contentValue": "{ \"swagger\":\"2.0\", ... }",
  ...
}
© www.soinside.com 2019 - 2024. All rights reserved.