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.
Enums, or enumerated types, are variable types that have a limited set of possible values. Enums are popular in API design, as they are often seen as a simple way to communicate a limited set of possible values for a given property. However, enums come with some challenges that may limit or impede your API design.
Use the default keyword in the parameter schema to specify the default value for an optional parameter. The default value is the one that the server uses if the client does not supply the parameter value in the request. The value type must be the same as the parameter's data type.
In computer programming, an enumerated type (also called enumeration, enum, or factor in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type.
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.
The first case is correct and these days swagger-ui generates a multiple-choise select of the enum values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With