为什么导入OpenAPI定义时“模式”会从“响应”对象中消失?

时间:2017-12-18 11:28:44

标签: azure-api-management openapi

我可以将以下OpenAPI定义成功导入Azure API Management。

但是,当我导出OpenAPI定义时,“schema”名称已从“respond”对象中删除。因此,我的门户中的开发人员未显示此操作的架构或示例。

如果添加到the official editor,我的API定义有效且功能正常。

如何防止架构被剥离?

{
  "swagger": "2.0",
  "info": {
    "title": "Foo",
    "description": "Foo",
    "version": "1"
  },
  "host": "example.org",
  "schemes": [
    "https"
  ],
  "paths": {
    "/foo": {
      "get": {
        "summary": "List all foo.",
        "responses": {
          "200": {
            "description": "Success.",
            "schema": {
              "$ref": "#/definitions/Foo"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Foo": {
      "type": "object",
      "properties": {
        "example": {
          "type": "string",
          "description": "An example."
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

当定义在根对象或操作对象中缺少“生成”名称时,似乎会出现此问题。

例如,以下定义应成功导入,然后在不删除“模式”的情况下导出。请注意,“produce”名称已添加到根对象中,位于“scheme”和“paths”之间

{
  "swagger": "2.0",
  "info": {
    "title": "Foo",
    "description": "Foo",
    "version": "1"
  },
  "host": "example.org",
  "schemes": [
    "https"
  ],
  "produces": ["application/json"]
  "paths": {
    "/foo": {
      "get": {
        "summary": "List all foo.",
        "responses": {
          "200": {
            "description": "Success.",
            "schema": {
              "$ref": "#/definitions/Foo"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Foo": {
      "type": "object",
      "properties": {
        "example": {
          "type": "string",
          "description": "An example."
        }
      }
    }
  }
}