swag icon indicating copy to clipboard operation
swag copied to clipboard

Multiple Enum variant selection

Open mesuutt opened this issue 3 years ago • 4 comments

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

mesuutt avatar Jul 05 '21 06:07 mesuutt

Is this available in OAS 2 specs?

ubogdan avatar Jul 28 '21 15:07 ubogdan

@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 avatar Aug 12 '21 06:08 mesuutt

@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.

j-sv avatar Aug 13 '21 07:08 j-sv

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.

KScaesar avatar Dec 17 '21 06:12 KScaesar