-
-
Notifications
You must be signed in to change notification settings - Fork 553
feat: Add @EnumDescription annotation for automatic enum #3125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I would suggest adding a test case for when the annotation is used. This both as an illustrative case for how to use it, but also to show that the current implementation actually behaves as expected when utilized. Use the current tests as a suggestion for how they usually are structured. |
|
Thanks for the feedback!
Note that the Which directory structure should I use for the |
|
I prefer the second approach with an integration test as per |
|
This PR adds test cases to verify the EnumDescription annotation functionality:
The tests verify that enum information is properly added to OpenAPI operation descriptions. Please review when convenient. Thanks! |
|
I see now that there exists two different ways of doing integration tests, either in the The difference is that the assertion is made against the entire A bit off topic, but what is the reason for deriving the name from a potential enum value, rather than explicitly having the values in a So the domain is: public enum UserStatus {
ACTIVE,
INACTIVE,
PENDING;
}while the DTO is @Schema(name = "UserStatus", description = "...", example = "...", ....)
public enum UserStatusDTO {
ACTIVE,
INACTIVE,
PENDING;
}The current approach seems like it could potentially cause minor "leakage", since it is not intuitive that anything that goes into an enum's value could reach the client. Sure it is semi-safe, since it is opt-in, but I would always argue for a more strict domain/api segmentation. |
Description
This PR implements automatic enum description injection into OpenAPI operation descriptions.
It addresses the issue described in #3116
What's Changed
@EnumDescriptionannotation to mark enum fields for automatic description generationUsage Example
Technical Details
EnumDescriptionOperationCustomizerimplementsGlobalOperationCustomizerSpringDocConfigurationFuture Improvements
As mentioned in the original issue, we considered adding support for schema-level descriptions as well.
This could be implemented using
PropertyCustomizerto inject enum descriptions into schema property descriptions.This enhancement could be added in a future PR if there's interest.