【问题标题】:swagger example response not respecting nested allOf不尊重嵌套 allOf 的招摇示例响应
【发布时间】:2021-12-22 15:48:49
【问题描述】:

当使用以下招摇时,生成的端点有一个示例响应与我认为招摇(和模型)规定的不一致。

大摇大摆:

components:
  examples: {}
  headers: {}
  parameters: {}
  requestBodies: {}
  responses: {}
  schemas:
    SubSubData:
      type: object
      properties:
        subSubDataProp:
          type: string
    SubData:
      allOf:
        - $ref: '#/components/schemas/SubSubData'
        - type: object
          properties:
            subDataProp:
              type: string
    Data:
      allOf:
        - $ref: '#/components/schemas/SubData'
        - type: object
          properties:
            dataProp:
              type: string
    ExampleResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/Data'
info:
  title: __PROJECT_NAME__
  version: 1.0.0
  description: |
    Add your Swagger description here.
  license:
    name: ISC
  contact:
    name: Me
openapi: 3.0.0
paths:
  /example:
    get:
      operationId: GetData
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExampleResponse'
      security: []

预期的反应:

{
  "data": {
    "dataProp": "string",
    "subDataProp": "string",
    "subSubDataProp": "string"
  }
}

实际:

{
  "data": {
    "dataProp": "string"
  }
}

我错过了什么吗?或者这是swagger ui/openapi中的一个错误

【问题讨论】:

    标签: swagger swagger-ui openapi


    【解决方案1】:

    这是 Swagger UI 中的一个错误:
    https://github.com/swagger-api/swagger-ui/issues/5972

    解决方法是将paths 移动到components 之前。

    【讨论】:

    • 解决了!这是一个非常奇怪的错误和奇怪的帮助,但谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 2019-04-05
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多