forked from loafle/openapi-generator-original
to fix #2306
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.*;
|
||||
public class CodegenModel {
|
||||
public String parent, parentSchema;
|
||||
public String name, classname, description, classVarName, modelJson, dataType;
|
||||
public String classFilename; // store the class file name, mainly used for import
|
||||
public String unescapedDescription;
|
||||
public String discriminator;
|
||||
public String defaultValue;
|
||||
|
||||
@@ -877,6 +877,7 @@ public class DefaultCodegen {
|
||||
m.unescapedDescription = model.getDescription();
|
||||
m.classname = toModelName(name);
|
||||
m.classVarName = toVarName(name);
|
||||
m.classFilename = toModelFilename(name);
|
||||
m.modelJson = Json.pretty(model);
|
||||
m.externalDocs = model.getExternalDocs();
|
||||
m.vendorExtensions = model.getVendorExtensions();
|
||||
|
||||
@@ -212,8 +212,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(modelNamePrefix + name + modelNameSuffix); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
@@ -223,6 +222,14 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
name = name + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
@@ -230,6 +237,10 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + underscore(dropDots("object_" + name)));
|
||||
|
||||
Reference in New Issue
Block a user