Search in sources :

Example 1 with ModelConverterContextImpl

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

the class ContainerTest method testArray.

@Test
public void testArray() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Model model = context.resolve(ArrayBean.class);
    final Map<String, Property> props = model.getProperties();
    assertEquals(1, props.size());
    final Property prop = props.get("a");
    assertNotNull(prop);
    assertEquals(prop.getType(), "array");
    final Property items = ((ArrayProperty) prop).getItems();
    assertNotNull(items);
    assertEquals(items.getType(), "integer");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) 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 2 with ModelConverterContextImpl

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

the class EnumTest method testEnum.

@Test
public void testEnum() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Model model = context.resolve(Currency.class);
    assertNull(model);
    final Property property = context.resolveProperty(Currency.class, new Annotation[] {});
    assertNotNull(property);
    assertTrue(property instanceof StringProperty);
    final StringProperty strProperty = (StringProperty) property;
    assertNotNull(strProperty.getEnum());
    final Collection<String> values = new ArrayList<String>(Collections2.transform(Arrays.asList(Currency.values()), Functions.toStringFunction()));
    assertEquals(strProperty.getEnum(), values);
}
Also used : Model(io.swagger.models.Model) ArrayList(java.util.ArrayList) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) Property(io.swagger.models.properties.Property) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 3 with ModelConverterContextImpl

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

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

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

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