Skip to content
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

Method validation is not triggered when constraints are applied to the elements of a List #31870

Closed
mcso opened this issue Dec 20, 2023 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@mcso
Copy link

mcso commented Dec 20, 2023

In Spring Boot 3.2.0 it seems method validation is not always happening as expected, if the constraint is on list elements only. It can be worked around by applying @Valid or a @Constraint to the list, or by having another argument for the endpoint which has a @Constraint, but otherwise it seems to miss them.
I have attached a small demo project to illustrate it. I would expect all of the test cases to be a success, but the one with only a @Constraint applied to the list elements fails.
I haven't tested if the parameter is for example a map (if it is even possible in this context), but my guess is it has the same issue.

Spring Boot version: 3.2.0
Java version: OpenJDK 19 (19+36-2238)

demo.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 20, 2023
@bclozel
Copy link
Member

bclozel commented Dec 20, 2023

This looks similar to #31746
Can you have a look and let us know?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Dec 20, 2023
@bclozel bclozel transferred this issue from spring-projects/spring-boot Dec 20, 2023
@mcso
Copy link
Author

mcso commented Dec 20, 2023

I would say no, unless I have misunderstood the other issue.
The issue isn't the path is incorrect, it is that the (in this example) @NotBlank validation is not done for entries in the string list.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 20, 2023
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Dec 20, 2023
@rstoyanchev rstoyanchev self-assigned this Dec 20, 2023
@rstoyanchev rstoyanchev changed the title Method validation does not always see all constraints Method validation is not triggered when constraints are applied to the elements of a List Dec 21, 2023
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Dec 21, 2023

At present you need @Valid with a List method parameter, and we don't for example detect constraints on elements of a container. For example:

@GetMapping
public String get(@RequestParam(required = false) List<@NotBlank String> list) {
    // ... 
}

Given that we do make a decision whether method validation applies to a given controller method, we should enhance checks to include the above, which is supported by bean validation.

@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Dec 21, 2023
@rstoyanchev rstoyanchev added this to the 6.1.3 milestone Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants