Search code examples
swaggerswagger-uiopenapi

swagger example response not respecting nested allOf


When using the following swagger, the resulting endpoint has an example response that doesn't align with what I believe the swagger (and the models) dictate.

The swagger:

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: []

The expected response:

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

Actual:

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

Am I missing something? Or is this a bug in the swagger ui/openapi


Solution

  • It's a bug in Swagger UI:
    https://github.com/swagger-api/swagger-ui/issues/5972

    The workaround is to move paths before components.