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());
}
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;
}
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);
}
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"));
}
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));
}
Aggregations