Search in sources :

Example 36 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-core by swagger-api.

the class ByteConverterTest method testReadOnlyByteArray.

@Test
public void testReadOnlyByteArray() {
    Schema model = new Schema().addProperties("byteArray", new ArraySchema().items(new BinarySchema()).readOnly(true));
    assertEquals(Json.pretty(model), "{" + NEWLINE + "  \"properties\" : {" + NEWLINE + "    \"byteArray\" : {" + NEWLINE + "      \"type\" : \"array\"," + NEWLINE + "      \"readOnly\" : true," + 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 37 with ArraySchema

use of io.swagger.v3.oas.annotations.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 38 with ArraySchema

use of io.swagger.v3.oas.annotations.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 39 with ArraySchema

use of io.swagger.v3.oas.annotations.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 40 with ArraySchema

use of io.swagger.v3.oas.annotations.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)

Aggregations

ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)107 Schema (io.swagger.v3.oas.models.media.Schema)85 Test (org.testng.annotations.Test)76 StringSchema (io.swagger.v3.oas.models.media.StringSchema)63 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)53 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)53 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)51 OpenAPI (io.swagger.v3.oas.models.OpenAPI)49 MapSchema (io.swagger.v3.oas.models.media.MapSchema)28 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)22 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)21 PathItem (io.swagger.v3.oas.models.PathItem)16 Parameter (io.swagger.v3.oas.models.parameters.Parameter)16 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)16 MediaType (io.swagger.v3.oas.models.media.MediaType)15 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)15 Operation (io.swagger.v3.oas.models.Operation)14 Content (io.swagger.v3.oas.models.media.Content)12 DateSchema (io.swagger.v3.oas.models.media.DateSchema)11 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)11