fix csharp extra comma in constructor

This commit is contained in:
wing328
2016-04-01 22:16:23 +08:00
parent f7affc6344
commit be13632bb4
7 changed files with 40 additions and 14 deletions

View File

@@ -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());

View File

@@ -2220,9 +2220,13 @@ 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()) {
List<Map.Entry<String, Property>> propertyList = new ArrayList<Map.Entry<String, Property>>(properties.entrySet());
final int totalCount = propertyList.size();
//for (Iterator<Map.Entry<String, Property>> it = properties.entrySet().iterator(); it.hasNext(); ) {
//for (Map.Entry<String, Property> entry : properties.entrySet()) {
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 +2240,22 @@ 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
//Map.Entry<String, Property> nextEntry = propertyList.get(i+1);
//final Property nextProp = propertyList.get(i+1).getValue();
if (!Boolean.TRUE.equals(propertyList.get(i+1).getValue().getReadOnly())) {
cp.hasMoreNonReadOnly = true;
LOGGER.info("set hasMoreNonReadONly to true");
}
}
if (cp.isContainer != null) {
addImport(m, typeMapping.get("array"));
}
addImport(m, cp.baseType);
addImport(m, cp.complexType);
vars.add(cp);

View File

@@ -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?");