Reputation: 14776
I am trying to figure out how to make the Swagger UI show a list of allowed values instead of an input field.
So far, I was able to get myself pretty confused with the different versions of Swagger, and the docs. I am not sure which is which (1.2, 2.0, YAML, JSON...)
So far, this is what I know:
allowableValues
but as far as I understand, its not available in Swagger 2.0enum
command, but was unable to make it work for me.parameters
section, or definitions
sectionFinally, here is the code I was trying in this Swagger editor:
swagger: '2.0'
host: asd.com
schemes:
- http
info:
version: "1.0.0"
title: test
paths:
/users:
get:
parameters:
- name: status
in: query
type: string
enum:
- online
- offline
responses:
"200":
description: Nice
Upvotes: 5
Views: 12411
Reputation: 769
The above solutions did not work for me. The simplest way to add a dropdown list in Swagger is to update the swagger.json file.
"parameters": [
{
"name": "status",
"in": "query",
"type": "string",
"default": "available",
"enum": [
"active",
"inactive",
"available"
],
"required": true
}
],
Upvotes: 0
Reputation: 14830
Swagger 2.0 has been released a couple of months ago, and the tools around it gradually add support for the spec itself.
The specification format itself is in JSON, but the editor tool (which is new in 2.0) allows you to use YAML for a more human-friendly editing.
allowableValues
- that's not part of Swagger 1.2 nor 2.0.enum
is indeed the property name to use for restricting a field to specific values.parameters
are used to define operation parameters (path, query, header, body and formData). definitions
are used to Schema Objects, which are normally models used by the API but can also represent arrays and primitives. enum
can be used next to any primitive type to restrict its definition, whether inside a parameter definition or a schema object definition.enum
in that sample.As for viewing the limited values in swagger-ui, for Swagger 2.0 it is just not implemented yet. As mentioned above, it is still work in progress. Feel free to open an issue about it directly on the repository.
In terms of validity, the YAML you pasted above looks fine.
Upvotes: 3