Forum Discussion

jaselee's avatar
jaselee
New Contributor
4 years ago

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.

 

 

 

  • 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

  • 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