对多个对象json数据的swagger响应

时间:2018-05-21 06:06:54

标签: node.js api swagger swagger-2.0 suppress-warnings

我已经开发了node API,现在我正在使用swagger为此API创建Documentation,但stuck中的response part,请帮助我写下此json结果的回复,

    [
  {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "Point",
          "coordinates": [
            -79.90295559,
            36.05593626
          ]
        },
        "properties": {
          "id": "f2e08a02-9be9-468d-9bae-b83118ef5110",
          "esri_id": "518",
          "name": "Greensboro et al, NC",
          "panelCount": 1,
          "tot": 790523
        }
      }
    ]
  }
]

我当前的swagger响应代码是这样的,

responses:
        # Response code
        200:
          description: Successful response
          # A schema describing your response object.
          # Use JSON Schema format
          schema:
            title: User Authentication
            type: array
            items:
              title: token
              type: object

我不知道如何撰写回复with type to each object

1 个答案:

答案 0 :(得分:2)

您可以在“定义”中定义JSON结构,并在架构中引用它

responses:
    # Response code
    200:
      description: Successful response
      schema:
        $ref: '#/definitions/userAuthentication'


definitions:
  -userAuthentication:
    title: User Authentication
    type: array
    items:
      title: token
      type: string

如果您想将令牌作为JSON,则定义它并引用。