question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ApiModelProperty doesn't seem to support List and allowableValues

See original GitHub issue

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>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
afdiacommented, 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;
4reactions
webroncommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java swagger-ui doesn't render allowableValues for parameter
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,...
Read more >
ApiModelProperty (swagger-annotations 1.5.0 API)
Limits the acceptable values for this parameter. There are three ways to describe the allowable values: To set a list of values, provide...
Read more >
springfox/springfox - Gitter
How can I use @ApiModelProperty to create an example value of null? This does not compile: @ApiModelProperty(example = null) public Long nullableField;.
Read more >
allowableValues from Enum.values()? - Google Groups
Is it possible to provide the allowableValues value from an enum using something like MyEnum.values()? It doesn't seem possible.
Read more >
docs/release-notes.md · serv/springfox - Gitee.com
... swagger-ui.html appears to be empty documentation @silentsnooc; (#2090) When using AlternateTypeRuleConvention ApiModelProperty annotation does not work ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found