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

后端 未结 7 2062
长发绾君心
长发绾君心 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:25

    Considering the format of the array you mentioned

    [
      { "name":"a" },
      { "name":"b" },
      { "name":"c" }
    ]
    

    I guess the following format can be used:

    paths:
      /test:
        post:
          description: Test request
          operationId: test
          parameters:
            - in: body
              name: requestParameter
              required: true
              schema:
                type: array
                items:
                  properties:
                    name:
                      type: string
          responses:
            '200':
              description: Success response
    

提交回复
热议问题