Search in sources :

Example 11 with IntegerProperty

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

the class ModelPropertyTest method extractPrimitiveArray.

@Test
public void extractPrimitiveArray() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(ModelWithPrimitiveArray.class);
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithPrimitiveArray");
    final ArrayProperty longArray = (ArrayProperty) model.getProperties().get("longArray");
    final Property longArrayItems = longArray.getItems();
    assertTrue(longArrayItems instanceof LongProperty);
    final ArrayProperty intArray = (ArrayProperty) model.getProperties().get("intArray");
    assertTrue(intArray.getItems() instanceof IntegerProperty);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) ModelWithBooleanProperty(io.swagger.models.ModelWithBooleanProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) 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 IntegerProperty

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

the class ModelSerializerTest method convertModel.

@Test(description = "it should convert a model")
public void convertModel() throws JsonProcessingException {
    final ModelImpl pet = new ModelImpl();
    final HashMap<String, Property> props = new HashMap<String, Property>();
    props.put("intValue", new IntegerProperty());
    props.put("longValue", new LongProperty());
    props.put("dateValue", new DateProperty());
    props.put("dateTimeValue", new DateTimeProperty());
    pet.setProperties(props);
    pet.setRequired(Arrays.asList("intValue", "name"));
    final String json = "{\n" + "   \"required\":[\n" + "      \"intValue\"\n" + "   ],\n" + "   \"properties\":{\n" + "      \"dateValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date\"\n" + "      },\n" + "      \"longValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int64\"\n" + "      },\n" + "      \"dateTimeValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date-time\"\n" + "      },\n" + "      \"intValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\"\n" + "      }\n" + "   }\n" + "}";
    SerializationMatchers.assertEqualsToJson(pet, json);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) HashMap(java.util.HashMap) DateProperty(io.swagger.models.properties.DateProperty) LongProperty(io.swagger.models.properties.LongProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) 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 13 with IntegerProperty

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

the class ModelSerializerTest method integerEnumGeneration.

@Test(description = "it should generate an integer field with enum")
public void integerEnumGeneration() throws IOException {
    final String json = "{\n" + "   \"properties\":{\n" + "      \"id\":{\n" + "         \"description\":\"fun!\",\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\",\n" + "         \"readOnly\":true,\n" + "         \"enum\": [ 0, 1]\n" + "      }\n" + "   }\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    IntegerProperty p = (IntegerProperty) model.getProperties().get("id");
    assertNotNull(p.getEnum());
    assertEquals(p.getEnum().get(0), new Integer(0));
    assertEquals(p.getEnum().get(1), new Integer(1));
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 14 with IntegerProperty

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

the class ModelWithRangesTest method modelWithRangesTest.

@Test(description = "test model with @ApiModelProperty.allowableValues")
public void modelWithRangesTest() {
    final Map<String, Property> properties = ModelConverters.getInstance().read(ModelWithRanges.class).get("ModelWithRanges").getProperties();
    final IntegerProperty inclusiveRange = (IntegerProperty) properties.get("inclusiveRange");
    assertEquals(inclusiveRange.getMinimum(), new BigDecimal(1));
    assertEquals(inclusiveRange.getMaximum(), new BigDecimal(5));
    assertNull(inclusiveRange.getExclusiveMaximum());
    assertNull(inclusiveRange.getExclusiveMinimum());
    final IntegerProperty exclusiveRange = (IntegerProperty) properties.get("exclusiveRange");
    assertEquals(exclusiveRange.getMinimum(), new BigDecimal(1));
    assertEquals(exclusiveRange.getMaximum(), new BigDecimal(5));
    assertEquals(exclusiveRange.getExclusiveMinimum(), Boolean.TRUE);
    assertEquals(exclusiveRange.getExclusiveMaximum(), Boolean.TRUE);
    final IntegerProperty positiveInfinityRange = (IntegerProperty) properties.get("positiveInfinityRange");
    assertEquals(positiveInfinityRange.getMinimum(), new BigDecimal(1.0));
    assertNull(positiveInfinityRange.getMaximum());
    assertNull(positiveInfinityRange.getExclusiveMaximum());
    assertNull(positiveInfinityRange.getExclusiveMinimum());
    final IntegerProperty negativeInfinityRange = (IntegerProperty) properties.get("negativeInfinityRange");
    assertNull(negativeInfinityRange.getMinimum());
    assertEquals(negativeInfinityRange.getMaximum(), new BigDecimal(5.0));
    assertNull(negativeInfinityRange.getExclusiveMaximum());
    assertNull(negativeInfinityRange.getExclusiveMinimum());
    final StringProperty stringValues = (StringProperty) properties.get("stringValues");
    assertEquals(stringValues.getEnum(), Arrays.asList("str1", "str2"));
    final DoubleProperty doubleValues = (DoubleProperty) properties.get("doubleValues");
    assertEquals(doubleValues.getMinimum(), new BigDecimal("1.0"));
    assertEquals(doubleValues.getMaximum(), new BigDecimal("8.0"));
    assertEquals(doubleValues.getExclusiveMaximum(), Boolean.TRUE);
    assertNull(doubleValues.getExclusiveMinimum());
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) StringProperty(io.swagger.models.properties.StringProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) StringProperty(io.swagger.models.properties.StringProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 15 with IntegerProperty

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

the class BeanValidatorTest method readBeanValidatorTest.

@Test(description = "read bean validations")
public void readBeanValidatorTest() {
    final Map<String, Model> schemas = ModelConverters.getInstance().readAll(BeanValidationsModel.class);
    final Model model = schemas.get("BeanValidationsModel");
    final Map<String, Property> properties = model.getProperties();
    final IntegerProperty age = (IntegerProperty) properties.get("age");
    Assert.assertEquals(age.getMinimum(), new BigDecimal(13.0));
    Assert.assertEquals(age.getMaximum(), new BigDecimal(99.0));
    final StringProperty password = (StringProperty) properties.get("password");
    Assert.assertEquals((int) password.getMinLength(), 6);
    Assert.assertEquals((int) password.getMaxLength(), 20);
    final StringProperty email = (StringProperty) properties.get("email");
    Assert.assertEquals((String) email.getPattern(), "(.+?)@(.+?)");
    final DoubleProperty minBalance = (DoubleProperty) properties.get("minBalance");
    Assert.assertTrue(minBalance.getExclusiveMinimum());
    final DoubleProperty maxBalance = (DoubleProperty) properties.get("maxBalance");
    Assert.assertTrue(maxBalance.getExclusiveMaximum());
    final ArrayProperty items = (ArrayProperty) properties.get("items");
    Assert.assertEquals((int) items.getMinItems(), 2);
    Assert.assertEquals((int) items.getMaxItems(), 10);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) BeanValidationsModel(io.swagger.models.BeanValidationsModel) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

IntegerProperty (io.swagger.models.properties.IntegerProperty)23 Test (org.testng.annotations.Test)20 Property (io.swagger.models.properties.Property)13 StringProperty (io.swagger.models.properties.StringProperty)11 ArrayProperty (io.swagger.models.properties.ArrayProperty)9 DoubleProperty (io.swagger.models.properties.DoubleProperty)9 LongProperty (io.swagger.models.properties.LongProperty)8 RefProperty (io.swagger.models.properties.RefProperty)7 BigDecimal (java.math.BigDecimal)7 FloatProperty (io.swagger.models.properties.FloatProperty)6 PathParameter (io.swagger.models.parameters.PathParameter)5 BooleanProperty (io.swagger.models.properties.BooleanProperty)5 MapProperty (io.swagger.models.properties.MapProperty)5 Model (io.swagger.models.Model)4 ModelImpl (io.swagger.models.ModelImpl)4 Response (io.swagger.models.Response)3 BodyParameter (io.swagger.models.parameters.BodyParameter)3 Parameter (io.swagger.models.parameters.Parameter)3 QueryParameter (io.swagger.models.parameters.QueryParameter)3 DateProperty (io.swagger.models.properties.DateProperty)3