Swagger how to write a model which is array format

116 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER
    /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
1
On

Your spec is correct.


Swagger Editor and UI render array models like this:

ArrayModelName   [ ItemModelName  <item schema> ]

or if the items are objects:

ArrayModelName   [ ItemModelName {
  properties
}]

The duplicate model names on your image is a display bug in Swagger Editor/UI. It's supposed to be fixed in the upcoming release later this week (September 15-16?).

In your example, the item model is inline and has no name/title, so it should be rendered as nameless.