Skip to content

[Java][Spring] Fixing Invalid @Valid for List Body Parameters - #24806

Draft
thiswasdumb wants to merge 3 commits into
OpenAPITools:masterfrom
thiswasdumb:java-valid-syntax
Draft

[Java][Spring] Fixing Invalid @Valid for List Body Parameters#24806
thiswasdumb wants to merge 3 commits into
OpenAPITools:masterfrom
thiswasdumb:java-valid-syntax

Conversation

@thiswasdumb

@thiswasdumb thiswasdumb commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Noted in #24752 and #24782 that when using a container, like a List, the @Valid annotation 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

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes the @Valid annotation placement for container properties in Java and Spring generators so generated code no longer carries a redundant container-level @Valid on 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 for Map values, where no type-argument annotation exists.

  • Update Java, JavaSpring, and java-pkmst templates to emit @Valid on containers only for Map types.
  • Regenerate all affected samples to match the new output.
  • Add unit tests covering List and Map property annotations.

Written for commit 2f69041. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@thiswasdumb
thiswasdumb marked this pull request as draft August 29, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant