Skip to content

Support extracting Bean Validation constraints from method parameters#1035

Open
JunggiKim wants to merge 1 commit intospring-projects:mainfrom
JunggiKim:spring-restdocs-method-constraints
Open

Support extracting Bean Validation constraints from method parameters#1035
JunggiKim wants to merge 1 commit intospring-projects:mainfrom
JunggiKim:spring-restdocs-method-constraints

Conversation

@JunggiKim
Copy link
Copy Markdown

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 @RequestParam
and @PathVariable.

What changed

  • added ConstraintResolver#resolveForMethodParameter(Method, int) as a
    backward-compatible default method
  • implemented method parameter constraint extraction in
    ValidatorConstraintResolver using Bean Validation method metadata
  • added ConstraintDescriptions#descriptionsForMethodParameter(...)
    overloads for explicit method-based access
  • supported inherited methods when resolving constraints by method name
  • documented the new API and added a source-backed example

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

  • supports parameter-level Bean Validation constraints
  • does not attempt to handle cross-parameter constraints in this change

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 build

Fixes gh-1026

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support extracting Bean Validation constraints from method parameters

2 participants