Array of objects as an input parameter in swagger

前端 未结 1 795
-上瘾入骨i
-上瘾入骨i 2020-12-09 14:27

I\'m trying to describe the following post parameter in swagger:

{
    \"sources\": [
        {
            \"id\": 101,
            \"parentId\": 201
               


        
相关标签:
1条回答
  • 2020-12-09 15:06

    If I understand correctly, your request body to post is a json object instead of form. In such case, your swagger document need to be modified as follows:

    1. When request body is json, a parameter with in: body is used instead of multiple parameters of in: formData.
    2. If in is body, a schema object is required.
    3. Defined the json properties under schema. If the property type is array, items object is required.

    Following is an example:

    paths:
      /bulk-action:
        post:
          consumes:
            - application/json
          parameters:
            - name: body
              in: body
              schema:
                properties:
                  sources:
                    type: array
                    items:
                      $ref: '#/definitions/BulkSource'
                  destinationdId:
                    type: integer
          responses:
            200:
              description: OK
    definitions:
      BulkSource:
        type: object
        properties:
          id:
            type: integer
          parentId:
            type: integer
    
    0 讨论(0)
提交回复
热议问题