Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiModelProperty doesn't seem to support List and allowableValues #1565

Closed
dkirrane opened this issue Dec 9, 2015 · 6 comments
Closed

ApiModelProperty doesn't seem to support List and allowableValues #1565

dkirrane opened this issue Dec 9, 2015 · 6 comments

Comments

@dkirrane
Copy link

dkirrane commented Dec 9, 2015

I have the following annotation in my model

  @ApiModelProperty(value = "A list of items", allowableValues = "item1, item2, item3") 
    private List<String> itemList;

the swagger.json generated is as follows.

        "itemList" : {
          "type" : "array",
          "description" : "A list of items",
          "items" : {
            "type" : "string"
          }
        }

allowableValues are missing from the swagger.json.
Also is array the correct output type for a List<String>?

My config

        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.5.4</version>
        </dependency>
                <plugins>
                    <plugin>
                        <groupId>com.github.kongchen</groupId>
                        <artifactId>swagger-maven-plugin</artifactId>
                        <version>3.1.1</version>
                        <executions>
                            <execution>
                                <id>swagger</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                ...                               
                            </execution>
                        </executions>
                    </plugin>
@webron
Copy link
Contributor

webron commented Dec 10, 2015

Yeah, at the moment allowableValues would work for primitives or ranges. The workaround for this would be to use a list of enum instead and the allowableValues would be derived from it.

@fehguy fehguy closed this as completed Dec 25, 2016
@afdia
Copy link

afdia commented Mar 5, 2017

Is this issue closed because it should work already or because it won't be fixed?

I have a similar problem. My object has a list of enum values, but I want to restrict the values which may be used by the API.

enum MyEnum { VAL1, VAL2, VAL3 }

This works:

@ApiModelProperty(allowableValues = "VAL1,VAL2")
MyEnum myenum;

This doesn't work (it ignores the allowableValues and uses all possible enum values instead):

@ApiModelProperty(allowableValues = "VAL1,VAL2")
List<MyEnum> mylist;

@paul8620
Copy link

It would be nice to support other types as well for allowed values

@NikolayMetchev
Copy link

In 2019 this still doesn't work for List

@DenysBJava
Copy link

DenysBJava commented Oct 19, 2021

In 2021 this still doesn't work for List

@lukasmaz
Copy link

lukasmaz commented Apr 4, 2022

In 2022 this still doesn't work for List

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants