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
/users/add:
post:
description: ''
operationId: AddUser
parameters:
- 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
items:
type: string
collectionFormat: multi
and it's kind of displaying what I want in the swagger editor
but what i'm getting in the UI is just an input field
In conclusion what I want to get is an inputted array which contains the user roles and input them in the database. Thank you
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.
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:
http://localhost:8080/accounts?roles=admin%2Cguest%2Cuser
You can then access the array values in the URL parameters rather than in "formData".