Search in sources :

Example 16 with ArraySchema

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

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

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

the class JsonPropertiesDeserializationTest method shouldDeserializeArrayPropertyMinItems.

@Test
public void shouldDeserializeArrayPropertyMinItems() throws Exception {
    String path = "json-schema-validation/array.json";
    ArraySchema property = (ArraySchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class);
    assertNotNull(property.getMinItems());
    assertEquals(property.getMinItems().intValue(), 1);
}
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 19 with ArraySchema

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

the class ParameterDeSerializationTest method deserializeEnumPathParameter.

@Test(description = "it should deserialize a path parameter with enum")
public void deserializeEnumPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"schema\":{" + "     \"type\":\"array\"," + "     \"items\":{" + "        \"type\":\"string\"," + "        \"enum\":[\"a\",\"b\",\"c\"]" + "     }" + "}}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
    ArraySchema as = (ArraySchema) p.getSchema();
    assertEquals(((StringSchema) as.getItems()).getEnum(), Arrays.asList("a", "b", "c"));
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Test(org.testng.annotations.Test)

Example 20 with ArraySchema

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

the class ArrayPropertyDeserializerTest method testArrayDeserialization.

@Test(description = "it should includes the example in the arrayproperty")
public void testArrayDeserialization() throws Exception {
    Operation operation = Yaml.mapper().readValue(yaml, Operation.class);
    ApiResponse response = operation.getResponses().get("200");
    assertNotNull(response);
    MediaType media = response.getContent().get("*/*");
    Schema responseSchema = media.getSchema();
    assertTrue(media.getExamples().size() == 2);
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof ArraySchema);
    ArraySchema mp = (ArraySchema) responseSchema;
    assertEquals(mp.getMinItems(), new Integer(3));
    assertEquals(mp.getMaxItems(), new Integer(100));
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) MediaType(io.swagger.v3.oas.models.media.MediaType) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) 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