Search in sources :

Example 1 with ModelConverter

use of io.swagger.converter.ModelConverter in project swagger-core by swagger-api.

the class XMLInfoTest method testReadingXmlAccessorTypeNone.

@Test
public void testReadingXmlAccessorTypeNone() throws Exception {
    final ModelConverter mr = modelResolver();
    final Model model = mr.resolve(XmlDecoratedBeanXmlAccessorNone.class, new ModelConverterContextImpl(mr), null);
    assertTrue(model instanceof ModelImpl);
    final ModelImpl impl = (ModelImpl) model;
    final Xml xml = impl.getXml();
    assertNotNull(xml);
    assertEquals(xml.getName(), "xmlDecoratedBean");
    final Property property = impl.getProperties().get("a");
    assertNotNull(property);
    assertNull(impl.getProperties().get("b"));
}
Also used : Xml(io.swagger.models.Xml) Model(io.swagger.models.Model) ApiModel(io.swagger.annotations.ApiModel) ModelImpl(io.swagger.models.ModelImpl) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelConverter(io.swagger.converter.ModelConverter) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 2 with ModelConverter

use of io.swagger.converter.ModelConverter in project swagger-core by swagger-api.

the class XMLInfoTest method testReadingXmlAccessorTypePublic.

@Test
public void testReadingXmlAccessorTypePublic() throws Exception {
    final ModelConverter mr = modelResolver();
    final Model model = mr.resolve(XmlDecoratedBeanXmlAccessorPublic.class, new ModelConverterContextImpl(mr), null);
    assertTrue(model instanceof ModelImpl);
    final ModelImpl impl = (ModelImpl) model;
    final Xml xml = impl.getXml();
    assertNotNull(xml);
    assertEquals(xml.getName(), "xmlDecoratedBean");
    final Property propertyA = impl.getProperties().get("a");
    assertNotNull(propertyA);
    Property propertyB = impl.getProperties().get("b");
    assertNotNull(propertyB);
}
Also used : Xml(io.swagger.models.Xml) Model(io.swagger.models.Model) ApiModel(io.swagger.annotations.ApiModel) ModelImpl(io.swagger.models.ModelImpl) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelConverter(io.swagger.converter.ModelConverter) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 3 with ModelConverter

use of io.swagger.converter.ModelConverter in project swagger-core by swagger-api.

the class JodaTest method testSimple.

@Test
public void testSimple() throws Exception {
    final ModelConverter mr = modelResolver();
    final Model model = mr.resolve(ModelWithJodaDateTime.class, new ModelConverterContextImpl(mr), null);
    assertNotNull(model);
    final Map<String, Property> props = model.getProperties();
    assertEquals(props.size(), 2);
    for (Map.Entry<String, Property> entry : props.entrySet()) {
        final String name = entry.getKey();
        final Property prop = entry.getValue();
        if ("name".equals(name)) {
            assertEquals(prop.getType(), "string");
        } else if ("createdAt".equals(name)) {
            assertEquals(prop.getType(), "string");
            assertEquals(prop.getFormat(), "date-time");
        } else {
            fail(String.format("Unknown property '%s'", name));
        }
    }
}
Also used : Model(io.swagger.models.Model) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Map(java.util.Map) ModelConverter(io.swagger.converter.ModelConverter) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 4 with ModelConverter

use of io.swagger.converter.ModelConverter in project swagger-core by swagger-api.

the class XMLInfoTest method testSimple.

@Test
public void testSimple() throws Exception {
    final ModelConverter mr = modelResolver();
    final Model model = mr.resolve(XmlDecoratedBean.class, new ModelConverterContextImpl(mr), null);
    assertTrue(model instanceof ModelImpl);
    final ModelImpl impl = (ModelImpl) model;
    final Xml xml = impl.getXml();
    assertNotNull(xml);
    assertEquals(xml.getName(), "xmlDecoratedBean");
    // Cast it to an array property
    final ArrayProperty property = (ArrayProperty) impl.getProperties().get("elements");
    assertNotNull(property);
    final Xml propertyXml = property.getXml();
    assertNotNull(propertyXml);
    assertNull(propertyXml.getName());
    assertTrue(propertyXml.getWrapped());
    // Get the xml for items for the array property
    final Xml itemsXml = property.getItems().getXml();
    assertNotNull(itemsXml);
    // Check the name of item name
    assertEquals(itemsXml.getName(), "element");
    assertNotNull(impl.getProperties().get("elementC"));
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Xml(io.swagger.models.Xml) Model(io.swagger.models.Model) ApiModel(io.swagger.annotations.ApiModel) ModelImpl(io.swagger.models.ModelImpl) ModelConverter(io.swagger.converter.ModelConverter) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Aggregations

ModelConverter (io.swagger.converter.ModelConverter)4 ModelConverterContextImpl (io.swagger.converter.ModelConverterContextImpl)4 Model (io.swagger.models.Model)4 Test (org.testng.annotations.Test)4 ApiModel (io.swagger.annotations.ApiModel)3 ModelImpl (io.swagger.models.ModelImpl)3 Xml (io.swagger.models.Xml)3 ArrayProperty (io.swagger.models.properties.ArrayProperty)3 Property (io.swagger.models.properties.Property)3 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 ApiModelProperty (io.swagger.annotations.ApiModelProperty)1 Map (java.util.Map)1