Search in sources :

Example 6 with ArraySchema

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 + "}");
}
Also used : ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) Schema(io.swagger.v3.oas.models.media.Schema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Test(org.testng.annotations.Test)

Example 7 with ArraySchema

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);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 8 with ArraySchema

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);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 9 with ArraySchema

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());
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 10 with ArraySchema

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);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Aggregations

ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)32 Test (org.testng.annotations.Test)28 Schema (io.swagger.v3.oas.models.media.Schema)23 StringSchema (io.swagger.v3.oas.models.media.StringSchema)18 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)12 MapSchema (io.swagger.v3.oas.models.media.MapSchema)8 Parameter (io.swagger.v3.oas.models.parameters.Parameter)8 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)7 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)4 OpenAPI (io.swagger.v3.oas.models.OpenAPI)4 HeaderParameter (io.swagger.v3.oas.models.parameters.HeaderParameter)4 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)4 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)4 LinkedHashMap (java.util.LinkedHashMap)4 Operation (io.swagger.v3.oas.models.Operation)3 BooleanSchema (io.swagger.v3.oas.models.media.BooleanSchema)3 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)3 Annotation (java.lang.annotation.Annotation)3 BigDecimal (java.math.BigDecimal)3 Map (java.util.Map)3