Swagger-ui: How to display a drop-down or a way to select an input from multiple inputs?

Created on 24 Oct 2014  路  1Comment  路  Source: swagger-api/swagger-ui

With ref. to this discussion https://groups.google.com/forum/#!topic/swagger-swaggersocket/5Oc9fQCPu5Q , i want to know the multi value select option (drop-down ) which was present in earlier version of swagger (1.2) is supported in 2.0 or not?

Most helpful comment

Just pushed a fix to address this. To show a single select input, your spec would look like such:

Note, the key here is to show the enum to tell the UI that they need to select from one of the values.

{
  "name": "status",
  "in": "query",
  "default": "available",
  "enum": [
    "alive",
    "dead",
    "available"
  ],
  "description": "Status values that need to be considered for filter",
  "required": true,
  "type": "string"
}

To show a multi-select input box:

{
  "name": "tags",
  "in": "query",
  "description": "Tags to filter by",
  "required": false,
  "type": "array",
  "items": {
    "type": "string"
  },
  "enum": [
    "tag1", "tag2"
  ]
}

Note here, the input is an array, because it can have multiple input values. It will then format the input in accordance to the collectionFormat as defined here:

https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameter-object-

>All comments

Just pushed a fix to address this. To show a single select input, your spec would look like such:

Note, the key here is to show the enum to tell the UI that they need to select from one of the values.

{
  "name": "status",
  "in": "query",
  "default": "available",
  "enum": [
    "alive",
    "dead",
    "available"
  ],
  "description": "Status values that need to be considered for filter",
  "required": true,
  "type": "string"
}

To show a multi-select input box:

{
  "name": "tags",
  "in": "query",
  "description": "Tags to filter by",
  "required": false,
  "type": "array",
  "items": {
    "type": "string"
  },
  "enum": [
    "tag1", "tag2"
  ]
}

Note here, the input is an array, because it can have multiple input values. It will then format the input in accordance to the collectionFormat as defined here:

https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameter-object-

Was this page helpful?
0 / 5 - 0 ratings