Skip to content

fix(typescript-fetch): convert models inside nested arrays and maps - #25672

Open
thekhegay wants to merge 2 commits into
OpenAPITools:masterfrom
thekhegay:fix/ts-fetch-nested-containers
Open

thekhegay wants to merge 2 commits into
OpenAPITools:masterfrom
thekhegay:fix/ts-fetch-nested-containers

Conversation

@thekhegay

@thekhegay thekhegay commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Commit all changed files.
  • 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.

Written for commit 207ff8a. Summary will update on new commits.

View guided diff

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

All reported issues were addressed across 7 files

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

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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][typescript-fetch] Dictionaries with arrays of objects with custom types are not deserialized using custom deserializer

1 participant