forked from loafle/openapi-generator-original
remove fixme by setting param to final and creating local variable for sanitising model name (#3525)
- general cleanup (cherry picked from commit 88cf7e801f78a6611fc0d63479c78296e7312419)
This commit is contained in:
parent
ffaeb11a61
commit
d0f0e17542
@ -98,7 +98,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
"object"
|
||||
));
|
||||
|
||||
languageGenericTypes = new HashSet<>(Arrays.asList(
|
||||
languageGenericTypes = new HashSet<>(Collections.singletonList(
|
||||
"Array"
|
||||
));
|
||||
|
||||
@ -181,7 +181,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
this.setNpmVersion(openAPI.getInfo().getVersion());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.parseBoolean(additionalProperties.get(SNAPSHOT).toString())) {
|
||||
if (npmVersion.toUpperCase(Locale.ROOT).matches("^.*-SNAPSHOT$")) {
|
||||
this.setNpmVersion(npmVersion + "." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||
} else {
|
||||
@ -264,46 +264,45 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
final String regex = "^.*[+*:;,.()-]+.*$";
|
||||
final Pattern pattern = Pattern.compile(regex);
|
||||
final Matcher matcher = pattern.matcher(str);
|
||||
boolean matches = matcher.matches();
|
||||
return matches;
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
public String toModelName(final String name) {
|
||||
ArrayList<String> exceptions = new ArrayList<String>(Arrays.asList("\\|", " "));
|
||||
name = sanitizeName(name, "(?![| ])\\W", exceptions); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
String sanName = sanitizeName(name, "(?![| ])\\W", exceptions);
|
||||
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
sanName = modelNamePrefix + "_" + sanName;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
name = name + "_" + modelNameSuffix;
|
||||
sanName = sanName + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = camelize("model_" + name);
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
if (isReservedWord(sanName)) {
|
||||
String modelName = camelize("model_" + sanName);
|
||||
LOGGER.warn(sanName + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (name.matches("^\\d.*")) {
|
||||
String modelName = camelize("model_" + name); // e.g. 200Response => Model200Response (after camelize)
|
||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + modelName);
|
||||
if (sanName.matches("^\\d.*")) {
|
||||
String modelName = camelize("model_" + sanName); // e.g. 200Response => Model200Response (after camelize)
|
||||
LOGGER.warn(sanName + " (model name starts with number) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
if (languageSpecificPrimitives.contains(name)) {
|
||||
String modelName = camelize("model_" + name);
|
||||
LOGGER.warn(name + " (model name matches existing language type) cannot be used as a model name. Renamed to " + modelName);
|
||||
if (languageSpecificPrimitives.contains(sanName)) {
|
||||
String modelName = camelize("model_" + sanName);
|
||||
LOGGER.warn(sanName + " (model name matches existing language type) cannot be used as a model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
return camelize(sanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user