forked from loafle/openapi-generator-original
[typescript-fetch] [BUG] Fix duplication of ModelNamePrefix in import statements (#20109)
This commit is contained in:
parent
474307675b
commit
d29196a1f0
@ -477,7 +477,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
|||||||
HashMap<String, String> tsImport = new HashMap<>();
|
HashMap<String, String> tsImport = new HashMap<>();
|
||||||
// TVG: This is used as class name in the import statements of the model file
|
// TVG: This is used as class name in the import statements of the model file
|
||||||
tsImport.put("classname", im);
|
tsImport.put("classname", im);
|
||||||
tsImport.put("filename", toModelFilename(im));
|
tsImport.put("filename", convertUsingFileNamingConvention(im));
|
||||||
tsImports.add(tsImport);
|
tsImports.add(tsImport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,6 +266,22 @@ public class TypeScriptFetchClientCodegenTest {
|
|||||||
codegen.toApiFilename("FirstSimpleController"));
|
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<String, Object> 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")
|
@Test(description = "Verify names of files generated in kebab-case and imports")
|
||||||
public void testGeneratedFilenamesInKebabCase() throws IOException {
|
public void testGeneratedFilenamesInKebabCase() throws IOException {
|
||||||
|
|
||||||
@ -281,6 +297,22 @@ public class TypeScriptFetchClientCodegenTest {
|
|||||||
TestUtils.assertFileExists(Paths.get(output + "/apis/pet-controller-api.ts"));
|
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<String, Object> 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")
|
@Test(description = "Verify names of files generated in camelCase and imports")
|
||||||
public void testGeneratedFilenamesInCamelCase() throws IOException {
|
public void testGeneratedFilenamesInCamelCase() throws IOException {
|
||||||
|
|
||||||
@ -296,6 +328,22 @@ public class TypeScriptFetchClientCodegenTest {
|
|||||||
TestUtils.assertFileExists(Paths.get(output + "/apis/petControllerApi.ts"));
|
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<String, Object> 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<String, Object> properties) throws IOException {
|
private static File generate(Map<String, Object> properties) throws IOException {
|
||||||
File output = Files.createTempDirectory("test").toFile();
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
output.deleteOnExit();
|
output.deleteOnExit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user