11

How do I specify an array as a parameter? For instance, post to /persons can be given strings username, firstname, and lastname, and array myArray.

paths:
  /persons:
    post:
      parameters:
        - name: person_what_is_the_purpose_of_this
          in: body
          description: The person to create.
          schema:
            required:
              - username
            properties:
              firstName:
                type: string
              lastName:
                type: string
              username:
                type: string
              myArray:
                type: array
                  items:
                    properties:
                      myArrayElement:
                        type: string
      responses:
        200:
          description: A list of Person
          schema:
            type: array
            items:
              required:
                - username
              properties:
                firstName:
                  type: string
                lastName:
                  type: string
                username:
                  type: string

2 Answers 2

12
swagger: "2.0"
info:
  version: "1.0.0"
  title: Swagger Petstore
host: petstore.swagger.io
basePath: /v2
schemes:
  - http
paths:
  /pets/findByStatus:
    get:
      parameters:
        - in: query
          name: status
          type: array
          items:
            type: string
      responses:
        "200":
          description: successful operation
          schema:
            type: array
            items:
              type: object
              required:
                - name
                - photoUrls
              properties:
                id:
                  type: integer
                  format: int64
                category:
                  type: object
                  properties:
                    id:
                      type: integer
                      format: int64
                    name:
                      type: string
                name:
                  type: string
                  example: doggie
                photoUrls:
                  type: array
                  items:
                    type: string
                tags:
                  type: array
                  items:
                    type: object
                    properties:
                      id:
                        type: integer
                        format: int64
                      name:
                        type: string
        "400":
          description: Invalid status value
Sign up to request clarification or add additional context in comments.

1 Comment

This is sends a list, not an array
6

You need to specify collectionFormat: multi

For your array it would look like this, be sure to put it on the same level as the type:

myArray:
  type: array
  collectionFormat: multi

Documentation about arrays

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.