Search in sources :

Example 46 with ArraySchema

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

the class ModelSerializerTest method deserializeArrayModel.

@Test(description = "it should deserialize an array model")
public void deserializeArrayModel() throws IOException {
    final String json = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
    final Schema p = m.readValue(json, Schema.class);
    assertTrue(p instanceof ArraySchema);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 47 with ArraySchema

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

the class ParameterSerializationTest method serializeStringArrayHeaderParameter.

@Test(description = "it should serialize a string array HeaderParameter")
public void serializeStringArrayHeaderParameter() {
    final Parameter p = new HeaderParameter().schema(new ArraySchema().items(new StringSchema()));
    final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 48 with ArraySchema

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

the class ReaderTest method test2497.

@Test(description = "test resource with array in response content")
public void test2497() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(ResponseContentWithArrayResource.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 1);
    PathItem pathItem = paths.get("/user");
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    ArraySchema schema = (ArraySchema) operation.getResponses().get("200").getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getItems().get$ref(), "#/components/schemas/User");
    assertEquals(openAPI.getComponents().getSchemas().get("User").getRequired().get(0), "issue3438");
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Paths(io.swagger.v3.oas.models.Paths) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 49 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project hippo by NHS-digital-website.

the class BorderHelperTest method lastChildModels.

@DataProvider
public static Object[][] lastChildModels() {
    final String expectedBorder = getBorder(SchemaBorder.HORIZONTAL, 1, 0) + getBorder(SchemaBorder.SHORT_VERTICAL, 1, 0);
    final Schema currentModel = new Schema();
    return new Object[][] { // "properties" child
    { currentModel, new Schema().properties(ImmutableMap.of("child", currentModel)), expectedBorder }, // "allOf" child
    { currentModel, new ComposedSchema().allOf(new ArrayList<>(asList(currentModel))), expectedBorder }, // "anyOf" child
    { currentModel, new ComposedSchema().anyOf(new ArrayList<>(asList(currentModel))), expectedBorder }, // "oneOf" child
    { currentModel, new ComposedSchema().oneOf(new ArrayList<>(asList(currentModel))), expectedBorder }, // "array" -> "items" child
    { currentModel, new ArraySchema().items(currentModel), expectedBorder } };
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) ArrayList(java.util.ArrayList) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider)

Example 50 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project hippo by NHS-digital-website.

the class SchemaHelperTest method schemaWithXOfPropertyUnderItemsObject.

private Schema<?> schemaWithXOfPropertyUnderItemsObject(final String propertyName) {
    final ComposedSchema items = new ComposedSchema();
    items.title("items object");
    setField(items, propertyName, new ArrayList<>(asList(new ObjectSchema().title(propertyName + " - A"), new ObjectSchema().title(propertyName + " - B"))));
    return new ObjectSchema().title("root object").properties(ImmutableMap.of("array-schema", new ArraySchema().items(items)));
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema)

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