Search in sources :

Example 36 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class ModelSerializerTest method deserializeModelWithReadOnlyProperty.

@Test(description = "it should deserialize a model with read-only property")
public void deserializeModelWithReadOnlyProperty() throws IOException {
    final String json = "{\n" + "   \"properties\":{\n" + "      \"id\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\",\n" + "         \"readOnly\":true\n" + "      }\n" + "   }\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    Property property = model.getProperties().get("id");
    assertTrue(property.getReadOnly());
}
Also used : ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) DateProperty(io.swagger.models.properties.DateProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 37 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class ModelSerializerTest method testIssue1852.

@Test
public void testIssue1852() throws Exception {
    String json = "{\n" + "  \"type\": \"integer\",\n" + "  \"minimum\": 10,\n" + "  \"maximum\": 20,\n" + "  \"default\": 15\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    assertEquals(model.getMinimum().intValue(), 10);
    assertEquals(model.getMaximum().intValue(), 20);
    assertEquals(model.getDefaultValue(), 15);
}
Also used : ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 38 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class ModelSerializerTest method testIssue2064Ip.

@Test
public void testIssue2064Ip() throws Exception {
    String json = "{\n" + "  \"type\": \"object\",\n" + "  \"properties\": {\n" + "    \"id\": {\n" + "      \"type\": \"integer\",\n" + "      \"format\": \"int32\",\n" + "      \"multipleOf\": 3.0\n" + "    }\n" + "  }\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    IntegerProperty ip = (IntegerProperty) model.getProperties().get("id");
    assertEquals(ip.getMultipleOf(), new BigDecimal("3.0"));
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ModelImpl(io.swagger.models.ModelImpl) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 39 with ModelImpl

use of io.swagger.models.ModelImpl 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 40 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class GericModelConverter method resolve.

@Override
public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> next) {
    if (type instanceof Class<?>) {
        Class<?> cls = (Class<?>) type;
        if (GenericModel.class.isAssignableFrom(cls)) {
            ModelImpl impl = new ModelImpl();
            impl.setName(cls.getSimpleName());
            for (Entry<String, Class<?>> entry : GenericModel.getDeclaredProperties().entrySet()) {
                impl.addProperty(entry.getKey(), context.resolveProperty(entry.getValue(), null));
            }
            context.defineModel(impl.getName(), impl);
            return impl;
        }
    }
    return null;
}
Also used : ModelImpl(io.swagger.models.ModelImpl)

Aggregations

ModelImpl (io.swagger.models.ModelImpl)46 Test (org.testng.annotations.Test)37 Model (io.swagger.models.Model)24 Property (io.swagger.models.properties.Property)17 StringProperty (io.swagger.models.properties.StringProperty)16 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 BodyParameter (io.swagger.models.parameters.BodyParameter)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 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