How can I override examples in openapi?

Viewed 2579

I have the response structure:

responses:
  '200':
    description: OK
    content:
      application/json:
        schema:
          type: object
          properties:
            data:
              allOf:
              - { $ref: ../../components/schemas/Product.yaml }
              example:
                active: false

And the Product.yaml one:

type: object
description: Product
properties:
  id:
    description: ID
    type: integer
    example: 1
  name:
    description: Name
    type: string
    example: 'fresh baguette'
  active:
    description: Is active
    type: boolean
    example: true

So I wanna override active example and when I do it like this:

data:
  allOf:
  - { $ref: ../../components/schemas/Product.yaml }
  example:
    active: false

In redoc ui under the "Response samples" I see the only active property.

My question is how can I override an example of only active property without overriding each of product properties?

1 Answers

There's no way to override an individual property value in an example. You need to provide the whole example:

responses:
  '200':
    description: OK
    content:
      application/json:
        schema:
          type: object
          properties:
            data:
              $ref: ../../components/schemas/Product.yaml

          example:
            data:
              id: 1
              name: fresh baguette
              active: false
Related