-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HandlerMethodValidator
should support simple Cross-Parameter constraints
#33271
Comments
Thanks for the report. It would help a lot if you could provide snippets, or a small sample to experiment with. |
HandlerMethodValidator
should support simple Cross-Parameter constraints
I will post one later today. Note that it will simply be a |
Example added. |
Workaround added. |
Thanks for the sample. For cross-parameter validation, the property path has the method node and then a cross-parameter node, but no other useful info on which parameters were validated or what the argument values were. Is that because the At any rate, a cross-parameter violation does not fit into the current model where a We could create a |
I 100% agree that the current model doesn't fit. The challenge in my mind is, at the end of the day, we need a single exception type that holds all method argument This exception type should contain violations of cross-parameter constraints and violations of individual arguments annotated with This would provide a complete solution for handling pre-method execution The
|
I'm not sure what you mean. You do raise a point that with method level
For the rest, I proposed above a |
I see that Cross-parameter validation results are not included in the result of I noticed that |
I've been trying to create a test that results in a |
It seems sensible that the
HandlerMethodValidator
should directly handle Cross-Parameter constraints or at a minimum not throw anIllegalArgumentException
.Similarly to
@Valid
annotations on@RequestBody
arguments, Cross-Parameter constraints are applied only if another argument of the method has an@Constriant
declared.Unfortunately, unless the
ConstraintValidatorContext
of theConstraintValidator.isValid
method is manipulated with a newConstraintViolation
that has a node kind in its path thatMethodValidationAdapter.adaptViolations
handles (PROPERTY
,RETURN_VALUE
,PARAMETER
) an exception is thrown:Here is a spring-boot-based example (apologies for not having time to do a 'pure' spring-framework one without security)
(Hacky) Workaround
This workaround will create two violations, one for each parameter with the same message.
The text was updated successfully, but these errors were encountered: