From c254c2399aa18f5b0d1c30417f2e33654af76361 Mon Sep 17 00:00:00 2001 From: kdelay Date: Fri, 14 Aug 2026 13:40:19 +0900 Subject: [PATCH] fix(typescript-fetch): import FromJSON for discriminator mapped models The discriminator import line in modelGeneric.mustache omitted {{modelName}}FromJSON. Mapped models are filtered out of tsImports so that line is their only import, which breaks when the child model is also used as a property type on the parent: property deserialization emits XFromJSON(...) and tsc fails with TS2552. Closes #24654 --- .../src/main/resources/typescript-fetch/modelGeneric.mustache | 2 +- .../infinite-recursion-issue/models/TestBaseDto.ts | 2 +- .../self-import-issue/models/AbstractUserDto.ts | 4 ++-- .../typescript-fetch/builds/default-v3.0/models/Animal.ts | 4 ++-- .../builds/default-v3.0/models/ParentWithNullable.ts | 2 +- .../typescript-fetch/builds/kebab-case/models/animal.ts | 4 ++-- .../builds/kebab-case/models/parent-with-nullable.ts | 2 +- .../builds/snakecase-discriminator/models/Animal.ts | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache index e2a1fcf328bb..da8c20213a6d 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache @@ -13,7 +13,7 @@ import { {{/hasImports}} {{#discriminator}} {{#discriminator.mappedModels}} -import { type {{modelName}}, {{modelName}}FromJSONTyped, {{modelName}}ToJSON, {{modelName}}ToJSONTyped } from './{{modelName}}{{importFileExtension}}'; +import { type {{modelName}}, {{modelName}}FromJSON, {{modelName}}FromJSONTyped, {{modelName}}ToJSON, {{modelName}}ToJSONTyped } from './{{modelName}}{{importFileExtension}}'; {{/discriminator.mappedModels}} {{/discriminator}} {{>modelGenericInterfaces}} diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts index e2db40b1d1fb..eb2a7f792dcd 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts @@ -21,7 +21,7 @@ import { TestObjectTypeToJSONTyped, } from './TestObjectType'; -import { type ExtendDto, ExtendDtoFromJSONTyped, ExtendDtoToJSON, ExtendDtoToJSONTyped } from './ExtendDto'; +import { type ExtendDto, ExtendDtoFromJSON, ExtendDtoFromJSONTyped, ExtendDtoToJSON, ExtendDtoToJSONTyped } from './ExtendDto'; /** * * @export diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts index 23066259cb7f..2ce5ef991a44 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts @@ -21,8 +21,8 @@ import { BranchDtoToJSONTyped, } from './BranchDto'; -import { type InternalAuthenticatedUserDto, InternalAuthenticatedUserDtoFromJSONTyped, InternalAuthenticatedUserDtoToJSON, InternalAuthenticatedUserDtoToJSONTyped } from './InternalAuthenticatedUserDto'; -import { type RemoteAuthenticatedUserDto, RemoteAuthenticatedUserDtoFromJSONTyped, RemoteAuthenticatedUserDtoToJSON, RemoteAuthenticatedUserDtoToJSONTyped } from './RemoteAuthenticatedUserDto'; +import { type InternalAuthenticatedUserDto, InternalAuthenticatedUserDtoFromJSON, InternalAuthenticatedUserDtoFromJSONTyped, InternalAuthenticatedUserDtoToJSON, InternalAuthenticatedUserDtoToJSONTyped } from './InternalAuthenticatedUserDto'; +import { type RemoteAuthenticatedUserDto, RemoteAuthenticatedUserDtoFromJSON, RemoteAuthenticatedUserDtoFromJSONTyped, RemoteAuthenticatedUserDtoToJSON, RemoteAuthenticatedUserDtoToJSONTyped } from './RemoteAuthenticatedUserDto'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts index 2a8b126041f7..c60d0dbc8f1a 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts @@ -13,8 +13,8 @@ */ import { mapValues } from '../runtime'; -import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; -import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; +import { type Cat, CatFromJSON, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; +import { type Dog, DogFromJSON, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts index 05c2dbb3775f..847925239293 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts @@ -13,7 +13,7 @@ */ import { mapValues } from '../runtime'; -import { type ChildWithNullable, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; +import { type ChildWithNullable, ChildWithNullableFromJSON, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts index 2a8b126041f7..c60d0dbc8f1a 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts @@ -13,8 +13,8 @@ */ import { mapValues } from '../runtime'; -import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; -import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; +import { type Cat, CatFromJSON, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; +import { type Dog, DogFromJSON, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts index 05c2dbb3775f..847925239293 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts @@ -13,7 +13,7 @@ */ import { mapValues } from '../runtime'; -import { type ChildWithNullable, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; +import { type ChildWithNullable, ChildWithNullableFromJSON, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts index 3b1b2fcdc204..9beda6b05c5a 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts @@ -13,8 +13,8 @@ */ import { mapValues } from '../runtime'; -import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; -import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; +import { type Cat, CatFromJSON, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; +import { type Dog, DogFromJSON, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** * * @export