首页 > 解决方案 > 验证的开放 API 规范无法上传到 Azure API 管理

问题描述

我正在尝试在我的 azure api 管理服务上导入与https://github.com/ccouzens/keycloak-openapi/blob/master/keycloak/9.0.json非常相似的 OpenAPI 规范 json。我在http://editor.swagger.io/上验证了我的 openapi.json 版本 。当我尝试使用上述 json 创建 API 资源时,出现错误:

{"error":{"code":"ValidationError","message":"One or more fields contain incorrect values:","details":[{"code":"ValidationError","target":"templateParameters","message":"All template parameters used in the UriTemplate must be defined in the Operation, and vice-versa."}]}}

请帮忙

标签: azureopenapiazure-api-management

解决方案


发现问题。json API 规范文件有多个 API URL,其中 {id} 在同一个 URL 中出现两次,这是 azure 的 API 管理不允许的,并且没有两个路径参数的“参数”定义。例如,参考下面的 URL 和 api 规范文件中的相应参数定义

/{realm}/client-scopes/{id}/protocol-mappers/models/{id}

 "parameters": [
        {
          "in": "path",
          "name": "realm",
          "description": "realm name (not id!)",
          "required": true,
          "schema": {
            "type": "string"
          },
          "style": "simple"
        },
        {
          "in": "path",
          "name": "id",
          "description": "Mapper id",
          "required": true,
          "schema": {
            "type": "string"
          },
          "style": "simple"
        }
      ]

swagger 编辑器 不考虑这些约束违规

因此,总而言之,要在 Azure api 管理服务上上传开放 API 规范,您需要考虑以下约束以及 azure 文档中存在的约束

  1. 您不能有两个具有相同标识字符串的路径参数
  2. 所有路径参数都应该在规范 json 中有一个“参数”定义

PS:我的 api 规范 json 与 json文件非常相似,但不一样。它还有其他问题,例如使用请求正文删除 API。


推荐阅读