Search code examples
swaggerswagger-2.0swagger-editor

Swagger how to write a model which is array format


The json like this

[{xx:xx,xx1:xx1},{},...]

Here a model of a get request, it return a array directly, not a formal json, how to write a model?

/hsseventwebapi/v1/walking/events/{eventcd}/livecomments:
get:
  operationId: イベント実況を返す
  summary: 個人に関連するランキングを返す
  description: "イベント実況を返す(取得したい実況一覧の開始日時を指定取得できる一覧は最大30件"
  tags:
    - Walking
  parameters:
    - name: eventcd
      in: path
      description: eventcd
      required: true
      type: integer
  responses:
    200:
      description: OK
      schema:
        $ref: '#/definitions/LiveListModel'

Here the model:

LiveListModel:
type: array
description: live list
items:
  type: object
  description: live item
  properties:
    eventNo:
      type: string
      description: eventNo
    liveCommentYmdhms:
      type: string
      description: liveCommentYmdhms
    liveComment:
      type: string
      description: liveComment
    liveCommentSeq:
      type: string
      description: liveCommentSeq
    targetAppUserNo:
      type: string
      description: targetAppUserNo
  required:
      - eventNo
      - liveCommentYmdhms
      - liveComment
      - liveCommentSeq
      - targetAppUserNo

Here is the ui two layer nested

There are two liveListModel, I can't parse it.


Solution

  •     /hsseventwebapi/v1/walking/events/{eventcd}/livecomments:
    get:
      operationId: イベント実況を返す
      summary: 個人に関連するランキングを返す
      description: "イベント実況を返す(取得したい実況一覧の開始日時を指定取得できる一覧は最大30件"
      tags:
        - Walking
      parameters:
        - name: eventcd
          in: path
          description: eventcd
          required: true
          type: integer
      responses:
        200:
          description: OK
          schema:
            type: array
            items:
              $ref: '#/definitions/LiveListItemModel'
    
    
    
    
    
     LiveListItemModel:
        type: object
        description: live item
        properties:
          eventNo:
            type: string
            description: eventNo
          liveCommentYmdhms:
            type: string
            description: liveCommentYmdhms
          liveComment:
            type: string
            description: liveComment
          liveCommentSeq:
            type: string
            description: liveCommentSeq
          targetAppUserNo:
             type: string
             description: targetAppUserNo
          required:
              - eventNo
              - liveCommentYmdhms
              - liveComment
              - liveCommentSeq
              - targetAppUserNo