Skip to content

fix(typescript-fetch): optional nullable fields return null instead of undefined - #24215

Merged
wing328 merged 2 commits into
OpenAPITools:masterfrom
mstojanovic8:master
Jul 6, 2026
Merged

wing328 merged 2 commits into
OpenAPITools:masterfrom
mstojanovic8:master

Conversation

@mstojanovic8

@mstojanovic8 mstojanovic8 commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

When an optional field is marked as nullable in the spec, FromJSONTyped now returns null (not undefined) when the API returns null. Non-nullable optional fields continue to return undefined as before.

Fixes #5670

PR checklist

  • Read the contribution guidelines.
  • Regenerated typescript-fetch samples: ./bin/generate-samples.sh ./bin/configs/typescript-fetch*
  • 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.

cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha @dennisameling


Summary by cubic

Make typescript-fetch models return null for optional nullable fields when the API sends null, and undefined when the field is missing. Non-nullable optionals are unchanged. Fixes #5670.

  • Bug Fixes

    • Use strict checks (=== undefined / === null) in modelGeneric.mustache so FromJSONTyped distinguishes missing vs explicit null across primitives, dates, arrays/sets, maps, free-form objects, and object refs.
    • Added test testOptionalNullableFieldDeserializesToNull with nullable_property.json; regenerated petstore typescript-fetch samples.
    • Updated samples/server/petstore/jaxrs-spec-enum/pom.xml to JUnit 5 (org.junit.jupiter) and maven-surefire-plugin/maven-failsafe-plugin 3.5.6 for reliable test runs.
  • Migration

    • If you relied on undefined for optional nullable fields, update checks to handle null (e.g., nullish coalescing). Missing fields still return undefined; non-nullable optional and required fields are unchanged.

Written for commit 1196727. Summary will update on new commits.

Review in cubic

…f undefined

  When an optional field is marked as nullable in the spec, FromJSONTyped
  now returns null (not undefined) when the API returns null. Non-nullable
  optional fields continue to return undefined as before.

  Fixes OpenAPITools#5670

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

4 issues found across 17 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts Outdated
Comment thread samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts Outdated

@macjohnny macjohnny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for the fix

@mstojanovic8

Copy link
Copy Markdown
Contributor Author

thanks for the fix

Thanks for the quick review! Looking forward to seeing this in the next release 🙌

@wing328

wing328 commented Jul 6, 2026

Copy link
Copy Markdown
Member

@mstojanovic8 thanks for the PR

can you please review the build failure when you've time?

let us know if you need help updating the samples

…f undefined

  Use strict equality (===) to distinguish between absent fields (undefined)
  and explicitly null fields. When an optional nullable field is absent from
  the JSON response, it returns undefined. When it is explicitly null, it
  returns null instead of undefined.

  Fixes OpenAPITools#5670
@wing328
wing328 merged commit efb214e into OpenAPITools:master Jul 6, 2026
37 checks passed
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.

[BUG] [typescript-fetch] null output shadowed for optional, nullable values

3 participants