diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index 875c881a397..69a0f3e8031 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -477,7 +477,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege HashMap tsImport = new HashMap<>(); // TVG: This is used as class name in the import statements of the model file tsImport.put("classname", im); - tsImport.put("filename", toModelFilename(im)); + tsImport.put("filename", convertUsingFileNamingConvention(im)); tsImports.add(tsImport); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java index 411d35827e3..ac0560194f6 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -266,6 +266,22 @@ public class TypeScriptFetchClientCodegenTest { codegen.toApiFilename("FirstSimpleController")); } + @Test(description = "Verify names of files generated in kebab-case and imports with additional model prefix") + public void testGeneratedFilenamesInPascalCaseWithAdditionalModelPrefix() throws IOException { + + Map properties = new HashMap<>(); + properties.put("fileNaming", TypeScriptFetchClientCodegen.PASCAL_CASE); + properties.put(CodegenConstants.MODEL_NAME_PREFIX, "SomePrefix"); + + File output = generate(properties); + + Path pet = Paths.get(output + "/models/SomePrefixPet.ts"); + TestUtils.assertFileExists(pet); + TestUtils.assertFileContains(pet, "} from './SomePrefixPetCategory';"); + TestUtils.assertFileExists(Paths.get(output + "/models/SomePrefixPetCategory.ts")); + TestUtils.assertFileExists(Paths.get(output + "/apis/PetControllerApi.ts")); + } + @Test(description = "Verify names of files generated in kebab-case and imports") public void testGeneratedFilenamesInKebabCase() throws IOException { @@ -281,6 +297,22 @@ public class TypeScriptFetchClientCodegenTest { TestUtils.assertFileExists(Paths.get(output + "/apis/pet-controller-api.ts")); } + @Test(description = "Verify names of files generated in kebab-case and imports with additional model prefix") + public void testGeneratedFilenamesInKebabCaseWithAdditionalModelPrefix() throws IOException { + + Map properties = new HashMap<>(); + properties.put("fileNaming", TypeScriptFetchClientCodegen.KEBAB_CASE); + properties.put(CodegenConstants.MODEL_NAME_PREFIX, "SomePrefix"); + + File output = generate(properties); + + Path pet = Paths.get(output + "/models/some-prefix-pet.ts"); + TestUtils.assertFileExists(pet); + TestUtils.assertFileContains(pet, "} from './some-prefix-pet-category';"); + TestUtils.assertFileExists(Paths.get(output + "/models/some-prefix-pet-category.ts")); + TestUtils.assertFileExists(Paths.get(output + "/apis/pet-controller-api.ts")); + } + @Test(description = "Verify names of files generated in camelCase and imports") public void testGeneratedFilenamesInCamelCase() throws IOException { @@ -296,6 +328,22 @@ public class TypeScriptFetchClientCodegenTest { TestUtils.assertFileExists(Paths.get(output + "/apis/petControllerApi.ts")); } + @Test(description = "Verify names of files generated in camelCase and imports with additional model prefix") + public void testGeneratedFilenamesInCamelCaseWithAdditionalModelPrefix() throws IOException { + + Map properties = new HashMap<>(); + properties.put("fileNaming", TypeScriptFetchClientCodegen.CAMEL_CASE); + properties.put(CodegenConstants.MODEL_NAME_PREFIX, "SomePrefix"); + + File output = generate(properties); + + Path pet = Paths.get(output + "/models/somePrefixPet.ts"); + TestUtils.assertFileExists(pet); + TestUtils.assertFileContains(pet, "} from './somePrefixPetCategory';"); + TestUtils.assertFileExists(Paths.get(output + "/models/somePrefixPetCategory.ts")); + TestUtils.assertFileExists(Paths.get(output + "/apis/petControllerApi.ts")); + } + private static File generate(Map properties) throws IOException { File output = Files.createTempDirectory("test").toFile(); output.deleteOnExit();