Search in sources :

Example 31 with ArraySchema

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

the class ParameterSerializationTest method serializeArrayQueryParameter.

@Test(description = "it should serialize a QueryParameter with array")
public void serializeArrayQueryParameter() {
    final Parameter p = new QueryParameter().schema(new ArraySchema().items(new StringSchema()));
    final String json = "{" + "   \"in\":\"query\"," + "   \"schema\":{" + "     \"type\":\"array\"," + "     \"items\":{" + "       \"type\":\"string\"" + "   }}" + "}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) 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) Test(org.testng.annotations.Test)

Example 32 with ArraySchema

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

the class ParameterSerializationTest method serializeStringArrayPathParameter.

@Test(description = "it should serialize a PathParameter with string array")
public void serializeStringArrayPathParameter() {
    Parameter p = new PathParameter().schema(new ArraySchema().items(new StringSchema()));
    final String json = "{\"in\":\"path\",\"required\":true,\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}";
    SerializationMatchers.assertEqualsToJson(p, json);
    final String yaml = "---\n" + "in: \"path\"\n" + "required: true\n" + "schema:\n" + "  type: \"array\"\n" + "  items:\n" + "    type: \"string\"";
    SerializationMatchers.assertEqualsToYaml(p, yaml);
}
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) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 33 with ArraySchema

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

the class ParameterSerializationTest method serializeIntegerArrayPathParameter.

@Test(description = "it should serialize a PathParameter with integer array")
public void serializeIntegerArrayPathParameter() {
    final Parameter p = new PathParameter().schema(new ArraySchema().items(new IntegerSchema()));
    final String json = "{\"in\":\"path\",\"required\":true,\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"integer\",\"format\":\"int32\"}}}\n";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) 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) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 34 with ArraySchema

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

the class ReaderTest method testResourceWithSubresources.

@Test(description = "test resource with subresources")
public void testResourceWithSubresources() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(ResourceWithSubResource.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 3);
    PathItem pathItem = paths.get("/employees/{id}");
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    ArraySchema arraySchema = (ArraySchema) operation.getResponses().get("200").getContent().values().iterator().next().getSchema();
    assertNotNull(arraySchema);
    assertEquals(arraySchema.getItems().get$ref(), "#/components/schemas/Pet");
    pathItem = paths.get("/employees/{id}/{id}");
    assertNotNull(pathItem);
    operation = pathItem.getGet();
    assertNotNull(operation);
    Schema schema = operation.getResponses().get("200").getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.get$ref(), "#/components/schemas/Pet");
    pathItem = paths.get("/employees/noPath");
    assertNotNull(pathItem);
    operation = pathItem.getGet();
    assertNotNull(operation);
    schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getType(), "string");
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) 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)

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