use of io.swagger.models.properties.Property 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);
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class RequiredFieldModelTest method testApiModelPropertyFirstPosition.
@Test(description = "it should apply read only flag when ApiProperty annotation first")
public void testApiModelPropertyFirstPosition() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(ApiFirstRequiredFieldModel.class);
final Model model = models.get("aaa");
final Property prop = model.getProperties().get("a");
assertTrue(prop.getRequired());
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class RequiredFieldModelTest method testApiModelPropertySecondPosition.
@Test(description = "it should apply read only flag when XmlElement annotation first")
public void testApiModelPropertySecondPosition() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(XmlFirstRequiredFieldModel.class);
final Model model = models.get("aaa");
final Property prop = model.getProperties().get("a");
assertTrue(prop.getRequired());
}
use of io.swagger.models.properties.Property 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());
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class ModelSerializerTest method readOnlyJsonGeneration.
/*
@Test(description = "it should deserialize a model with custom format")
public void deserializeModelWithCustomFormat() throws IOException {
final String json = "{\n" +
" \"properties\":{\n" +
" \"id\":{\n" +
" \"type\":\"string\",\n" +
" \"format\":\"custom\"\n" +
" }\n" +
" }\n" +
"}";
final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
Json.prettyPrint(model);
}*/
@Test(description = "it should generate a JSON with read-only from pojo, #1161")
public void readOnlyJsonGeneration() throws IOException {
Map<String, Model> models = ModelConverters.getInstance().read(io.swagger.models.ReadOnlyModel.class);
Model model = models.get("ReadOnlyModel");
Property id = model.getProperties().get("id");
assertTrue(id.getReadOnly());
Property readWriteId = model.getProperties().get("readWriteId");
assertNull(readWriteId.getReadOnly());
}
Aggregations