swag
swag copied to clipboard
Multiple Enum variant selection
Hi,
I have an endpoint which get a query param named status which accepts params as ?status=ACTIVE&status=PASSIVE
.
I want to render a select box with multiple selection in swagger.
I tried enums shown as below which renders a selectbox but only one element is selectable.
// @Param status query string false "status" Enums(ACTIVE,PASSIVE)
Also I tried arrays shown as below:
// @Param status query []string false "status"
This renders multiple inputs but send status array as ?status=ACTIVE,PASSIVE
(comes with ,
seperated, so I must split incoming parameter with ,
)
I want to select multiple enum variants with selectbox and parameter should come as ?status=ACTIVE&status=PASSIVE
.
Thanks for helps
Is this available in OAS 2 specs?
@ubogdan yes, it is available. I copied this json from java swagger:
{
"name": "status",
"in": "query",
"description": "status",
"required": false,
"type": "array",
"items": {
"type": "string",
"enum": [
"ACTIVE",
"PASSIVE"
]
},
"collectionFormat": "multi",
"enum": [
"ACTIVE",
"PASSIVE"
]
},
@mesuutt, I think this is fixed in the latest release. I made a correction for the first example you tried, that was included in v1.7.1, so it should generate the JSON you copied now.
collectionFormat ? // @Param collection query []string false "string collection" collectionFormat(multi)
https://github.com/swaggo/swag#available
Determines the format of the array if type array is used. Possible values are:
csv - comma separated values foo,bar.
ssv - space separated values foo bar.
tsv - tab separated values foo\tbar.
pipes - pipe separated values foo|bar.
multi - corresponds to multiple parameter instances instead of multiple values for a single instance foo=bar&foo=baz. This is valid only for parameters in "query" or "formData".
Default value is csv.