Add support for Bean Validation's constraint groups#940
Add support for Bean Validation's constraint groups#940nosan wants to merge 1 commit intospring-projects:mainfrom
Conversation
a232a20 to
f6319bf
Compare
|
@wilkinsona |
|
I have very little time for REST Docs at the moment but I shouldn't have let this sit for so long without at least acknowledging it. Sorry. I'll try to make some time to look at it properly in the next few days. |
|
No pressure - take your time. I just wanted to check if it makes sense to proceed, since there's a merge conflict, and understand what to do with the pull request. |
|
I've finally found some time to review this. Thanks for the PR, @nosan, and for your patience. I consider groups to be a concept that's specific to bean validation. As such, I'd prefer to minimise how many classes know about that concept. If I were to do that building on what REST Docs offers today, I'd use a custom sub-class of public class ValidatorGroupConstraintResolver extends ValidatorConstraintResolver {
private final Class<?> group;
public ValidatorGroupConstraintResolver(Class<?> group) {
this.group = group;
}
@Override
public List<Constraint> resolveForProperty(String property, Class<?> clazz) {
return super.resolveForProperty(property, clazz).stream()
.filter((constraint) -> isMember(constraint, this.group))
.toList();
}
private boolean isMember(Constraint constraint, Class<?> group) {
for (Class<?> candidate : (Class<?>[]) constraint.getConfiguration().get("groups")) {
if (group.isAssignableFrom(candidate)) {
return true;
}
}
return false;
}
}I think it might be worth REST Docs making this a bit easier as, for example, dealing with the inheritance of the groups is somewhat subtle (I think I've got that right by using |
Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
gh-887
ConstraintDescriptionscan be extended with additional methods withgroupsas an argument.P.S. docs also need to be updated.