From 8d8e3ddf16f2e79c24faf50fb3436b8f545d852f Mon Sep 17 00:00:00 2001 From: Stefan Paul Noack Date: Wed, 18 Jun 2025 16:50:20 +0200 Subject: [PATCH] fix(typescript-fetch): use `type` modifier on imports for `discriminator.mappedModels` (#21397) * typescript-fetch: use `type` modifier on imports for `discriminator.mappedModels` This ensures that the generated code works when `--verbatimModuleSyntax` is enabled for the TypeScript compiler. Regular imports already use the `type` modifier, so this should not be a breaking change. * update samples --- .../src/main/resources/typescript-fetch/modelGeneric.mustache | 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 +- .../builds/snakecase-discriminator/models/Animal.ts | 4 ++-- 5 files changed, 8 insertions(+), 8 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 25265adf980..454f2c68b79 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 { {{modelName}}, {{modelName}}FromJSONTyped, {{modelName}}ToJSON, {{modelName}}ToJSONTyped } from './{{modelName}}{{importFileExtension}}'; +import { type {{modelName}}, {{modelName}}FromJSONTyped, {{modelName}}ToJSON, {{modelName}}ToJSONTyped } from './{{modelName}}{{importFileExtension}}'; {{/discriminator.mappedModels}} {{/discriminator}} {{>modelGenericInterfaces}} 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 ad4ece85fb3..fda9bb25bb6 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 { InternalAuthenticatedUserDto, InternalAuthenticatedUserDtoFromJSONTyped, InternalAuthenticatedUserDtoToJSON, InternalAuthenticatedUserDtoToJSONTyped } from './InternalAuthenticatedUserDto'; -import { RemoteAuthenticatedUserDto, RemoteAuthenticatedUserDtoFromJSONTyped, RemoteAuthenticatedUserDtoToJSON, RemoteAuthenticatedUserDtoToJSONTyped } from './RemoteAuthenticatedUserDto'; +import { type InternalAuthenticatedUserDto, InternalAuthenticatedUserDtoFromJSONTyped, InternalAuthenticatedUserDtoToJSON, InternalAuthenticatedUserDtoToJSONTyped } from './InternalAuthenticatedUserDto'; +import { type RemoteAuthenticatedUserDto, 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 a6fed19c73b..d7831b21cab 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 { Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; -import { Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; +import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; +import { type Dog, 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 410f2d732cc..fdc763ac2e4 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 { ChildWithNullable, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; +import { type ChildWithNullable, 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 6edfcf07925..ae195a01bfa 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 { Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; -import { Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; +import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; +import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** * * @export