[Java][Spring] Fixing Invalid @Valid for List Body Parameters - #24806
[Java][Spring] Fixing Invalid @Valid for List Body Parameters#24806thiswasdumb wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
1 issue found across 318 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ArrayTest.java">
<violation number="1" location="samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ArrayTest.java:113">
P2: For nested containers (List<List<@Valid ReadOnlyFirst>>), removing the getter-level @Valid drops validation of the inner model entirely. The container-level @Valid is only redundant when the container's immediate type argument itself carries @Valid (e.g. List<@Valid Pet>); here the outer List's type argument (List<@Valid ReadOnlyFirst>) has no @Valid, so HV no longer cascades, and the inner ReadOnlyFirst elements are never validated. This needs a template fix, not just the sample: for a container whose item type is itself a container (isContainer && items.isContainer), keep @Valid on the outer getter or emit @Valid on the nested type argument.</violation>
</file>
Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.
Re-trigger cubic
| * @return arrayArrayOfInteger | ||
| */ | ||
| @jakarta.annotation.Nullable | ||
| @Valid |
There was a problem hiding this comment.
P2: For nested containers (List<List<@Valid ReadOnlyFirst>>), removing the getter-level @Valid drops validation of the inner model entirely. The container-level @Valid is only redundant when the container's immediate type argument itself carries @Valid (e.g. List<@Valid Pet>); here the outer List's type argument (List<@Valid ReadOnlyFirst>) has no @Valid, so HV no longer cascades, and the inner ReadOnlyFirst elements are never validated. This needs a template fix, not just the sample: for a container whose item type is itself a container (isContainer && items.isContainer), keep @Valid on the outer getter or emit @Valid on the nested type argument.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ArrayTest.java, line 113:
<comment>For nested containers (List<List<@Valid ReadOnlyFirst>>), removing the getter-level @Valid drops validation of the inner model entirely. The container-level @Valid is only redundant when the container's immediate type argument itself carries @Valid (e.g. List<@Valid Pet>); here the outer List's type argument (List<@Valid ReadOnlyFirst>) has no @Valid, so HV no longer cascades, and the inner ReadOnlyFirst elements are never validated. This needs a template fix, not just the sample: for a container whose item type is itself a container (isContainer && items.isContainer), keep @Valid on the outer getter or emit @Valid on the nested type argument.</comment>
<file context>
@@ -110,7 +110,6 @@ public ArrayTest addArrayArrayOfIntegerItem(List<Long> arrayArrayOfIntegerItem)
*/
@jakarta.annotation.Nullable
- @Valid
@JsonProperty(value = JSON_PROPERTY_ARRAY_ARRAY_OF_INTEGER, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
</file context>
Noted in #24752 and #24782 that when using a container, like a List, the
@Validannotation is incorrect and can have runtime issues when trying to handle the generated classes with the double@Valid.NOTE: I want to fix it to not just differentiate maps from the other containers, I am working on it to make it so containers have the same notation and will push when this is fixed.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Fixes the
@Validannotation placement for container properties in Java and Spring generators so generated code no longer carries a redundant container-level@Validon lists, sets, and arrays, which Hibernate Validator deprecates (HV000271) and which caused runtime issues when combined with type-argument@Valid. The container-level annotation is now only emitted forMapvalues, where no type-argument annotation exists.Java,JavaSpring, andjava-pkmsttemplates to emit@Validon containers only forMaptypes.Written for commit 2f69041. Summary will update on new commits.