Reputation: 1379
type": "array",
"items": {
"type": "string",
"enum": ["MALE","FEMALE","WORKER"]
}
or
type": "array",
"items": {
"type": "string",
},
"enum": ["MALE","FEMALE","WORKER"]
?
Nothing in the spec about this. The goal is of course to get swagger-ui to show the enum values.
Upvotes: 21
Views: 35544
Reputation: 1573
If you want to create a filter restricting by enum, take a look below:
- schema:
type: array
items:
type: string
enum: ["1", "2", "3", "4", "5"]
in: query
name: ContractStatus
description: Status of the installment contract. 1- status-1 2- status-2 3- status-3 4- status-4 5- status-5
Upvotes: 0
Reputation: 1379
The first case is correct and these days swagger-ui generates a multiple-choise select of the enum values.
Upvotes: 8
Reputation: 5331
It will depend on what you want to enum:
Each enum value MUST be of the described object type
First syntax means These are the possible values of the String in this array
AnArray:
type: array
items:
type: string
enum:
- MALE
- FEMALE
- WORKER
This array can contain multiple String, but each String must have MALE, FEMALE or WORKER value.
Second one means These are the possible values of this Array
AnotherArray:
type: array
items:
type: string
enum:
-
- FEMALE
- WORKER
-
- MALE
- WORKER
Each enum value is therefore an array. In this example, this array can only have to possible value ["FEMALE","WORKER"] and ["MALE","WORKER"].
Unfortunately even if this syntax is valid, no enum values are shown in Swagger UI.
Upvotes: 17