I have a class that looks like this:
public class Rule {
private RuleType type; //enum
private String value;
}
The enum is:
public enum RuleType {
TYPE_A,
TYPE_B,
TYPE_C;
}
Now, for each rule type the values are different:
TYPE_A requires a number 1 through 10,TYPE_B is true or false, andTYPE_C is a string.I try to add Swagger annotations to the enum so that the documentation can show this, something like this:
public enum RuleType {
@ApiModelProperty(value = "1 - 10")
TYPE_A,
@ApiModelProperty(value = "True or False")
TYPE_B,
@ApiModelProperty(value = "String")
TYPE_C;
}
But this doesn't work. The Swagger output just ignores the properties on the enums.
Is there a way to create documentation like this?
You cannot do this as you like.
But there is another simple solution in adding the annotation @ApiModelProperty with a summary description to the property:
public class Rule {
@ApiModelProperty(value =
"TYPE_A must be 1 - 10\n" +
"TYPE_B must be True or False\n" +
"TYPE_C must be String")
private RuleType type; //enum
private String value;
}
Results in Swagger UI showing the description with enum values for the property type:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With