You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
For typescript-fetch, when a discriminator parent model also has a property (or array property) typed as one of its own discriminator children, the generated parent file imports only XxxFromJSONTyped / XxxToJSON / XxxToJSONTyped for that child, but property deserialization still calls XxxFromJSON(...).
This produces a TypeScript compile error:
error TS2552: Cannot find name 'RemoteInventoryFromJSON'. Did you mean 'RemoteInventoryToJSON'?
modelGeneric.mustache emitting a compact discriminator import that omits {{modelName}}FromJSON.
Property mapping still generating {{datatype}}FromJSON(...).
When the child is only used as a discriminator mapping (not also as a property), this is fine. When it is also a property type on the same parent, the missing FromJSON import breaks the build.
openapi-generator version
Confirmed with 7.24.0 (openapi-generator-cli).
The buggy import line is still present on master in modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache.
This specific case (inheritance discriminator parent + property typed as child → missing FromJSON import in modelGeneric.mustache) does not appear to have an open dedicated issue.
Suggest a fix
In modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache, include {{modelName}}FromJSON in the discriminator mapped-model import:
{{#discriminator}}
{{#discriminator.mappedModels}}
import { type {{modelName}}, {{modelName}}FromJSON, {{modelName}}FromJSONTyped, {{modelName}}ToJSON, {{modelName}}ToJSONTyped } from './{{modelName}}{{importFileExtension}}';
{{/discriminator.mappedModels}}
{{/discriminator}}
Alternative (also valid): emit property deserialization with XxxFromJSONTyped(json, false) instead of XxxFromJSON(json), so it matches the symbols already imported for discriminator children.
The first option is the smallest template change and matches how normal tsImports already import both FromJSON and FromJSONTyped.
Bug Report Checklist
Description
For
typescript-fetch, when a discriminator parent model also has a property (or array property) typed as one of its own discriminator children, the generated parent file imports onlyXxxFromJSONTyped/XxxToJSON/XxxToJSONTypedfor that child, but property deserialization still callsXxxFromJSON(...).This produces a TypeScript compile error:
Root cause appears to be the combination of:
TypeScriptFetchClientCodegen.postProcessAllModelsfiltering discriminator mapped models out of normaltsImports(to avoid duplicate imports; introduced for [BUG][typescript-fetch] duplicate imports for models with a discriminator #15637 / [FIX][typescript-fetch] Fix duplicate imports for models with a discriminator #19195).modelGeneric.mustacheemitting a compact discriminator import that omits{{modelName}}FromJSON.{{datatype}}FromJSON(...).When the child is only used as a discriminator mapping (not also as a property), this is fine. When it is also a property type on the same parent, the missing
FromJSONimport breaks the build.openapi-generator version
Confirmed with 7.24.0 (
openapi-generator-cli).The buggy import line is still present on
masterinmodules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache.OpenAPI declaration file content or url
Generation Details
Steps to reproduce
typescript-fetchas shown.models/InventoryEntity.ts.RemoteInventoryFromJSONis used but not imported.tscfails with TS2552.Actual output
Expected output
Related issues/PRs
tsImports, which sets up this failure mode.modelOneOf.mustache). Related symptom, different template/path.ToJSON/ hierarchy handling. Not this import bug.This specific case (inheritance discriminator parent + property typed as child → missing
FromJSONimport inmodelGeneric.mustache) does not appear to have an open dedicated issue.Suggest a fix
In
modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache, include{{modelName}}FromJSONin the discriminator mapped-model import:Alternative (also valid): emit property deserialization with
XxxFromJSONTyped(json, false)instead ofXxxFromJSON(json), so it matches the symbols already imported for discriminator children.The first option is the smallest template change and matches how normal
tsImportsalready import bothFromJSONandFromJSONTyped.