use of io.swagger.models.properties.UntypedProperty in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method propertyFromTypedObject.
public Property propertyFromTypedObject(ExtendedTypedObject obj) {
String type = obj.getType() == null ? null : obj.getType().toString();
String format = obj.getFormat() == null ? null : obj.getFormat().toString();
Property output = null;
if ("array".equals(type)) {
ArrayProperty am = new ArrayProperty();
Items items = obj.getItems();
if (items == null) {
LOGGER.error("Error! Missing array type for property! Assuming `object` -- please fix your spec");
items = new Items();
items.setType("object");
}
type = items.getType() == null ? null : items.getType().toString();
format = items.getFormat() == null ? null : items.getFormat().toString();
Map<PropertyBuilder.PropertyId, Object> args = new HashMap<>();
if (items.getExtraFields().get("enum") != null && items.getExtraFields().get("enum").isArray()) {
ArrayNode an = (ArrayNode) items.getExtraFields().get("enum");
List<String> enumValues = new ArrayList<>();
for (JsonNode jn : an) {
enumValues.add(jn.textValue());
}
args.put(PropertyBuilder.PropertyId.ENUM, enumValues);
}
Property innerType = PropertyBuilder.build(type, format, args);
if (innerType != null && !(innerType instanceof UntypedProperty)) {
am.setItems(innerType);
} else if (items.getRef() != null) {
am.setItems(new RefProperty(items.getRef()));
} else {
am.setItems(new RefProperty(type));
}
output = am;
} else {
Map<PropertyBuilder.PropertyId, Object> args = new HashMap<PropertyBuilder.PropertyId, Object>();
if (obj.getEnumValues() != null && obj.getEnumValues().size() > 0) {
args.put(PropertyBuilder.PropertyId.ENUM, obj.getEnumValues());
}
if (obj.getMinimum() != null) {
args.put(PropertyBuilder.PropertyId.MINIMUM, new BigDecimal(obj.getMinimum()));
}
if (obj.getMaximum() != null) {
args.put(PropertyBuilder.PropertyId.MAXIMUM, new BigDecimal(obj.getMaximum()));
}
Property i = PropertyBuilder.build(type, format, args);
if (i != null && !(i instanceof UntypedProperty)) {
output = i;
} else {
if (obj.getRef() != null) {
output = new RefProperty(obj.getRef());
} else if (type != null && !type.equals("void")) {
output = new RefProperty(type);
}
}
}
return output;
}
Aggregations