use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.
the class ApiDeclarationParser method readProperties.
List<ModelProperty> readProperties(Map<String, Object> properties, MessageBuilder messages) {
List<ModelProperty> output = new ArrayList<ModelProperty>();
for (String key : properties.keySet()) {
Map<String, Object> value = (Map<String, Object>) properties.get(key);
ModelProperty prop = new ModelProperty();
String type = readString(value.get("type"));
prop.setType(type);
String qualifiedType = readString(value.get("qualifiedType"));
output.add(prop);
}
return output;
}
use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method convertProperty.
public Property convertProperty(ModelProperty property) {
Property output = null;
output = propertyFromTypedObject(property);
output.setDescription(property.getDescription());
return output;
}
use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.
the class ModelConverterTest method convertModelWithPrimitives.
@Test
public void convertModelWithPrimitives() throws Exception {
io.swagger.models.apideclaration.Model model = new io.swagger.models.apideclaration.Model();
model.setDescription("the model");
Map<String, ModelProperty> properties = new LinkedHashMap<String, ModelProperty>();
ModelProperty id = new ModelProperty();
id.setType("integer");
id.setFormat(Format.INT64);
id.setDescription("the id property");
properties.put("id", id);
ModelProperty name = new ModelProperty();
name.setType("string");
name.setDescription("the name property");
properties.put("name", name);
model.setProperties(properties);
ModelProperty age = new ModelProperty();
age.setType("integer");
age.setFormat(Format.INT32);
age.setDescription("the age property");
properties.put("age", age);
model.setProperties(properties);
List<String> required = new ArrayList<String>();
required.add("id");
required.add("name");
model.setRequired(required);
Model converted = converter.convertModel(model);
assertEquals(model.getDescription(), converted.getDescription());
Map<String, Property> convertedProperties = converted.getProperties();
assertTrue(convertedProperties.size() == 3);
assertTrue(convertedProperties.keySet().iterator().next().equals("id"));
}
use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.
the class ModelConverterTest method convertModelWithSubtypes.
@Test
public void convertModelWithSubtypes() throws Exception {
io.swagger.models.apideclaration.Model model = new io.swagger.models.apideclaration.Model();
model.setDescription("the model");
model.setDiscriminator("type");
List<String> subtypes = new ArrayList<String>();
subtypes.add("Cat");
subtypes.add("Dog");
Map<String, ModelProperty> properties = new LinkedHashMap<String, ModelProperty>();
ModelProperty id = new ModelProperty();
id.setType("integer");
id.setFormat(Format.INT64);
id.setDescription("the id property");
properties.put("id", id);
ModelProperty type = new ModelProperty();
type.setType("string");
type.setDescription("the type property, which is the discriminator");
properties.put("type", type);
model.setProperties(properties);
Model converted = converter.convertModel(model);
// TODO: subtypes are not translated 1:1
}
use of io.swagger.models.apideclaration.ModelProperty 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");
}
Aggregations