Add support for Bean Validation's constraint groups

Open
#887 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
documentation

Research direction

Start with the ConstraintDescriptions API and its descriptionsForProperty method, which the issue identifies as the entry point. Trace how Bean Validation annotations are collected, then determine how a requested validation group should filter the returned descriptions; done means the documented example can retrieve only the OnCreate constraints for email.

Written by the indexing model from the issue text.

Description

type: enhancement

The docs gives an example of documenting constraints:

public void example() {
	ConstraintDescriptions userConstraints = new ConstraintDescriptions(UserInput.class);
	List<String> descriptions = userConstraints.descriptionsForProperty("name");
}

static class UserInput {

	@NotNull
	@Size(min = 1)
	String name;

	@NotNull
	@Size(min = 8)
	String password;

}

This way, you get all constraints descriptions for one property, but when using validation groups, how to get only the constraints descriptions for the given group? For example:

public void example() {
	ConstraintDescriptions userConstraints = new ConstraintDescriptions(UserInput.class);
        List<String> descriptions = userConstraints.descriptionsForProperty("email").groups(OnCreate.class);
}

static class UserInput {

	@NotNull
	String name;

        @NotNull(groups = OnCreate.class)
        @Null(groups = OnEdit.class)
        String email;
}
Dominant language
Java
Stars
1.2k
Forks
731
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-restdocs

All issues in spring-projects/spring-restdocs

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.