forked from loafle/openapi-generator-original
[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:
parent
524ef63e37
commit
15d31f753d
@ -604,11 +604,11 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelName(String name) {
|
public String toModelName(String name) {
|
||||||
String modelName = super.toModelName(name);
|
if (modelSuffix.length() != 0 && !name.endsWith(modelSuffix)) {
|
||||||
if (modelSuffix.length() == 0 || modelName.endsWith(modelSuffix)) {
|
name = name + modelSuffix;
|
||||||
return modelName;
|
|
||||||
}
|
}
|
||||||
return modelName + modelSuffix;
|
|
||||||
|
return super.toModelName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String removeModelPrefixSuffix(String name) {
|
public String removeModelPrefixSuffix(String name) {
|
||||||
|
@ -16,6 +16,16 @@ import org.testng.annotations.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class TypeScriptAngularClientCodegenTest {
|
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
|
@Test
|
||||||
public void testModelFileSuffix() {
|
public void testModelFileSuffix() {
|
||||||
TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
|
TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user