Swagger UI parameter as list instead of text input

swagger, swagger-ui

Solution

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.

- I'm not sure where you got `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.

- Currently, the Swagger 2.0 pet store example is located here - http://petstore.swagger.wordnik.com/ui. At the time of writing this answer, there's no usage of `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.

Problem

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: - There is some command called `allowableValues` but as far as I understand, its not available in Swagger 2.0 - I found the `enum` command, but was unable to make it work for me. - I am not sure if I should define this list of allowed values in the `parameters` section, or `definitions` section - I found the petstore example where it does have a select field like I want (GET /pet/findByTags), but as far as I could see in the "raw" JSON, it looks like the older Swagger format. Finally, 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 ```

Original source

Related problems