feat(spring): add x-inner-validation vendor extension for collection items#23710
Open
adraarda23 wants to merge 2 commits intoOpenAPITools:masterfrom
Open
feat(spring): add x-inner-validation vendor extension for collection items#23710adraarda23 wants to merge 2 commits intoOpenAPITools:masterfrom
adraarda23 wants to merge 2 commits intoOpenAPITools:masterfrom
Conversation
…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
Contributor
There was a problem hiding this comment.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a new field-level OpenAPI vendor extension
x-inner-validationthat 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.:The implementation precomputes the full datatype string in
SpringCodegen#postProcessModelPropertyand exposes it viax-datatype-with-inner-annotationon 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 throughJsonNullable<...>for nullable containers. Map /additionalPropertiesis intentionally not covered by this extension.Scoped to the Spring generator on purpose: the issue author's reference attempt was on
JavaSpring/pojo.mustacheand 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
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Adds
x-inner-validationto 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/setitemsschema; fixes #23705.x-inner-validationon arrayitemsto inject an annotation onList/Setelement types; usesSetwhenuniqueItems: true.JsonNullable<...>.Map/additionalProperties.Written for commit 474c60c. Summary will update on new commits.