user3568043
user3568043

Reputation: 143

Swagger documentation

How to write documentation in swagger for array of objects. This is my code, but I don't know how to access data in array of objects.

{ 
    "first_name":"Sam",
    "last_name":"Smith",  
    "reservations":[
        {
            "chkin_date":"2016-03-31",
            "chkout_date":"2016-04-08",
            "adults":1,
            "children":2,
            "chdage":[2,3]
        },
        {
            "chkin_date":"2016-03-30",
            "chkout_date":"2016-04-03",
            "adults":1,
            "children":2,
            "chdage":[2,3,5]
        }
    ]
}

Upvotes: 2

Views: 938

Answers (1)

fehguy
fehguy

Reputation: 6824

Here you go:

definitions:
  SomeObject:
    properties:
      first_name:
        type: string
        example: Sam
      last_name:
        type: string
        example: Smith

      reservations:
        type: array
        items:
          $ref: '#/definitions/Reservation'
  Reservation:
    properties:
      chkin_date:
        type: string
        format: date
        example: 2016-03-31
      chkout_date:
        type: string
        format: date
        example: 2016-04-08
      adults:
        type: integer
        format: int32
        example: 1
      children:
        type: integer
        format: int32
        example: 2
      chdage:
        type: array
        items:
          type: integer
          format: int32

Upvotes: 7

Related Questions