Support extracting Bean Validation constraints from method parameters#1035
Open
JunggiKim wants to merge 1 commit intospring-projects:mainfrom
Open
Support extracting Bean Validation constraints from method parameters#1035JunggiKim wants to merge 1 commit intospring-projects:mainfrom
JunggiKim wants to merge 1 commit intospring-projects:mainfrom
Conversation
Add an explicit method-parameter constraint resolution path so ConstraintDescriptions can describe validation declared on controller method parameters as well as bean properties. ValidatorConstraintResolver now uses Bean Validation method metadata to extract parameter constraints. ConstraintDescriptions provides explicit method-based overloads and can resolve inherited methods when looking up constraints by name. The documentation also includes a source-backed example for method parameter constraints, and the tests cover positive, empty, inherited, and invalid-index scenarios. Fixes spring-projectsgh-1026 Signed-off-by: kjg <kimjg2477@gmail.com>
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.
Summary
This pull request adds support for extracting Bean Validation constraints
from method parameters so generated documentation can stay aligned with
validation declared on controller parameters such as
@RequestParamand
@PathVariable.What changed
ConstraintResolver#resolveForMethodParameter(Method, int)as abackward-compatible default method
ValidatorConstraintResolverusing Bean Validation method metadataConstraintDescriptions#descriptionsForMethodParameter(...)overloads for explicit method-based access
Why it is implemented this way
The goal was to extend the existing property-based constraint support
without introducing a separate abstraction layer or changing the current
resolution model.
The new API remains explicit and deterministic because the caller must
identify the target method and parameter index directly. The
implementation also stays close to the existing Bean Validation-based
resolution strategy by using method metadata from the validator.
Scope
Testing
./gradlew :spring-restdocs-core:test --tests org.springframework.restdocs.constraints.ValidatorConstraintResolverTests --tests org.springframework.restdocs.constraints.ConstraintDescriptionsTests./gradlew :spring-restdocs-docs:compileTestJava./gradlew check./gradlew buildFixes gh-1026