use of io.swagger.v3.oas.annotations.media.ArraySchema 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.annotations.media.ArraySchema 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.annotations.media.ArraySchema in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeArrayStringProperty.
@Test(description = "it should serialize a string array property")
public void serializeArrayStringProperty() throws IOException {
final Schema p = new ArraySchema().items(new StringSchema());
final String json = "{\"type\":\"array\",\"items\":{\"type\":\"string\"}}";
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-core by swagger-api.
the class ContainerTest method testArray.
@Test
public void testArray() throws Exception {
final ModelResolver modelResolver = new ModelResolver(mapper());
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
final Schema model = context.resolve(new AnnotatedType(ArrayBean.class));
final Map<String, Schema> props = model.getProperties();
assertEquals(1, props.size());
final Schema prop = props.get("a");
assertNotNull(prop);
assertEquals(prop.getType(), "array");
final Schema items = ((ArraySchema) prop).getItems();
assertNotNull(items);
assertEquals(items.getType(), "integer");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-core by swagger-api.
the class XMLInfoTest method testSimple.
@Test
public void testSimple() throws Exception {
final ModelConverter mr = modelResolver();
ModelConverterContextImpl ctx = new ModelConverterContextImpl(mr);
final Schema model = mr.resolve(new AnnotatedType(XmlDecoratedBean.class), ctx, null);
final XML xml = model.getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "xmlDecoratedBean");
// Cast it to an array property
final ArraySchema property = (ArraySchema) model.getProperties().get("elements");
assertNotNull(property);
final XML propertyXml = property.getXml();
assertNotNull(propertyXml);
assertNull(propertyXml.getName());
assertTrue(propertyXml.getWrapped());
// Get the xml for items for the array property
final XML itemsXml = property.getItems().getXml();
assertNotNull(itemsXml);
// Check the name of item name
assertEquals(itemsXml.getName(), "element");
assertNotNull(model.getProperties().get("elementC"));
}
Aggregations