Allow templates to use maxItems and minItems for Arrays (#4309)

Issue 3925
This commit is contained in:
JasonNorth
2017-01-06 11:57:29 +00:00
committed by wing328
parent c0f1716fe7
commit 5686109cc9
2 changed files with 14 additions and 1 deletions

View File

@@ -49,7 +49,10 @@ public class CodegenProperty implements Cloneable {
public boolean isInherited;
public String nameInCamelCase; // property name in camel case
// enum name based on the property name, usually use as a prefix (e.g. VAR_NAME) for enum name (e.g. VAR_NAME_VALUE1)
public String enumName;
public String enumName;
public Integer maxItems;
public Integer minItems;
@Override
public String toString() {
@@ -117,6 +120,8 @@ public class CodegenProperty implements Cloneable {
result = prime * result + Objects.hashCode(isInherited);
result = prime * result + Objects.hashCode(nameInCamelCase);
result = prime * result + Objects.hashCode(enumName);
result = prime * result + ((maxItems == null) ? 0 : maxItems.hashCode());
result = prime * result + ((minItems == null) ? 0 : minItems.hashCode());
return result;
}
@@ -283,6 +288,12 @@ public class CodegenProperty implements Cloneable {
if (!Objects.equals(this.enumName, other.enumName)) {
return false;
}
if (this.maxItems != other.maxItems && (this.maxItems == null || !this.maxItems.equals(other.maxItems))) {
return false;
}
if (this.minItems != other.minItems && (this.minItems == null || !this.minItems.equals(other.minItems))) {
return false;
}
return true;
}

View File

@@ -1691,6 +1691,8 @@ public class DefaultCodegen {
property.baseType = getSwaggerType(p);
// handle inner property
ArrayProperty ap = (ArrayProperty) p;
property.maxItems = ap.getMaxItems();
property.minItems = ap.getMinItems();
CodegenProperty cp = fromProperty(property.name, ap.getItems());
updatePropertyForArray(property, cp);
} else if (p instanceof MapProperty) {