Search in sources :

Example 11 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class ModelPropertyConverterTest method convertStringModelPropertyWithEnum.

@Test
public void convertStringModelPropertyWithEnum() throws Exception {
    ModelProperty property = new ModelProperty();
    property.setType("string");
    property.setDescription("a simple string");
    List<String> enumValues = new ArrayList<String>();
    enumValues.add("cat");
    enumValues.add("dog");
    property.setEnumValues(enumValues);
    Property converted = converter.convertProperty(property);
    assertEquals(converted.getClass(), StringProperty.class);
    assertEquals(converted.getType(), "string");
    assertEquals(converted.getDescription(), property.getDescription());
    StringProperty prop = (StringProperty) converted;
    assertNotNull(prop.getEnum());
    assertTrue(prop.getEnum().size() == 2);
}
Also used : ModelProperty(io.swagger.models.apideclaration.ModelProperty) ArrayList(java.util.ArrayList) StringProperty(io.swagger.models.properties.StringProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 12 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class ModelPropertyConverterTest method convertLongModelProperty.

@Test
public void convertLongModelProperty() throws Exception {
    ModelProperty property = new ModelProperty();
    property.setType("integer");
    property.setFormat(Format.INT64);
    property.setDescription("a simple int64 property");
    property.setMinimum("1");
    property.setMaximum("4");
    Property converted = converter.convertProperty(property);
    assertEquals(converted.getClass(), LongProperty.class);
    assertEquals(converted.getType(), "integer");
    assertEquals(converted.getFormat(), "int64");
    LongProperty prop = (LongProperty) converted;
    assertEquals(prop.getMinimum(), new BigDecimal("1"));
    assertEquals(prop.getMaximum(), new BigDecimal("4"));
}
Also used : LongProperty(io.swagger.models.properties.LongProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 13 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class ModelPropertyConverterTest method convertFloatModelProperty.

@Test
public void convertFloatModelProperty() throws Exception {
    ModelProperty property = new ModelProperty();
    property.setType("number");
    property.setFormat(Format.FLOAT);
    property.setDescription("a simple float property");
    property.setMinimum("1.23");
    property.setMaximum("4.56");
    Property converted = converter.convertProperty(property);
    assertEquals(converted.getClass(), FloatProperty.class);
    assertEquals(converted.getType(), "number");
    assertEquals(converted.getFormat(), "float");
    FloatProperty prop = (FloatProperty) converted;
    assertEquals(prop.getMinimum(), new BigDecimal("1.23"));
    assertEquals(prop.getMaximum(), new BigDecimal("4.56"));
}
Also used : ModelProperty(io.swagger.models.apideclaration.ModelProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 14 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class ModelPropertyConverterTest method convertDoubleModelProperty.

@Test
public void convertDoubleModelProperty() throws Exception {
    ModelProperty property = new ModelProperty();
    property.setType("number");
    property.setFormat(Format.DOUBLE);
    property.setDescription("a simple double property");
    property.setMinimum("1.23");
    property.setMaximum("4.56");
    Property converted = converter.convertProperty(property);
    assertEquals(converted.getClass(), DoubleProperty.class);
    assertEquals(converted.getType(), "number");
    assertEquals(converted.getFormat(), "double");
    DoubleProperty prop = (DoubleProperty) converted;
    assertEquals(prop.getMinimum(), new BigDecimal("1.23"));
    assertEquals(prop.getMaximum(), new BigDecimal("4.56"));
}
Also used : ModelProperty(io.swagger.models.apideclaration.ModelProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

ModelProperty (io.swagger.models.apideclaration.ModelProperty)14 Property (io.swagger.models.properties.Property)12 Test (org.testng.annotations.Test)12 ArrayProperty (io.swagger.models.properties.ArrayProperty)11 RefProperty (io.swagger.models.properties.RefProperty)11 StringProperty (io.swagger.models.properties.StringProperty)11 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)10 DoubleProperty (io.swagger.models.properties.DoubleProperty)10 FloatProperty (io.swagger.models.properties.FloatProperty)10 IntegerProperty (io.swagger.models.properties.IntegerProperty)10 LongProperty (io.swagger.models.properties.LongProperty)10 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 Model (io.swagger.models.Model)2 Items (io.swagger.models.apideclaration.Items)2 LinkedHashMap (java.util.LinkedHashMap)2 UntypedProperty (io.swagger.models.properties.UntypedProperty)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1