Skip to content

feat(spring): add x-inner-validation vendor extension for collection items#23710

Open
adraarda23 wants to merge 2 commits intoOpenAPITools:masterfrom
adraarda23:feat/issue-23705-x-inner-validation
Open

feat(spring): add x-inner-validation vendor extension for collection items#23710
adraarda23 wants to merge 2 commits intoOpenAPITools:masterfrom
adraarda23:feat/issue-23705-x-inner-validation

Conversation

@adraarda23
Copy link
Copy Markdown

@adraarda23 adraarda23 commented May 7, 2026

Introduces a new field-level OpenAPI vendor extension x-inner-validation that places a custom annotation on the type argument of Java collections (List, Set) generated by the Spring server generator, enabling per-element bean validation constraints such as @NotNull. When set on the items schema, the generated POJO field, getter, setter and fluent builder all use the annotated parameterized type, e.g.:

private List<@jakarta.validation.constraints.NotNull Stubb> sample;

The implementation precomputes the full datatype string in SpringCodegen#postProcessModelProperty and exposes it via x-datatype-with-inner-annotation on the property; a small mustache partial (dataTypeWithInnerAnnotation) then renders that string or falls back to {{datatypeWithEnum}}, so existing models without the extension produce byte-identical output. The wrap is also propagated through JsonNullable<...> for nullable containers. Map / additionalProperties is intentionally not covered by this extension.

Scoped to the Spring generator on purpose: the issue author's reference attempt was on JavaSpring/pojo.mustache and Spring has no library overrides for that template, so coverage is complete here. Other Java and JaxRS generators have library-specific pojo overrides that would each need to be wired up separately; that can be added in a follow-up if requested.

Fixes #23705

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • 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

Adds x-inner-validation to the Spring generator to place type-use annotations on collection element types (e.g., List<@jakarta.validation.constraints.NotNull Foo>), enabling per-element bean validation. Docs now clarify the extension is set on the array/set items schema; fixes #23705.

  • New Features
    • Set x-inner-validation on array items to inject an annotation on List/Set element types; uses Set when uniqueItems: true.
    • Propagates to fields, getters, setters, fluent setters, and through JsonNullable<...>.
    • No change when absent; scoped to Spring only; not applied to Map/additionalProperties.

Written for commit 474c60c. Summary will update on new commits.

…items

Introduces a new field-level OpenAPI vendor extension `x-inner-validation`
that places a custom annotation on the type argument of Java collections
(`List`, `Set`) generated by the Spring server generator, enabling
per-element bean validation constraints such as `@NotNull`. When set on the
items schema, the generated POJO field, getter, setter and fluent builder
all use the annotated parameterized type, e.g.:

    private List<@jakarta.validation.constraints.NotNull Stubb> sample;

The implementation precomputes the full datatype string in
`SpringCodegen#postProcessModelProperty` and exposes it via
`x-datatype-with-inner-annotation` on the property; a small mustache
partial (`dataTypeWithInnerAnnotation`) then renders that string or falls
back to `{{datatypeWithEnum}}`, so existing models without the extension
produce byte-identical output. The wrap is also propagated through
`JsonNullable<...>` for nullable containers. Map / `additionalProperties`
is intentionally not covered by this extension.

Scoped to the Spring generator on purpose: the issue author's reference
attempt was on `JavaSpring/pojo.mustache` and Spring has no library
overrides for that template, so coverage is complete here. Other Java and
JaxRS generators have library-specific pojo overrides that would each need
to be wired up separately; that can be added in a follow-up if requested.

Fixes OpenAPITools#23705
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 10 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="docs/generators/spring.md">

<violation number="1" location="docs/generators/spring.md:147">
P2: The docs say `x-inner-validation` is a FIELD extension, but Spring only reads it from array/set `items`, so the placement is misleading.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread docs/generators/spring.md Outdated
Address cubic-dev-ai review (P2): the FIELD-level placement was
misleading because Spring reads the extension from the array/set
items schema, not directly from the property.
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.

[REQ] Possibilty of annoted type arguments with bean Validation for Java Collections

1 participant