Ask a Question

Newbie Asking

SOLVED
jaselee
New Contributor

Newbie Asking

I'm very new to swagger and I wanted to document a successful output of a longer JSON unfortunately I couldn't find a way. 

I wanted to output the following in 02.png

I couldn't figure out how to write them so that I can output multiple arrays in JSON.

 

 

 

2 REPLIES 2
ponelat
Staff

Hi @jaselee 

 

Your definition looks good.

Examples on higher levels can override examples on lower levels, so to show multiple items in an array, you can override the example on the array level.

Ie:

 

# ...
Vendors:
  type: array
  items:
      type: object
      properties:
        Id:
          type: string
          example: '006000'
        Name:
          type: string
          example: Toshiba
  example:
  - { Id: '006000', Name: 'Toshiba' }
  - { Id: '007000', Name: 'Samsung' }
  - #...

 

 

Here is a test definition showing this in action...

https://app.swaggerhub.com/apis/ponelat/example-examples/1.0.0

Thank you, @ponelat ! This is the answer I'm looking for!

cancel
Showing results for 
Search instead for 
Did you mean: