[typescript-angular] Sanitize/transform model name after appending model suffix (#5105)

This makes sure the final (suffixed) model name is checked against the TS keywords / reserved names.
This commit is contained in:
Alexey Makhrov 2020-01-24 13:59:48 -08:00 committed by Esteban Gehring
parent 524ef63e37
commit 15d31f753d
2 changed files with 14 additions and 4 deletions

View File

@ -604,11 +604,11 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
@Override
public String toModelName(String name) {
String modelName = super.toModelName(name);
if (modelSuffix.length() == 0 || modelName.endsWith(modelSuffix)) {
return modelName;
if (modelSuffix.length() != 0 && !name.endsWith(modelSuffix)) {
name = name + modelSuffix;
}
return modelName + modelSuffix;
return super.toModelName(name);
}
public String removeModelPrefixSuffix(String name) {

View File

@ -16,6 +16,16 @@ import org.testng.annotations.Test;
public class TypeScriptAngularClientCodegenTest {
@Test
public void testModelSuffix() {
TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
codegen.additionalProperties().put("modelSuffix", "MySuffix");
codegen.processOpts();
Assert.assertEquals(codegen.toModelName("TestName"), "TestNameMySuffix");
Assert.assertEquals(codegen.toModelName("Error"), "ErrorMySuffix");
}
@Test
public void testModelFileSuffix() {
TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();