Skip to content

feat: add opt-in support for validation annotations on Optional type arguments - #5358

Open
Mattias-Sehlstedt wants to merge 1 commit into
swagger-api:3.0.0from
Mattias-Sehlstedt:preserve-optional-type-argument-validations
Open

Mattias-Sehlstedt wants to merge 1 commit into
swagger-api:3.0.0from
Mattias-Sehlstedt:preserve-optional-type-argument-validations

Conversation

@Mattias-Sehlstedt

Copy link
Copy Markdown
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 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 ModelResolver chain, 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 ModelResolver toggle, preserve-optional-type-argument-annotations, similar to that of enums-as-ref. It utilizes the logic built for the already existing addGenericTypeArgumentAnnotationsForOptionalField, 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 default Jakarta Validation set.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the preserve-optional-type-argument-validations branch from a6d76c8 to 6d94d4d Compare October 23, 2026 17:19

This branch has not been deployed

No deployments
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.

1 participant