fix: resolve Validation Meta annotations not working (#4886)
Pull Request
Thank you for contributing to swagger-core!
Please fill out the following information to help us review your PR efficiently.
Description
This PR fixes an issue where Validation Meta annotations were not being correctly recognized by the ModelResolver.
Problem
When developers use composed validation annotations (for example, a custom @MyNotBlank built on top of @NotBlank), swagger-core failed to introspect these Meta annotations, causing validation metadata to be lost in generated models.
Solution
Enhanced ModelResolver to introspect and apply Meta annotations properly.
A new test class ComposedConstraintMetaAnnotationTest verifies correct handling of composed constraint annotations.
Fixes: #4886
Type of Change
- [x] 🐛 Bug fix
- [x] 🧪 Tests
Checklist
- [x] I have added/updated tests as needed
- [x] The PR title is descriptive
- [x] The code builds and passes tests locally (
mvn clean test/gradle test) - [x] I have linked related issue #4886
Screenshots / Additional Context
-
Verified that composed constraint annotations are now detected and applied.
-
No regressions in direct annotation handling.
-
Affected files:
modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.javamodules/swagger-core/src/test/java/io/swagger/v3/core/resolving/ComposedConstraintMetaAnnotationTest.java
Hi @kuntal1461, Thanks a lot for providing the PR, it is a step in the right direction to resolve Validation Meta annotations issue.
To be able to merge these changes we need some adjustments:
- #4960 fix should be removed from this PR
- resolving Validation Meta annotations does currently work on a path variable in a Controller which means that at least part of the code could be reused in the case of DTOs as well. The logic for controllers meta annotations is in
ParameterProcessorand it needs to be adjusted before applying it inModelResolver. Maybe consider moving it to a new class - the logic currently recognizes only
javax.validation.*.jakarta.validation.*should be recognized as well - Test: - Add the new test using jakarta.validation.constraints.* - Test composed constraints for @Size, @Pattern etc - Add a parameter vs. DTO parity test to prevent regressions