mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-17 09:29:11 +00:00
Fix handling of --model-name-prefix|suffix in typescript-angular (#2590)
These will be removed as well when generating import path & model file names. Previously only the language-specific `modelSuffix` was removed.
This commit is contained in:
committed by
William Cheng
parent
4d1c115f8f
commit
596354ec17
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
@@ -501,7 +502,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
HashMap<String, String> 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(removeModelSuffixIfNecessary(im)));
|
||||
tsImport.put("filename", toModelFilename(removeModelPrefixSuffix(im)));
|
||||
tsImports.add(tsImport);
|
||||
}
|
||||
}
|
||||
@@ -590,11 +591,21 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
return modelName + modelSuffix;
|
||||
}
|
||||
|
||||
private String removeModelSuffixIfNecessary(String name) {
|
||||
if (modelSuffix.length() == 0 || !name.endsWith(modelSuffix)) {
|
||||
return name;
|
||||
public String removeModelPrefixSuffix(String name) {
|
||||
String result = name;
|
||||
if (modelSuffix.length() > 0 && result.endsWith(modelSuffix)) {
|
||||
result = result.substring(0, result.length() - modelSuffix.length());
|
||||
}
|
||||
return name.substring(0, name.length() - modelSuffix.length());
|
||||
String prefix = capitalize(this.modelNamePrefix);
|
||||
String suffix = capitalize(this.modelNameSuffix);
|
||||
if (prefix.length() > 0 && result.startsWith(prefix)) {
|
||||
result = result.substring(prefix.length());
|
||||
}
|
||||
if (suffix.length() > 0 && result.endsWith(suffix)) {
|
||||
result = result.substring(0, result.length() - suffix.length());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -648,7 +659,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
* @return the transformed name
|
||||
*/
|
||||
private String convertUsingFileNamingConvention(String originalName) {
|
||||
String name = this.removeModelSuffixIfNecessary(originalName);
|
||||
String name = this.removeModelPrefixSuffix(originalName);
|
||||
if ("kebab-case".equals(fileNaming)) {
|
||||
name = dashize(underscore(name));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user