use of io.swagger.v3.oas.models.media.ArraySchema in project swagger-core by swagger-api.
the class ByteConverterTest method testByteArray.
@Test
public void testByteArray() {
Schema model = new Schema().addProperties("byteArray", new ArraySchema().items(new BinarySchema()));
assertEquals(Json.pretty(model), "{" + NEWLINE + " \"properties\" : {" + NEWLINE + " \"byteArray\" : {" + NEWLINE + " \"type\" : \"array\"," + NEWLINE + " \"items\" : {" + NEWLINE + " \"type\" : \"string\"," + NEWLINE + " \"format\" : \"binary\"" + NEWLINE + " }" + NEWLINE + " }" + NEWLINE + " }" + NEWLINE + "}");
}
use of io.swagger.v3.oas.models.media.ArraySchema in project swagger-core by swagger-api.
the class JsonPropertiesDeserializationTest method testDeserializeConstrainedArrayProperties.
@Test(description = "should deserialize an array property with constraints")
public void testDeserializeConstrainedArrayProperties() throws Exception {
OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertiesWithConstraints.json", OpenAPI.class);
Map<String, Schema> properties = oas.getComponents().getSchemas().get("Health").getProperties();
ArraySchema withMin = (ArraySchema) properties.get("array_with_min");
assertEquals(withMin.getMinItems(), Integer.valueOf(5));
assertNull(withMin.getMaxItems());
assertNull(withMin.getUniqueItems());
ArraySchema withMax = (ArraySchema) properties.get("array_with_max");
assertNull(withMax.getMinItems());
assertEquals(withMax.getMaxItems(), Integer.valueOf(10));
assertNull(withMax.getUniqueItems());
ArraySchema withUnique = (ArraySchema) properties.get("array_with_unique");
assertNull(withUnique.getMinItems());
assertNull(withUnique.getMaxItems());
assertEquals(withUnique.getUniqueItems(), Boolean.TRUE);
ArraySchema withAll = (ArraySchema) properties.get("array_with_all");
assertEquals(withAll.getMinItems(), Integer.valueOf(1));
assertEquals(withAll.getMaxItems(), Integer.valueOf(10));
assertEquals(withAll.getUniqueItems(), Boolean.TRUE);
}
use of io.swagger.v3.oas.models.media.ArraySchema in project swagger-core by swagger-api.
the class JsonPropertiesDeserializationTest method shouldDeserializeArrayPropertyMaxItems.
@Test
public void shouldDeserializeArrayPropertyMaxItems() throws Exception {
String path = "json-schema-validation/array.json";
ArraySchema property = (ArraySchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class);
assertNotNull(property.getMaxItems());
assertEquals(property.getMaxItems().intValue(), 10);
}
use of io.swagger.v3.oas.models.media.ArraySchema in project swagger-core by swagger-api.
the class JsonPropertiesDeserializationTest method shouldDeserializeArrayPropertyUniqueItems.
@Test
public void shouldDeserializeArrayPropertyUniqueItems() throws Exception {
String path = "json-schema-validation/array.json";
ArraySchema property = (ArraySchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class);
assertNotNull(property.getUniqueItems());
assertTrue(property.getUniqueItems());
}
use of io.swagger.v3.oas.models.media.ArraySchema in project swagger-core by swagger-api.
the class ModelPropertyTest method extractProperties.
@Test
public void extractProperties() {
final Map<String, Schema> models = ModelConverters.getInstance().readAll(Family.class);
assertEquals(models.size(), 3);
final Schema person = models.get("Person");
final Schema employer = (Schema) person.getProperties().get("employer");
assertTrue(employer instanceof ArraySchema);
final ArraySchema employerProperty = (ArraySchema) employer;
final Schema items = employerProperty.getItems();
assertEquals(items.get$ref(), "#/components/schemas/Employer");
final Schema awards = (Schema) person.getProperties().get("awards");
assertTrue(awards instanceof ArraySchema);
assertTrue(((ArraySchema) awards).getItems() instanceof StringSchema);
}
Aggregations