fix(typescript-fetch): convert models inside nested arrays and maps
Core marks a container whose items are containers again as primitive (Array/Map base type is language primitive), so model template copies such property as is. For map of arrays of models (this issue), and same for array of arrays, array of maps and map of maps, FromJSON returns raw json: nested Date stays string, and ToJSON does not drop readOnly fields
TypeScriptFetchClientCodegen now builds conversion for such properties when innermost items are models and puts it into x-nestedFromJson / x-nestedToJson, e.g. mapValues(json['x'], (v0: any) => (v0 as Array<any>).map(BarFromJSON)). Template uses them with same null/undefined gaurds as existing array branch. Nested containers of primitives, enums, free-form objects or with uniqueItems keep current output
Added test in TypeScriptFetchClientCodegenTest for all four shapes, it fails on master. Sample changes: ArrayTest.arrayArrayOfModel in 3 typescript-fetch builds (default-v3.0, kebab-case, snakecase-discriminator), other 90 typescript configs unchanged. Typescript tests pass. Generated client for the test spec passes tsc --strict, ran it under node: nested when is Date after FromJSON and ISO string after ToJSON
Fixes #21730
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
Commit all changed files../mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha @KannaKim
Summary by cubic
Fixes #21730 by generating explicit FromJSON/ToJSON conversions for models nested inside arrays and maps in the typescript-fetch client.
Previously, nested containers of models were copied as-is, so FromJSON returned raw JSON (e.g. Date values stayed strings) and ToJSON kept readOnly fields. Now the generator detects when the innermost items are models and emits level-by-level conversion using map and mapValues, preserving null/undefined inner containers along the way. Nested containers of primitives, enums, free-form objects, or with uniqueItems keep the current output.