Repository navigation
feat: add opt-in support for validation annotations on Optional type arguments - #5358
Open
Mattias-Sehlstedt wants to merge 1 commit into
Conversation
Mattias-Sehlstedt
force-pushed
the
preserve-optional-type-argument-validations
branch
from
October 23, 2026 17:19
a6d76c8 to
6d94d4d
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 adds opt-in support for preserving validation annotations declared on Optional type arguments during model resolution.
The background is that I want to be able to discover annotation within optionals in the
ModelResolverchain, so that I can use these to express restrictions in my OAS. For example the customizer that springdoc-openapi offers springdoc/springdoc-openapi#3370.This is achieved with a new
ModelResolvertoggle,preserve-optional-type-argument-annotations, similar to that ofenums-as-ref. It utilizes the logic built for the already existingaddGenericTypeArgumentAnnotationsForOptionalField, which extracts these annotations, but only for the sake of feeding them to the bean resolver (the internal validation annotation introspection).This change also adds configurable predicate,
optionalTypeArgumentAnnotationsToPreserve, so additional type-use annotations can be preserved beyond the defaultJakartaValidation set.Type of Change
Checklist
Screenshots / Additional Context