Java swagger-ui doesn't render allowableValues for parameter

Viewed 5695

I have a SpringBoot, JAX-RS, and Maven app. I'm using Swagger annotations to provide info on the REST service interface. It basically works, but I'm having trouble with some parameters that I expect a limited set of values. I believe I'm specifying the "@Api..." annotations correctly, and I can see the expected results in the swagger.json file, but the swagger-ui doesn't appear to do anything with that information.

My pom.xml appears to specify version 1.5.20 of the swagger artifacts.

The following is a heavily elided excerpt from the Java interface:

@GET
@Path("...")
@ApiOperation("...")
@ApiImplicitParams({
    ...
    @ApiImplicitParam(name = "poi_types", value = "Types of locations to include",
                      allowableValues = "pos, wifi, country",
                      dataType = "string", paramType = "query"),
    ...
    })
public Object ...(@QueryParam(...)
                              @ApiParam(name = ..., value = "...")
                  String ...) {

In the swagger.json, I see the following for that entry:

    {
        "name" : "poi_types",
        "in" : "query",
        "description" : "Types of locations to include",
        "required" : false,
        "type" : "string",
        "enum" : [ "pos", "wifi", "country" ]
    }

In the generated UI, I see the following:

swagger-ui excerpt for poi_types

I've seen somewhere some mentions of possible disconnects between the required schema and what swagger-ui renders, like perhaps requiring a "schema" element in the parameter definition that includes the "type"and "enum" properties. I tried manually changing the swagger.json to include that, but it made no difference.

Can anyone provide any background here?

Update:

I upgraded to swagger-core and swagger-annotations v1.6.2. I also tried putting "allowableValues" into an "@ApiParam" instead of just an "@ApiImplicitParam". Neither of these changes made any difference. I don't see any indication in the UI of the allowable values.

This is the changed element from the @ApiParam change:

    {
      "name" : "isocc2",
      "in" : "query",
      "description" : "Country code",
      "required" : false,
      "type" : "string",
      "enum" : [ "en", "es" ]
    }

This is how this displays in the swagger UI:

view of parameter with allowableValues

I also verified from the browser the swagger.json that it loaded, and it matches what I expected.

Just in case, I tested it in Chrome in addition to Firefox.

What else could be wrong here?

1 Answers

Have you tried using ?

public Object ...(@QueryParam(...)
                  @ApiParam(name = ..., value = "...", 
                            allowableValues = "pos, wifi, country",)
                  String poi_types) {

allowableValues property works well on @ApiParam.

Related