【问题标题】:How to version an API in Azure API Management using Azure Resource Manager如何使用 Azure 资源管理器在 Azure API 管理中对 API 进行版本控制
【发布时间】:2018-02-07 12:13:27
【问题描述】:

使用门户在 Azure API 管理服务中创建新 API 时,您可以指定是否要对 API 进行版本控制。但是,在使用 ARM 在管理服务中创建 API 时,我找不到复制此操作的方法。这是目前不支持,还是我遗漏了什么?

我尝试在门户中创建版本化 API,并将创建的模板与非版本化 API 的模板进行比较,但看不出有什么区别。

提前致谢。

【问题讨论】:

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


    【解决方案1】:

    要通过 ARM 脚本实现这一点,您需要先创建一个 ApiVersionSet 资源:

    {
        "name": "[concat(variables('ManagementServiceName'), '/', variables('VersionSetName'))]",
        "type": "Microsoft.ApiManagement/service/api-version-sets",
        "apiVersion": "2017-03-01",
        "properties": {
            "description": "Api Description",
            "displayName": "Api Name",
            "versioningScheme": "Segment"
        }
    }
    

    然后更新Microsoft.ApiManagement/service/apis 资源上的apiVersionSetId 属性:

    {
            "type": "Microsoft.ApiManagement/service/apis",
            "name": "[concat(variables('ManagementServiceName'), '/', variables('ApiName'))]",
            "apiVersion": "2017-03-01",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/api-version-sets', variables('ManagementServiceName'), variables('VersionSetName'))]"
            ],
            "properties": {
                "displayName": "string",
                "apiRevision": "1",
                "description": "",
                "serviceUrl": "string",
                "path": "string",
                "protocols": [
                    "https"
                ],
                "isCurrent": true,
                "apiVersion": "v1",
                "apiVersionName": "v1",
                "apiVersionDescription": "string",
                "apiVersionSetId": "[concat('/api-version-sets', variables('VersionSetName'))]"
            }
        }
    

    【讨论】:

    • 由于某种原因 Microsoft.ApiManagement/service/api-version-sets 在模板中没有被识别?有人可以检查它是否仍然是同一类型吗?
    【解决方案2】:

    api-version-sets

    的资源
                  "name": "my-api-version-sets",
                  "type": "api-version-sets",
                  "apiVersion": "2018-01-01",
                  "properties": {
                    "displayName": "Provider API",
                    "versioningScheme": "Segment"
                  },
                  "dependsOn": [
                    "[concat('Microsoft.ApiManagement/service/', variables('apiManagementServiceName'))]"
                  ]
    

    然后apis

                    "apiVersion": "2018-01-01",
                    "type": "apis",
    
                    "properties": {
                        ....
    
                        "isCurrent": true,
                        "apiVersion": "v1",
                        "apiVersionSetId": "/api-version-sets/my-api-version-sets" 
    

    【讨论】:

      【解决方案3】:

      您可以在 Azure ARM 门户上以路径、标头或查询字符串的形式指定版本。但旧的 azure API 管理门户不支持构建版本控制。您可以通过任何方式在 Web API URL 后缀中指定版本控制。

      如果您有任何问题,请添加一些图片并描述您的问题。

      Azure ARM Portal (New APIM)

      Azure APIM Portal (OLD)

      谢谢, 因法兹

      【讨论】:

      • 我投了反对票,因为问题是如何使用 ARM 模板而不是 UI 来实现它。
      猜你喜欢
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多