Skip to content

Comments

fix(java) #10010 oneOf and readOnly inheritance#23012

Open
thorstenhirsch wants to merge 4 commits intoOpenAPITools:masterfrom
thorstenhirsch:fix/java-10010
Open

fix(java) #10010 oneOf and readOnly inheritance#23012
thorstenhirsch wants to merge 4 commits intoOpenAPITools:masterfrom
thorstenhirsch:fix/java-10010

Conversation

@thorstenhirsch
Copy link
Contributor

@thorstenhirsch thorstenhirsch commented Feb 19, 2026

The java generator has problems with oneOf wrapper inheritance and inherited readOnly @JsonCreator as you can see in e.g. #10010. An example spec that results in broken generated code is e.g. https://app.swaggerhub.com/apis/cashlink-dev/issuer-api/v2

This PR fixes the issues, so that the java generator will generate compilable code and unit tests.

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.

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)


Summary by cubic

Stops using oneOf wrapper schemas as parent classes and fixes @JsonCreator for inherited readOnly fields in the Java generator. Generates compilable models and updated samples. Fixes #10010.

  • Bug Fixes
    • Detect oneOf wrapper schemas (oneOf + properties/discriminator) and inline their properties instead of treating them as parents.
    • Skip wrappers in parent resolution to avoid invalid inheritance.
    • Mark inherited readOnly vars and generate protected setters; update Java native pojo.mustache so @JsonCreator calls setters (handles JsonNullable too).
    • Add unit tests for both scenarios and update petstore Java native samples.

Written for commit 35e1a2f. Summary will update on new commits.

@thorstenhirsch thorstenhirsch marked this pull request as ready for review February 19, 2026 18:20
Copy link
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 12 files

Prompt for AI agents (all 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="modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache:98">
P2: Inherited readOnly properties with `x-is-jackson-optional-nullable` call the protected setter with a `JsonNullable<T>` value, but the setter expects `T`, causing a compile-time type mismatch in generated code.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

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

this();
{{#readOnlyVars}}
this.{{name}} = {{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}};
{{#vendorExtensions.x-is-inherited-readonly}}this.set{{nameInPascalCase}}({{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}});{{/vendorExtensions.x-is-inherited-readonly}}{{^vendorExtensions.x-is-inherited-readonly}}this.{{name}} = {{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}};{{/vendorExtensions.x-is-inherited-readonly}}
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 19, 2026

Choose a reason for hiding this comment

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

P2: Inherited readOnly properties with x-is-jackson-optional-nullable call the protected setter with a JsonNullable<T> value, but the setter expects T, causing a compile-time type mismatch in generated code.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache, line 98:

<comment>Inherited readOnly properties with `x-is-jackson-optional-nullable` call the protected setter with a `JsonNullable<T>` value, but the setter expects `T`, causing a compile-time type mismatch in generated code.</comment>

<file context>
@@ -95,7 +95,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
   this();
   {{#readOnlyVars}}
-    this.{{name}} = {{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}};
+    {{#vendorExtensions.x-is-inherited-readonly}}this.set{{nameInPascalCase}}({{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}});{{/vendorExtensions.x-is-inherited-readonly}}{{^vendorExtensions.x-is-inherited-readonly}}this.{{name}} = {{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}};{{/vendorExtensions.x-is-inherited-readonly}}
   {{/readOnlyVars}}
   }{{/withXml}}{{/vendorExtensions.x-has-readonly-properties}}
</file context>
Fix with Cubic

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.

[BUG] [JAVA] openapi-generator-maven-plugin does not handle allOf composed of multiple objects

1 participant