[java] Enum in array of array (#66)

This commit is contained in:
Jérémie Bresson
2018-05-18 19:01:11 +02:00
committed by GitHub
parent a1ff502411
commit 82ee8656fd
42 changed files with 122 additions and 124 deletions
@@ -19,8 +19,8 @@ package org.openapitools.codegen;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Map;
public class CodegenParameter {
public boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
@@ -38,6 +38,7 @@ public class CodegenParameter {
public List<String> _enum;
public Map<String, Object> allowableValues;
public CodegenProperty items;
public CodegenProperty mostInnerItems;
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
public boolean hasValidation;
@@ -142,6 +143,9 @@ public class CodegenParameter {
if (this.items != null) {
output.items = this.items;
}
if (this.mostInnerItems != null) {
output.mostInnerItems = this.mostInnerItems;
}
if(this.vendorExtensions != null){
output.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions);
}
@@ -259,6 +263,8 @@ public class CodegenParameter {
return false;
if (items != null ? !items.equals(that.items) : that.items != null)
return false;
if (mostInnerItems != null ? !mostInnerItems.equals(that.mostInnerItems) : that.mostInnerItems != null)
return false;
if (vendorExtensions != null ? !vendorExtensions.equals(that.vendorExtensions) : that.vendorExtensions != null)
return false;
if (hasValidation != that.hasValidation)
@@ -335,6 +341,7 @@ public class CodegenParameter {
result = 31 * result + (_enum != null ? _enum.hashCode() : 0);
result = 31 * result + (allowableValues != null ? allowableValues.hashCode() : 0);
result = 31 * result + (items != null ? items.hashCode() : 0);
result = 31 * result + (mostInnerItems != null ? mostInnerItems.hashCode() : 0);
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
result = 31 * result + (hasValidation ? 13:31);
result = 31 * result + (required ? 13:31);
@@ -399,6 +406,7 @@ public class CodegenParameter {
", _enum=" + _enum +
", allowableValues=" + allowableValues +
", items=" + items +
", mostInnerItems=" + mostInnerItems +
", vendorExtensions=" + vendorExtensions +
", hasValidation=" + hasValidation +
", required=" + required +
@@ -63,6 +63,7 @@ public class CodegenProperty implements Cloneable {
public List<String> _enum;
public Map<String, Object> allowableValues;
public CodegenProperty items;
public CodegenProperty mostInnerItems;
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
public boolean hasValidation; // true if pattern, maximum, etc are set (only used in the mustache template)
public boolean isInherited;
@@ -436,6 +437,7 @@ public class CodegenProperty implements Cloneable {
result = prime * result + ((isPrimitiveType ? 13:31));
result = prime * result + ((isReadOnly ? 13:31));
result = prime * result + ((items == null) ? 0 : items.hashCode());
result = prime * result + ((mostInnerItems == null) ? 0 : mostInnerItems.hashCode());
result = prime * result + ((jsonSchema == null) ? 0 : jsonSchema.hashCode());
result = prime * result + ((max == null) ? 0 : max.hashCode());
result = prime * result + ((maxLength == null) ? 0 : maxLength.hashCode());
@@ -700,6 +702,9 @@ public class CodegenProperty implements Cloneable {
if (this.items != null) {
cp.items = this.items;
}
if (this.mostInnerItems != null) {
cp.mostInnerItems = this.mostInnerItems;
}
if(this.vendorExtensions != null){
cp.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions);
}
@@ -766,6 +771,7 @@ public class CodegenProperty implements Cloneable {
", _enum=" + _enum +
", allowableValues=" + allowableValues +
", items=" + items +
", mostInnerItems=" + mostInnerItems +
", vendorExtensions=" + vendorExtensions +
", hasValidation=" + hasValidation +
", isInherited=" + isInherited +
@@ -1899,6 +1899,7 @@ public class DefaultCodegen implements CodegenConfig {
property.isPrimitiveType = true;
}
property.items = innerProperty;
property.mostInnerItems = getMostInnerItems(innerProperty);
// inner item is Enum
if (isPropertyInnerMostEnum(property)) {
// isEnum is set to true when the type is an enum
@@ -1930,6 +1931,7 @@ public class DefaultCodegen implements CodegenConfig {
property.isPrimitiveType = true;
}
property.items = innerProperty;
property.mostInnerItems = getMostInnerItems(innerProperty);
property.dataFormat = innerProperty.dataFormat;
// inner item is Enum
if (isPropertyInnerMostEnum(property)) {
@@ -1952,21 +1954,22 @@ public class DefaultCodegen implements CodegenConfig {
* @return True if the inner most type is enum
*/
protected Boolean isPropertyInnerMostEnum(CodegenProperty property) {
CodegenProperty currentProperty = property;
while (currentProperty != null && (Boolean.TRUE.equals(currentProperty.isMapContainer)
|| Boolean.TRUE.equals(currentProperty.isListContainer))) {
currentProperty = currentProperty.items;
}
CodegenProperty currentProperty = getMostInnerItems(property);
return currentProperty == null ? false : currentProperty.isEnum;
}
protected Map<String, Object> getInnerEnumAllowableValues(CodegenProperty property) {
protected CodegenProperty getMostInnerItems(CodegenProperty property) {
CodegenProperty currentProperty = property;
while (currentProperty != null && (Boolean.TRUE.equals(currentProperty.isMapContainer)
|| Boolean.TRUE.equals(currentProperty.isListContainer))) {
currentProperty = currentProperty.items;
}
return currentProperty;
}
protected Map<String, Object> getInnerEnumAllowableValues(CodegenProperty property) {
CodegenProperty currentProperty = getMostInnerItems(property);
return currentProperty == null ? new HashMap<String, Object>() : currentProperty.allowableValues;
}
@@ -2530,6 +2533,7 @@ public class DefaultCodegen implements CodegenConfig {
collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat;
CodegenProperty codegenProperty = fromProperty("inner", inner);
codegenParameter.items = codegenProperty;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
codegenParameter.baseType = codegenProperty.dataType;
codegenParameter.isContainer = true;
codegenParameter.isListContainer = true;
@@ -2544,6 +2548,7 @@ public class DefaultCodegen implements CodegenConfig {
} else if (ModelUtils.isMapSchema(parameterSchema)) { // for map parameter
CodegenProperty codegenProperty = fromProperty("inner", (Schema) parameterSchema.getAdditionalProperties());
codegenParameter.items = codegenProperty;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
codegenParameter.baseType = codegenProperty.dataType;
codegenParameter.isContainer = true;
codegenParameter.isMapContainer = true;
@@ -2598,6 +2603,7 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.datatypeWithEnum = codegenProperty.datatypeWithEnum;
codegenParameter.enumName = codegenProperty.enumName;
codegenParameter.items = codegenProperty.items;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
}
codegenParameter.collectionFormat = collectionFormat;
@@ -4084,6 +4090,7 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter = fromFormProperty(entry.getKey(), inner, imports);
CodegenProperty codegenProperty = fromProperty("inner", inner);
codegenParameter.items = codegenProperty;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
codegenParameter.baseType = codegenProperty.dataType;
codegenParameter.isPrimitiveType = false;
codegenParameter.isContainer = true;
@@ -4159,6 +4166,7 @@ public class DefaultCodegen implements CodegenConfig {
if (codegenProperty.items != null && codegenProperty.items.isEnum) {
codegenParameter.items = codegenProperty.items;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
}
// import
@@ -4238,6 +4246,7 @@ public class DefaultCodegen implements CodegenConfig {
}
codegenParameter.paramName = toParamName(codegenParameter.baseName);
codegenParameter.items = codegenProperty.items;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
codegenParameter.dataType = getTypeDeclaration(schema);
codegenParameter.baseType = getSchemaType(inner);
codegenParameter.isContainer = Boolean.TRUE;
@@ -4272,6 +4281,7 @@ public class DefaultCodegen implements CodegenConfig {
}
codegenParameter.paramName = toArrayModelParamName(codegenParameter.baseName);
codegenParameter.items = codegenProperty.items;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
codegenParameter.dataType = getTypeDeclaration(arraySchema);
codegenParameter.baseType = getSchemaType(arraySchema);
codegenParameter.isContainer = Boolean.TRUE;