Search in sources :

Example 6 with ModelImpl

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");
}
Also used : ModelImpl(io.swagger.models.ModelImpl) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 7 with ModelImpl

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());
}
Also used : Xml(io.swagger.models.Xml) Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 8 with ModelImpl

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);
}
Also used : Xml(io.swagger.models.Xml) Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 9 with ModelImpl

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");
}
Also used : AbstractModelWithApiModel(io.swagger.models.composition.AbstractModelWithApiModel) Model(io.swagger.models.Model) ModelWithApiModel(io.swagger.models.ModelWithApiModel) EmptyModel(io.swagger.models.EmptyModel) JodaDateTimeModel(io.swagger.models.JodaDateTimeModel) JacksonReadonlyModel(io.swagger.models.JacksonReadonlyModel) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 10 with ModelImpl

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");
}
Also used : BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) AbstractModelWithApiModel(io.swagger.models.composition.AbstractModelWithApiModel) Model(io.swagger.models.Model) ModelWithApiModel(io.swagger.models.ModelWithApiModel) EmptyModel(io.swagger.models.EmptyModel) JodaDateTimeModel(io.swagger.models.JodaDateTimeModel) JacksonReadonlyModel(io.swagger.models.JacksonReadonlyModel) StringProperty(io.swagger.models.properties.StringProperty) ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) ModelWithUrlProperty(io.swagger.models.composition.ModelWithUrlProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Aggregations

ModelImpl (io.swagger.models.ModelImpl)45 Test (org.testng.annotations.Test)37 Model (io.swagger.models.Model)23 Property (io.swagger.models.properties.Property)16 StringProperty (io.swagger.models.properties.StringProperty)15 ArrayProperty (io.swagger.models.properties.ArrayProperty)12 IntegerProperty (io.swagger.models.properties.IntegerProperty)11 RefProperty (io.swagger.models.properties.RefProperty)9 Xml (io.swagger.models.Xml)8 RefModel (io.swagger.models.RefModel)7 LongProperty (io.swagger.models.properties.LongProperty)7 MapProperty (io.swagger.models.properties.MapProperty)7 ApiModel (io.swagger.annotations.ApiModel)6 ApiModelProperty (io.swagger.annotations.ApiModelProperty)6 BodyParameter (io.swagger.models.parameters.BodyParameter)6 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)5 ComposedModel (io.swagger.models.ComposedModel)5 EmptyModel (io.swagger.models.EmptyModel)4 JacksonReadonlyModel (io.swagger.models.JacksonReadonlyModel)4 JodaDateTimeModel (io.swagger.models.JodaDateTimeModel)4