Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[core] Handle referenced enum case correctly
  • Loading branch information
jmini committed Jan 28, 2019
commit 031f980724ef789aa8844b4e95f02a9276852142
Original file line number Diff line number Diff line change
Expand Up @@ -1989,57 +1989,17 @@ public CodegenProperty fromProperty(String name, Schema p) {
if (property.minimum != null || property.maximum != null)
property.hasValidation = true;

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();

if (p.getEnum() != null) {
List<Object> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (Object i : _enum) {
property._enum.add(String.valueOf(i));
}
property.isEnum = true;
allowableValues.put("values", _enum);
}

if (allowableValues.size() > 0) {
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isBooleanSchema(p)) { // boolean type
property.isBoolean = true;
property.getter = toBooleanGetter(name);
} else if (ModelUtils.isDateSchema(p)) { // date format
property.isString = false; // for backward compatibility with 2.x
property.isDate = true;
if (p.getEnum() != null) {
List<String> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (String i : _enum) {
property._enum.add(i);
}
property.isEnum = true;

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isDateTimeSchema(p)) { // date-time format
property.isString = false; // for backward compatibility with 2.x
property.isDateTime = true;
if (p.getEnum() != null) {
List<String> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (String i : _enum) {
property._enum.add(i);
}
property.isEnum = true;

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isStringSchema(p)) {
if (ModelUtils.isByteArraySchema(p)) {
property.isByteArray = true;
Expand Down Expand Up @@ -2067,16 +2027,6 @@ public CodegenProperty fromProperty(String name, Schema p) {
if (property.pattern != null || property.minLength != null || property.maxLength != null)
property.hasValidation = true;

if (p.getEnum() != null) {
List<String> _enum = p.getEnum();
property._enum = _enum;
property.isEnum = true;

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isNumberSchema(p)) {
property.isNumeric = Boolean.TRUE;
if (ModelUtils.isFloatSchema(p)) { // float
Expand Down Expand Up @@ -2105,21 +2055,35 @@ public CodegenProperty fromProperty(String name, Schema p) {
if (property.minimum != null || property.maximum != null)
property.hasValidation = true;

if (p.getEnum() != null && !p.getEnum().isEmpty()) {
List<Object> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (Object i : _enum) {
property._enum.add(String.valueOf(i));
}
property.isEnum = true;
} else if (ModelUtils.isFreeFormObject(p)){
property.isFreeFormObject = true;
}

//Inline enum case:
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
List<Object> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (Object i : _enum) {
property._enum.add(String.valueOf(i));
}
property.isEnum = true;

Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
if (allowableValues.size() > 0) {
property.allowableValues = allowableValues;
}
}
//Referenced enum case:
Schema r = ModelUtils.getReferencedSchema(globalOpenAPI, p);
if (r.getEnum() != null && !r.getEnum().isEmpty()) {
List<Object> _enum = r.getEnum();

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
if (allowableValues.size() > 0) {
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isFreeFormObject(p)){
property.isFreeFormObject = true;
}

property.dataType = getTypeDeclaration(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ public String getAlias(String name) {

@Override
public String toDefaultValue(Schema p) {
p = ModelUtils.getReferencedSchema(globalOpenAPI, p);
if (ModelUtils.isArraySchema(p)) {
final ArraySchema ap = (ArraySchema) p;
final String pattern;
Expand Down