Search in sources :

Example 71 with ModelImpl

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

the class ByteConverterTest method testByteArray.

@Test
public void testByteArray() {
    Model model = new ModelImpl().property("byteArray", new ArrayProperty(new BinaryProperty()));
    assertEquals(Json.pretty(model), "{" + NEWLINE + "  \"properties\" : {" + NEWLINE + "    \"byteArray\" : {" + NEWLINE + "      \"type\" : \"array\"," + NEWLINE + "      \"items\" : {" + NEWLINE + "        \"type\" : \"string\"," + NEWLINE + "        \"format\" : \"binary\"" + NEWLINE + "      }" + NEWLINE + "    }" + NEWLINE + "  }" + NEWLINE + "}");
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) BinaryProperty(io.swagger.models.properties.BinaryProperty) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 72 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 73 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 74 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 75 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)

Aggregations

ModelImpl (io.swagger.models.ModelImpl)112 Test (org.testng.annotations.Test)46 Model (io.swagger.models.Model)43 Property (io.swagger.models.properties.Property)40 StringProperty (io.swagger.models.properties.StringProperty)32 RefProperty (io.swagger.models.properties.RefProperty)29 BodyParameter (io.swagger.models.parameters.BodyParameter)28 ArrayProperty (io.swagger.models.properties.ArrayProperty)27 RefModel (io.swagger.models.RefModel)24 IntegerProperty (io.swagger.models.properties.IntegerProperty)18 Swagger (io.swagger.models.Swagger)16 JavaType (com.fasterxml.jackson.databind.JavaType)15 Map (java.util.Map)15 MapProperty (io.swagger.models.properties.MapProperty)14 Test (org.junit.Test)14 Parameter (io.swagger.models.parameters.Parameter)12 HashMap (java.util.HashMap)12 ArrayModel (io.swagger.models.ArrayModel)11 ComposedModel (io.swagger.models.ComposedModel)11 ArrayList (java.util.ArrayList)11