Search in sources :

Example 6 with ModelConverterContextImpl

use of io.swagger.converter.ModelConverterContextImpl 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)

Example 7 with ModelConverterContextImpl

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

the class ATMTest method testATMModel.

@Test
public void testATMModel() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Model model = context.resolve(ATM.class);
    assertNotNull(model);
}
Also used : Model(io.swagger.models.Model) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 8 with ModelConverterContextImpl

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

the class ComplexPropertyTest method testOuterBean.

@Test
public void testOuterBean() throws Exception {
    final ModelResolver modelResolver = modelResolver();
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Model model = context.resolve(OuterBean.class);
    assertNotNull(model);
}
Also used : Model(io.swagger.models.Model) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 9 with ModelConverterContextImpl

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

the class ContainerTest method testMap.

@Test
public void testMap() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Model model = context.resolve(MapBean.class);
    final Map<String, Property> props = model.getProperties();
    assertEquals(1, props.size());
    final Property prop = props.get("stuff");
    assertNotNull(prop);
    assertEquals(prop.getType(), "object");
    final Property items = ((MapProperty) prop).getAdditionalProperties();
    assertNotNull(items);
    assertEquals(items.getType(), "string");
    assertEquals(items.getFormat(), "date-time");
}
Also used : MapProperty(io.swagger.models.properties.MapProperty) Model(io.swagger.models.Model) MapProperty(io.swagger.models.properties.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 10 with ModelConverterContextImpl

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

the class ContainerTest method testComplexMap.

@Test
public void testComplexMap() throws Exception {
    ModelResolver resolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(resolver);
    context.resolve(WrapperType.class);
    final Map<String, Model> models = context.getDefinedModels();
    final Model innerType = models.get("InnerType");
    assertNotNull(innerType);
    final Map<String, Property> innerProps = innerType.getProperties();
    assertEquals(innerProps.size(), 2);
    final Property foo = innerProps.get("foo");
    assertEquals(foo.getType(), "integer");
    assertEquals(foo.getFormat(), "int32");
    final Property name = innerProps.get("name");
    assertEquals(name.getType(), "string");
    final Model wrapperType = models.get("WrapperType");
    assertNotNull(wrapperType);
    assertEquals(wrapperType.getProperties().get("innerType").getType(), "object");
}
Also used : Model(io.swagger.models.Model) MapProperty(io.swagger.models.properties.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Aggregations

ModelConverterContextImpl (io.swagger.converter.ModelConverterContextImpl)11 Model (io.swagger.models.Model)10 Test (org.testng.annotations.Test)10 Property (io.swagger.models.properties.Property)7 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 ModelConverter (io.swagger.converter.ModelConverter)4 ApiModel (io.swagger.annotations.ApiModel)3 ModelImpl (io.swagger.models.ModelImpl)3 Xml (io.swagger.models.Xml)3 MapProperty (io.swagger.models.properties.MapProperty)3 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiModelProperty (io.swagger.annotations.ApiModelProperty)1 StringProperty (io.swagger.models.properties.StringProperty)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 BeforeTest (org.testng.annotations.BeforeTest)1