use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class XmlModelTest method deserializeModel.
@Test(description = "it should deserialize a model")
public void deserializeModel() throws IOException {
final String yaml = "---\n" + "type: \"object\"\n" + "properties:\n" + " id:\n" + " type: \"string\"\n" + " xml:\n" + " attribute: true\n" + " name:\n" + " type: \"string\"\n" + " xml:\n" + " name: \"renamed\"\n" + " list:\n" + " type: \"array\"\n" + " items:\n" + " type: \"string\"\n" + " wrappedList:\n" + " type: \"array\"\n" + " xml:\n" + " name: \"wrappedListItems\"\n" + " wrapped: true\n" + " items:\n" + " type: \"string\"\n" + " forcedElement:\n" + " type: \"array\"\n" + " items:\n" + " type: \"string\"\n" + "xml:\n" + " name: \"rootName\"";
final ModelImpl model = io.swagger.util.Yaml.mapper().readValue(yaml, ModelImpl.class);
final Property wrappedList = model.getProperties().get("wrappedList");
assertNotNull(wrappedList);
assertNotNull(wrappedList.getXml());
assertEquals(wrappedList.getXml().getName(), "wrappedListItems");
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class XmlModelTest method processXMLModelAttribute.
@Test(description = "it should process an XML model attribute")
public void processXMLModelAttribute() {
final Map<String, Model> schemas = ModelConverters.getInstance().readAll(Monster.class);
final Model model = schemas.get("Monster");
assertNotNull(model);
assertTrue(model instanceof ModelImpl);
Xml xml = ((ModelImpl) model).getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "monster");
final Property property = model.getProperties().get("children");
assertNotNull(property);
xml = property.getXml();
assertTrue(xml.getWrapped());
assertNull(xml.getName());
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class XmlModelTest method itShouldNotCreateXmlObject.
@Test(description = "it should not create an xml object")
public void itShouldNotCreateXmlObject() {
final Map<String, Model> schemas = ModelConverters.getInstance().readAll(Address.class);
final Model model = schemas.get("Address");
assertNotNull(model);
assertTrue(model instanceof ModelImpl);
final Property property = model.getProperties().get("streetNumber");
final Xml xml = property.getXml();
assertNull(xml);
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelConverterTest method scanEmptyModel.
@Test(description = "it should scan an empty model per 499")
public void scanEmptyModel() {
final Map<String, Model> schemas = readAll(EmptyModel.class);
final ModelImpl model = (ModelImpl) schemas.get("EmptyModel");
assertNull(model.getProperties());
assertEquals(model.getType(), "object");
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelConverterTest method serializeParameterizedType.
@Test(description = "it should serialize a parameterized type per 606")
public void serializeParameterizedType() {
final Map<String, Model> schemas = readAll(Employee.class);
final ModelImpl employee = (ModelImpl) schemas.get("employee");
final Map<String, Property> props = employee.getProperties();
final Iterator<String> et = props.keySet().iterator();
final Property id = props.get(et.next());
assertTrue(id instanceof IntegerProperty);
final Property firstName = props.get(et.next());
assertTrue(firstName instanceof StringProperty);
final Property lastName = props.get(et.next());
assertTrue(lastName instanceof StringProperty);
final Property department = props.get(et.next());
assertTrue(department instanceof RefProperty);
final Property manager = props.get(et.next());
assertTrue(manager instanceof RefProperty);
final Property team = props.get(et.next());
assertTrue(team instanceof ArrayProperty);
final ArrayProperty ap = (ArrayProperty) team;
assertTrue(ap.getUniqueItems());
assertNotNull(employee.getXml());
assertEquals(employee.getXml().getName(), "employee");
}
Aggregations