Enum in swagger
In case of swagger-maven-plugin 3.1.0 this might be a minimal documentation:
@ApiModel
public class Input {
@ApiModelProperty
public Day day;
}
@ApiModel
public enum Day {
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday;
}
Then this is the generated json model:
"definitions" : {
"Input" : {
"type" : "object",
"properties" : {
"day" : {
"type" : "string",
"enum" : [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]
}
}
}
}
And this is how the model is presented in the SwaggerUI:
Input {
day (string, optional) = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
}
According to the doc you pointed:
The dataType. See the documentation for the supported datatypes. If the data type is a custom object, set it's name, or nothing. In case of an enum use 'string' and allowableValues for the enum constants.
I think you should add the enum values manually:
@ApiModel
public class Input {
@ApiModelProperty(dataType = "string", allowableValues = "Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday", value = "description", notes = "notes")
public Day day;
}
Custom Springfox Plugin solution:
swagger.io recommends: "If you need to specify descriptions for enum items, you can do this in the description of the parameter or property"
I implemented this recommendation based on a proprietary @ApiEnum annotation. The library is available here: https://github.com/hoereth/springfox-enum-plugin