Array of Multiple items in Swagger

DRYRA Source

So I'm creating a user endpoint with nodejs to add a user to the database , and for the api documentation I'm using swagger editor and I'm completely new to it. what I want to do is add a user with login , password , avatar but that user has multiple roles I want to add to the database what I have done in the yaml document in the swagger editor is this

description: ''
operationId: AddUser
- description: The user login
  in: formData
  name: user
  required: true
  type: string
- description: The user password
  in: formData
  name: password
  required: true
  type: string
- description: The user name
  in: formData
  name: username
  required: true
  type: string
- description: The user avatar
  in: formData
  name: avatar
  required: true
  type: file
- in: formData
  name: roles
  description: roles
  required: false
  type: array
    type: string
    collectionFormat: multi

and it's kind of displaying what I want in the swagger editor enter image description here

but what i'm getting in the UI is just an input field enter image description here

In conclusion what I want to get is an inputted array which contains the user roles and input them in the database. Thank you



answered 3 years ago Mike #1

What version of Swagger UI are you using? I am on version 2.1.1 and when I put the same definition as you I get the following input box for an array field.

swagger array parameter

Try upgrading to the newest version of Swagger UI.

Also, if you update the "in" field to be "query" the resulting URL will look like this:


You can then access the array values in the URL parameters rather than in "formData".

comments powered by Disqus