Reputation: 282
I'm creating the API description of our application using Swagger/OpenApi V3 annotations, imported from following dependency:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.0</version>
</dependency>
I want to add the description to each enum value :
public enum Gender {
@Schema(description = "NotSpecified")
NOT_SPECIFIED,
@Schema(description = "Male")
MALE,
@Schema(description = "Female")
FEMALE;
}
But springdoc doesn't generate descriptions for enum.
Gender:
type: string
example: MALE
enum:
- NOT_SPECIFIED
- MALE
- FEMALE
Is there a way to add description to each enum value?
Upvotes: 6
Views: 5952
Reputation: 163
I believe you can describe enum values only in desciption of enum (https://swagger.io/docs/specification/data-models/enums/). So you can do sth like this:
@Schema(enumAsRef = true, description = "gender: \n" +
"* `NOT_SPECIFIED` - NotSpecified\n" +
"* `MALE` - Male\n" +
"* `FEMALE` - Female\n" +
"")
enum Gender {
NOT_SPECIFIED,
MALE,
FEMALE
}
and the generated swagger looks quite good then.
Upvotes: 12