fix(typescript-fetch): optional nullable fields return null instead of undefined
Merged
MS
4mo ago+106+106+012345678901234567890123456789-57-57-01234567890123456789
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:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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) inmodelGeneric.mustachesoFromJSONTypeddistinguishes missing vs explicit null across primitives, dates, arrays/sets, maps, free-form objects, and object refs. - Added test
testOptionalNullableFieldDeserializesToNullwithnullable_property.json; regeneratedpetstoretypescript-fetchsamples. - Updated
samples/server/petstore/jaxrs-spec-enum/pom.xmlto JUnit 5 (org.junit.jupiter) andmaven-surefire-plugin/maven-failsafe-plugin3.5.6 for reliable test runs.
- Use strict checks (
-
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.