mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 08:39:19 +00:00
[core] Handle referenced enum case correctly (#2001)
* [core] Handle referenced enum case correctly * Update all samples * Fix compile error after merge
This commit is contained in:
committed by
William Cheng
parent
02a8dad77c
commit
c871e3bc81
@@ -1927,57 +1927,17 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
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;
|
||||
@@ -2005,16 +1965,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
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
|
||||
@@ -2043,23 +1993,37 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
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;
|
||||
|
||||
// legacy support
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
allowableValues.put("values", _enum);
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
} 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(this.openAPI, p);
|
||||
if (r.getEnum() != null && !r.getEnum().isEmpty()) {
|
||||
List<Object> _enum = r.getEnum();
|
||||
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
allowableValues.put("values", _enum);
|
||||
if (allowableValues.size() > 0) {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
property.dataType = getTypeDeclaration(p);
|
||||
property.dataFormat = p.getFormat();
|
||||
property.baseType = getSchemaType(p);
|
||||
|
||||
@@ -727,6 +727,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
p = ModelUtils.getReferencedSchema(this.openAPI, p);
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
final ArraySchema ap = (ArraySchema) p;
|
||||
final String pattern;
|
||||
|
||||
Reference in New Issue
Block a user