Skip to content

[Java] fix: map the OAS 3.1 null type to Object, not a never-generated ModelNull - #24935

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
renechoi:fix/issue-24520-java-null-type
Sep 14, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
renechoi:fix/issue-24520-java-null-type

Conversation

@renechoi

@renechoi renechoi commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

A Java property declared type: 'null' becomes ModelNull, which is never emitted, so generated clients fail to compile (regression in 7.17.0).

AbstractJavaCodegen lacks a null typeMapping, so getSchemaType falls through to toModelName("null"), where the reserved-word rule prefixes Model. Python, Go, Elixir, and Xojo already map null.

#24701 used unquoted type: null, which YAML parses as a null scalar, so it did not exercise this path. third_property adds the quoted form. Reverting the mapping makes the new unit test and sample compilation fail; patched, the sample compiles and the module suite passes 4,985 tests.

TypeScript still has this gap, so Ref #24520, not Fixes.

  • Read contribution guidelines.
  • Built and regenerated affected samples.
  • Java TC: /cc @xhh

Summary by cubic

Maps the OAS 3.1 null type to Object in Java codegen so properties declared type: 'null' no longer generate a reference to ModelNull, a class the generator never emits. This was a regression in 7.17.0 that made generated clients fail to compile; Python, Go, Elixir, and Xojo already map null.

Bug Fixes

  • The previous fixture used unquoted type: null, which YAML parses as a null scalar, so it didn't exercise this path; the new third_property uses the quoted form.
  • TypeScript still has this gap, so this addresses but does not close issue 24520.

Written for commit 412e049. Summary will update on new commits.

Review in cubic

…d ModelNull

AbstractJavaCodegen has no "null" entry in typeMapping, so getSchemaType falls
through to toModelName("null"). "null" is a Java reserved word, so the model
name becomes ModelNull, a class the generator never emits, and the generated
client does not compile. Python, Go, Elixir and Xojo already map "null" in
their typeMapping; this adds the Java one.

The 3_1 java fixture gains third_property with the quoted form of the null
type. The existing second_property uses unquoted "type: null", which YAML
reads as a null scalar, so that property carries no type at all and already
generated Object. Only bin/configs/java-okhttp-gson-3.1.yaml consumes this
fixture, and samples-java-petsore-client-jdk11 builds that sample, so the
regression is now covered in CI.

@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.

No issues found across 6 files

Re-trigger cubic

@wing328

wing328 commented Sep 14, 2026

Copy link
Copy Markdown
Member

thanks for the PR

cc @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) @KannaKim (2026/07)

@wing328 wing328 added this to the 7.26.0 milestone Sep 14, 2026
@wing328
wing328 merged commit 7ade6f2 into OpenAPITools:master Sep 14, 2026
149 of 151 checks passed
rar91279 added a commit to rar91279/openapi-generator that referenced this pull request Sep 14, 2026
Picks up OpenAPITools#24935, which maps the OAS 3.1 null type to Object instead of a
never-generated ModelNull. The 3.1 test spec gained a third_property
declaring the null type as the OAS 3.1 quoted string, so the sample now
carries that property as Object.

Regenerating all 129 java configs and exporting the generator docs produced
no other change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants