Forum Discussion

jerry91's avatar
jerry91
New Contributor
2 years ago
Solved

Swagger Response In Array

Hi Team, My client want to see api response in array. But swagger always show response in json. Please check the attached image. Client wants response as he mentioned with the array brackets. Please take a look on the attached image.

 

 

  • Hi jerry91 

    When playing a little bit with your example I got the following result:

    Is that what you are looking for?

3 Replies

  • chichepo's avatar
    chichepo
    Champion Level 3

    Hi jerry91 

    When playing a little bit with your example I got the following result:

    Is that what you are looking for?

    • jerry91's avatar
      jerry91
      New Contributor

      Hi chichepo 

      Yes I need something like this.  What changes I have to made in my swagger documentation ?

      • chichepo's avatar
        chichepo
        Champion Level 3

        jerry91 

         

        First I declared my response simply using media type application/json

        responses:
                '200':
                  description: Successful operation
                  content:
                    application/json:
                      schema:
                        $ref: '#/components/schemas/MyResponse'

          
        Then, for a better readability, I define the response schema as following:

          schemas:
            MyResponse:
              type: object
              properties:
                outbox_manager:
                  $ref: '#/components/schemas/TheFirstArray'
        
            TheFirstArray:
              type: array
              items:
                type: object
                properties:
                  field01:
                    type: string
                  field02:
                    type: string
                  other_details:
                    type: array
                    items:
                      $ref: '#/components/schemas/TheSecondArray'
        
            TheSecondArray:
              type: object
              properties:
                field01:
                  type: string
                field02:
                  type: string

         

        Et voila!! ğŸ˜‰