use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.
the class PropertyDeserializerTest method deserializePropertyWithMinimumMaximumValues.
@Test
public void deserializePropertyWithMinimumMaximumValues() throws Exception {
String json = "{\n" + " \"type\": \"integer\",\n" + " \"format\": \"int32\",\n" + " \"minimum\": 32,\n" + " \"maximum\": 100\n" + "}";
Schema param = Json.mapper().readValue(json, Schema.class);
IntegerSchema ip = (IntegerSchema) param;
assertEquals(ip.getMinimum(), new BigDecimal("32"));
assertEquals(ip.getMaximum(), new BigDecimal("100"));
}
use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.
the class ModelPropertyTest method extractPrimitiveArray.
@Test
public void extractPrimitiveArray() {
final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithPrimitiveArray.class);
assertEquals(models.size(), 1);
final Schema model = models.get("ModelWithPrimitiveArray");
final ArraySchema longArray = (ArraySchema) model.getProperties().get("longArray");
final Schema longArrayItems = longArray.getItems();
assertTrue(longArrayItems instanceof IntegerSchema);
final ArraySchema intArray = (ArraySchema) model.getProperties().get("intArray");
assertTrue(intArray.getItems() instanceof IntegerSchema);
}
use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.
the class ModelExampleTest method createModelWithExample.
@Test(description = "it should create a model with example")
public void createModelWithExample() {
ObjectSchema model = new ObjectSchema();
model.addProperties("name", new StringSchema().example("Tony"));
model.addProperties("id", new IntegerSchema().example(123));
model.example("{\"name\":\"Fred\",\"id\":123456\"}");
assertEquals(model.getExample(), "{\"name\":\"Fred\",\"id\":123456\"}");
}
use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.
the class BeanValidatorTest method readBeanValidatorTest.
@Test(description = "read bean validations")
public void readBeanValidatorTest() {
final Map<String, Schema> schemas = ModelConverters.getInstance().readAll(BeanValidationsModel.class);
final Schema model = schemas.get("BeanValidationsModel");
final Map<String, Schema> properties = model.getProperties();
Assert.assertTrue(model.getRequired().contains("id"));
final IntegerSchema age = (IntegerSchema) properties.get("age");
Assert.assertEquals(age.getMinimum(), new BigDecimal(13.0));
Assert.assertEquals(age.getMaximum(), new BigDecimal(99.0));
final StringSchema password = (StringSchema) properties.get("password");
Assert.assertEquals((int) password.getMinLength(), 6);
Assert.assertEquals((int) password.getMaxLength(), 20);
final StringSchema email = (StringSchema) properties.get("email");
Assert.assertEquals((String) email.getPattern(), "(.+?)@(.+?)");
final NumberSchema minBalance = (NumberSchema) properties.get("minBalance");
Assert.assertTrue(minBalance.getExclusiveMinimum());
final NumberSchema maxBalance = (NumberSchema) properties.get("maxBalance");
Assert.assertTrue(maxBalance.getExclusiveMaximum());
final ArraySchema items = (ArraySchema) properties.get("items");
Assert.assertEquals((int) items.getMinItems(), 2);
Assert.assertEquals((int) items.getMaxItems(), 10);
}
use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeIntegerMapProperty.
@Test(description = "it should serialize a integer MapProperty")
public void serializeIntegerMapProperty() throws IOException {
final Schema p = new MapSchema().additionalProperties(new IntegerSchema());
final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
assertEquals(m.writeValueAsString(p), json);
}
Aggregations