Skip to content

How to have examples for an object which has an array of objects #3079

Closed Answered by hkosova
mcrobbj asked this question in Q&A
Discussion options

You must be logged in to vote

Multiple schema-level examples are supported in OpenAPI 3.1. They must be inline example values and cannot be $refs.

openapi: 3.1.0
...

components:
  schemas:
    MyObject:
      type: object
      properties:
        foo:
          type: string
          # Multiple property-level examples
          examples:
            - Hello, world!
            - quick brown fox
      # Multiple object-level examples
      examples:
        - foo: Hello, world!
        - foo: quick brown fox
    
    MyArray:
      type: array
      items:
        $ref: '#/components/schemas/MyObject'
      # Multiple array-level examples
      examples: 
        -
          # The 1st example
          - foo: Hello, …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by handrews
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
example obj/keywords Issues with the Example Object or exampel(s) keywords
3 participants