0

I try to create api for post request using swagger but cannot determine what parameters I should configure in swagger in order to create this API.

I used postman in order to get all information about the response and implement in swagger.

'/api/v1/labels':
post:
      tags:
        - devices
      summary: 'create new label'
      description: 'create new label to a given device'
      operationId: createNewLabel
      produces:
        - application/json
      parameters:
        - name: x-access-token
          description: 'cognito token'
          in: header
          type: string
          required: true
        - in: body
          name: body
          description: add label details
          required: true
          schema:
            $ref: '#/definitions/labelRequest'
      responses:
        '201':
          schema:
            $ref: '#/definitions/labelRequest'
          description: Created

and this is the definition I wrote:

labelRequest:
    type: object
    items:
      $ref: '#/definitions/labelRequestBody'

  labelRequestBody:
    type: object
    properties:
      device_ids:
        type: array
        items:
          type: string
          example: ["9bc11e25-4db2-4780-b761-390e3806082a"]
          format: uuid
      name:
        type: string
        example: new_label

This is the API call:

https:///api/v1/labels

with those headers:

x-access-token

and with this body as payload:

{
    "device_ids":["ea4b9daa-07cd-4cd6-981f-c86e1e81f04c"],
    "name":"labelName"
}

expected result is: 201 (created)

1 Answer 1

1

You are almost there, just change the labelRequest schema to:

definitions:
  labelRequest:
    type: object
    properties:
      device_ids:
        type: array
        items:
          type: string
          # Array item example should NOT be enclosed in []
          example: "9bc11e25-4db2-4780-b761-390e3806082a"
          format: uuid
      name:
        type: string
        example: new_label
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.