use of io.swagger.models.apideclaration.Items in project swagger-parser by swagger-api.
the class ModelPropertyConverterTest method convertStringArrayModelProperty.
@Test
public void convertStringArrayModelProperty() throws Exception {
ModelProperty property = new ModelProperty();
property.setType("array");
Items items = new Items();
items.setType("string");
property.setItems(items);
Property converted = converter.convertProperty(property);
assertEquals(converted.getClass(), ArrayProperty.class);
ArrayProperty prop = (ArrayProperty) converted;
Property innerType = prop.getItems();
assertEquals(innerType.getType(), "string");
}
use of io.swagger.models.apideclaration.Items 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;
}
use of io.swagger.models.apideclaration.Items in project swagger-parser by swagger-api.
the class ModelPropertyConverterTest method convertRefArrayModelProperty.
@Test
public void convertRefArrayModelProperty() throws Exception {
ModelProperty property = new ModelProperty();
property.setType("array");
Items items = new Items();
items.setRef("Pet");
property.setItems(items);
Property converted = converter.convertProperty(property);
assertEquals(converted.getClass(), ArrayProperty.class);
ArrayProperty prop = (ArrayProperty) converted;
Property innerType = prop.getItems();
RefProperty ref = (RefProperty) innerType;
assertEquals(ref.getSimpleRef(), "Pet");
}
use of io.swagger.models.apideclaration.Items in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method modelFromExtendedTypedObject.
public Model modelFromExtendedTypedObject(ExtendedTypedObject obj) {
String type = obj.getType() == null ? null : obj.getType().toString();
String format = obj.getFormat() == null ? null : obj.getFormat().toString();
Model output = null;
if (obj.getRef() != null) {
output = new RefModel().asDefault(obj.getRef());
} else {
if ("array".equals(type)) {
ArrayModel am = new ArrayModel();
Items items = obj.getItems();
type = items.getType() == null ? null : items.getType().toString();
format = items.getFormat() == null ? null : items.getFormat().toString();
Property innerType = PropertyBuilder.build(type, format, null);
if (innerType != null) {
am.setItems(innerType);
}
if (items.getRef() != null) {
am.setItems(new RefProperty(items.getRef()));
} else {
am.setItems(new RefProperty(type));
}
output = am;
} else {
Property input = PropertyBuilder.build(type, format, null);
if (input != null) {
output = PropertyBuilder.toModel(input);
} else if (!"void".equals(type)) {
// use ref model
output = new RefModel().asDefault(type);
}
}
}
return output;
}
Aggregations