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>
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.
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;
It would be nice to support other types as well for allowed values
In 2019 this still doesn't work for List
Most helpful comment
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.
This works:
This doesn't work (it ignores the allowableValues and uses all possible enum values instead):