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);
}
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);
}
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));
}
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());
}
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);
}
Aggregations