How to describe a model in Swagger for an array with simple objects?

后端 未结 7 2046
长发绾君心
长发绾君心 2020-12-15 15:30

I have a REST services to document, some of them accepts simple array like:

[
  { \"name\":\"a\" },
  { \"name\":\"b\" },
  { \"name\":\"c\" }
]
7条回答
  •  轮回少年
    2020-12-15 16:19

    I tried the follwoing in the editor.swagger.io, it satisfies the request of this question and works. The POST request body expects an array. The array is composed of 'stackoverflow' items. Each item is an object, that has name property.

    paths:
      /test:
        post:
          summary: test 123
          description: test 123
          parameters:
            - name: param1
              in: body
              required: true
              description: test param1
              schema:
                type: array
                items:
                  $ref: '#/definitions/stackoverflow'
          responses:
            200:
              description: OK
    definitions:
      stackoverflow:
        type: object
        properties:
          name:
            type: string
            description: name of the object
    

提交回复
热议问题