Search in sources :

Example 91 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project flow by vaadin.

the class SchemaResolverTest method should_ReturnNullableArray_When_GivenTypeIsAListString.

@Test
public void should_ReturnNullableArray_When_GivenTypeIsAListString() {
    ResolvedType resolvedType = mockReferencedTypeOf(Collection.class);
    ResolvedReferenceType resolvedReferenceType = resolvedType.asReferenceType();
    List<Pair<ResolvedTypeParameterDeclaration, ResolvedType>> pairs = Collections.singletonList(new Pair<>(null, mockReferencedTypeOf(String.class)));
    when(resolvedReferenceType.getTypeParametersMap()).thenReturn(pairs);
    Map<String, GeneratorType> usedTypes = new HashMap<>();
    SchemaResolver schemaResolver = new SchemaResolver(new GeneratorType(resolvedType), usedTypes);
    Schema schema = schemaResolver.resolve();
    Assert.assertTrue(schema instanceof ArraySchema);
    Assert.assertTrue(schema.getNullable());
    Assert.assertTrue(((ArraySchema) schema).getItems() instanceof StringSchema);
    Assert.assertTrue(usedTypes.isEmpty());
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) HashMap(java.util.HashMap) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Pair(com.github.javaparser.utils.Pair) Test(org.junit.Test)

Example 92 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project flow by vaadin.

the class SchemaResolver method createCollectionSchema.

private Schema createCollectionSchema() {
    ArraySchema array = new ArraySchema();
    List<GeneratorType> typeArguments = type.getTypeArguments();
    if (!typeArguments.isEmpty()) {
        array.items(new SchemaResolver(typeArguments.get(0), usedTypes).resolve());
    }
    return array;
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema)

Example 93 with ArraySchema

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

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

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