Swagger文档

时间:2016-03-31 18:59:16

标签: swagger

如何在swagger中为对象数组编写文档。这是我的代码,但我不知道如何访问对象数组中的数据。

{ 
    "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]
        }
    ]
}

1 个答案:

答案 0 :(得分:7)

你走了:

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