Skip to content

Question regarding the behaviour of allOf and example #10611

@anthops

Description

@anthops

I was wondering what the expected behavior of allOf with example is. For example I have:

/example:
  get:
    summary: Example
    responses:
      '200':
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/MySchema'
                - example:
                    my_string: "override"
                    my_array:
                      - "override"

components:
  schemas:
    MySchema
      type: object
      properties:
        my_string:
          type: string
        my_array:
          type: array
          items:
            type: string
      example:
        my_string: "original"
        my_array:
          - "original"   

This results in the following example for the response:

{
  "my_string": "override",
  "my_array": [
    "original",
    "override"
  ]
}

Swapping the order within the allOf block results in:

{
  "my_string": "original",
  "my_array": [
    "override",
    "original"
  ]
}

For context, I have a Schema that I want to use in a few different response bodies. Some of these responses need certain values to be slightly different in the examples. I noticed the above behaviour and thought it would be convenient, although I want to make sure that this is expected / supported.

I'm also unsure if this is something specific to swagger-ui or if it's part of the OpenAPI spec, so apologies if I' have asked in the wrong place.

Thanks in advance :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions