forked from loafle/openapi-generator-original
Merge pull request #2484 from wing328/csharp_fix_constructor
[C#] fix extra comma in the constructor when last property is read-only
This commit is contained in:
@@ -32,6 +32,7 @@ public class CodegenProperty {
|
||||
public Boolean exclusiveMinimum;
|
||||
public Boolean exclusiveMaximum;
|
||||
public Boolean hasMore, required, secondaryParam;
|
||||
public Boolean hasMoreNonReadOnly; // for model constructor, true if next properyt is not readonly
|
||||
public Boolean isPrimitiveType, isContainer, isNotContainer;
|
||||
public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime;
|
||||
public Boolean isListContainer, isMapContainer;
|
||||
@@ -63,6 +64,7 @@ public class CodegenProperty {
|
||||
result = prime * result + ((exclusiveMinimum == null) ? 0 : exclusiveMinimum.hashCode());
|
||||
result = prime * result + ((getter == null) ? 0 : getter.hashCode());
|
||||
result = prime * result + ((hasMore == null) ? 0 : hasMore.hashCode());
|
||||
result = prime * result + ((hasMoreNonReadOnly == null) ? 0 : hasMoreNonReadOnly.hashCode());
|
||||
result = prime * result + ((isContainer == null) ? 0 : isContainer.hashCode());
|
||||
result = prime * result + (isEnum ? 1231 : 1237);
|
||||
result = prime * result + ((isNotContainer == null) ? 0 : isNotContainer.hashCode());
|
||||
|
||||
@@ -2220,9 +2220,12 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
private void addVars(CodegenModel m, List<CodegenProperty> vars, Map<String, Property> properties, Set<String> mandatory) {
|
||||
final int totalCount = properties.size();
|
||||
int count = 0;
|
||||
for (Map.Entry<String, Property> entry : properties.entrySet()) {
|
||||
// convert set to list so that we can access the next entry in the loop
|
||||
List<Map.Entry<String, Property>> propertyList = new ArrayList<Map.Entry<String, Property>>(properties.entrySet());
|
||||
final int totalCount = propertyList.size();
|
||||
for (int i = 0; i < totalCount; i++) {
|
||||
Map.Entry<String, Property> entry = propertyList.get(i);
|
||||
|
||||
final String key = entry.getKey();
|
||||
final Property prop = entry.getValue();
|
||||
|
||||
@@ -2236,13 +2239,19 @@ public class DefaultCodegen {
|
||||
// m.hasEnums to be set incorrectly if allProperties has enumerations but properties does not.
|
||||
m.hasEnums = true;
|
||||
}
|
||||
count++;
|
||||
if (count != totalCount) {
|
||||
|
||||
if (i+1 != totalCount) {
|
||||
cp.hasMore = true;
|
||||
// check the next entry to see if it's read only
|
||||
if (!Boolean.TRUE.equals(propertyList.get(i+1).getValue().getReadOnly())) {
|
||||
cp.hasMoreNonReadOnly = true; // next entry is not ready only
|
||||
}
|
||||
}
|
||||
|
||||
if (cp.isContainer != null) {
|
||||
addImport(m, typeMapping.get("array"));
|
||||
}
|
||||
|
||||
addImport(m, cp.baseType);
|
||||
addImport(m, cp.complexType);
|
||||
vars.add(cp);
|
||||
|
||||
@@ -101,6 +101,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("binary", "byte[]");
|
||||
typeMapping.put("bytearray", "byte[]");
|
||||
typeMapping.put("boolean", "bool?");
|
||||
typeMapping.put("integer", "int?");
|
||||
typeMapping.put("float", "float?");
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace {{packageName}}.Model
|
||||
/// </summary>
|
||||
{{#vars}}{{^isReadOnly}} /// <param name="{{name}}">{{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}.</param>
|
||||
{{/isReadOnly}}{{/vars}}
|
||||
public {{classname}}({{#vars}}{{^isReadOnly}}{{{datatypeWithEnum}}} {{name}} = null{{#hasMore}}, {{/hasMore}}{{/isReadOnly}}{{/vars}})
|
||||
public {{classname}}({{#vars}}{{^isReadOnly}}{{{datatypeWithEnum}}} {{name}} = null{{#hasMoreNonReadOnly}}, {{/hasMoreNonReadOnly}}{{/isReadOnly}}{{/vars}})
|
||||
{
|
||||
{{#vars}}{{^isReadOnly}}{{#required}}// to ensure "{{name}}" is required (not null)
|
||||
if ({{name}} == null)
|
||||
|
||||
@@ -1314,12 +1314,16 @@
|
||||
},
|
||||
"Name": {
|
||||
"description": "Model for testing model name same as property name",
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"snake_case": {
|
||||
"readOnly": true,
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
@@ -1375,6 +1379,59 @@
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"format_test" : {
|
||||
"type" : "object",
|
||||
"required": [
|
||||
"number"
|
||||
],
|
||||
"properties" : {
|
||||
"integer" : {
|
||||
"type": "integer"
|
||||
},
|
||||
"int32" : {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"int64" : {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"number" : {
|
||||
"type": "number"
|
||||
},
|
||||
"float" : {
|
||||
"type": "number",
|
||||
"format": "float"
|
||||
},
|
||||
"double" : {
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
},
|
||||
"string" : {
|
||||
"type": "string"
|
||||
},
|
||||
"byte" : {
|
||||
"type": "string",
|
||||
"format": "byte"
|
||||
},
|
||||
"binary" : {
|
||||
"type": "string",
|
||||
"format": "binary"
|
||||
},
|
||||
"date" : {
|
||||
"type": "string",
|
||||
"format": "date"
|
||||
},
|
||||
"dateTime" : {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"dateTime" : {
|
||||
"type": "string",
|
||||
"format": "password"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user