cancel
Showing results for 
Search instead for 
Did you mean: 

Example composition

SOLVED
tobias_wolff
Occasional Visitor

Example composition

Hi,

I have recently discovered the possibility to add examples to components, request bodies and responses - which btw. is a great feature. I got it working to a certain extend by defining examples in the "components/examples" section and reusing them in the request bodies and response in the paths section. I now wonder, if there also is a way to do a composition on examples using $refs. I tried the following:

components:
  examples:
    ProductResponse:
      value:
        id: 1
        name: Test Product One
    ProductListResponse:
      value:
        count: 1
        data:
          - $ref: '#/components/examples/ProductResponse'

But using this in a response as follows:

      responses:
        200:
          description: |
            Returns a (possibly empty) list of products.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProductListResponse'
              examples:
                ProductListResponse:
                  $ref: '#/components/examples/ProductListResponse'

will render the "Example Value" section in the swagger UI as such:

ListResponse.png

Can you, please, let me know if I am missing something?

 

Thanks,

   Tobias.

1 ACCEPTED SOLUTION

Accepted Solutions
HKosova
Moderator

Re: Example composition


I now wonder, if there also is a way to do a composition on examples using $refs.

Example values do not support $ref. Each example must be a complete literal example.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

1 REPLY 1
HKosova
Moderator

Re: Example composition


I now wonder, if there also is a way to do a composition on examples using $refs.

Example values do not support $ref. Each example must be a complete literal example.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors