forked from loafle/openapi-generator-original
Merge pull request #3187 from swagger-api/model_propert_same_name
[C#] Fix model with only read-only attributes and model & property using the same name
This commit is contained in:
@@ -37,6 +37,7 @@ public class CodegenModel {
|
||||
|
||||
public Set<String> imports = new TreeSet<String>();
|
||||
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, isArrayModel;
|
||||
public Boolean hasOnlyReadOnly = true; // true if all properties are read-only
|
||||
public ExternalDocs externalDocs;
|
||||
|
||||
public Map<String, Object> vendorExtensions;
|
||||
|
||||
@@ -2596,6 +2596,11 @@ public class DefaultCodegen {
|
||||
m.hasEnums = true;
|
||||
}
|
||||
|
||||
// set model's hasOnlyReadOnly to false if the property is read-only
|
||||
if (!Boolean.TRUE.equals(cp.isReadOnly)) {
|
||||
m.hasOnlyReadOnly = false;
|
||||
}
|
||||
|
||||
if (i+1 != totalCount) {
|
||||
cp.hasMore = true;
|
||||
// check the next entry to see if it's read only
|
||||
|
||||
@@ -259,7 +259,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
// check to see if model name is same as the property name
|
||||
// which will result in compilation error
|
||||
// if found, prepend with _ to workaround the limitation
|
||||
if (var.name.equals(cm.name)) {
|
||||
if (var.name.equalsIgnoreCase(cm.name)) {
|
||||
var.name = "_" + var.name;
|
||||
}
|
||||
}
|
||||
@@ -615,8 +615,6 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
enumName = camelize(enumName) + "Enum";
|
||||
|
||||
LOGGER.info("toEnumVarName = " + enumName);
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user