Skip to content

Conversation

@kuntal1461
Copy link
Contributor


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

  • 🐛 Bug fix
  • 🧪 Tests

Checklist


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.java
    • modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/ComposedConstraintMetaAnnotationTest.java

@ewaostrowska ewaostrowska force-pushed the bug/4886-validation-meta-annotations branch from def7aee to 9268835 Compare October 29, 2025 07:19
@ewaostrowska
Copy link
Contributor

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:

  • [Bug]: SpecFilter skips the ApiResponse#$ref field #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 ParameterProcessor and it needs to be adjusted before applying it in ModelResolver. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation Meta annotations not working

2 participants