use of io.swagger.v3.oas.annotations.media.ArraySchema in project flow by vaadin.
the class SchemaResolver method createArraySchema.
private Schema createArraySchema() {
ArraySchema array = new ArraySchema();
array.items(new SchemaResolver(type.getItemType(), usedTypes).resolve());
return array;
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project flow by vaadin.
the class SchemaResolverTest method should_ReturnArraySchema_When_GivenTypeIsAnArray.
@Test
public void should_ReturnArraySchema_When_GivenTypeIsAnArray() {
ResolvedType arrayType = mock(ResolvedType.class);
ResolvedArrayType arrayResolvedType = mock(ResolvedArrayType.class);
ResolvedType stringType = mockReferencedTypeOf(String.class);
when(arrayType.isArray()).thenReturn(true);
when(arrayType.asArrayType()).thenReturn(arrayResolvedType);
when(arrayResolvedType.getComponentType()).thenReturn(stringType);
Map<String, GeneratorType> usedTypes = new HashMap<>();
SchemaResolver schemaResolver = new SchemaResolver(new GeneratorType(arrayType), 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 CodeGenerator method getTypeDeclaration.
@Override
public String getTypeDeclaration(Schema schema) {
String optionalSuffix = "";
if (GeneratorUtils.isTrue(schema.getNullable())) {
optionalSuffix = MainGenerator.OPTIONAL_SUFFIX;
}
if (schema instanceof ArraySchema) {
ArraySchema arraySchema = (ArraySchema) schema;
Schema inner = arraySchema.getItems();
return String.format("Array<%s>%s", this.getTypeDeclaration(inner), optionalSuffix);
} else if (GeneratorUtils.isNotBlank(schema.get$ref())) {
return OpenAPIUtil.getSimpleRef(schema.get$ref()) + optionalSuffix;
} else if (schema.getAdditionalProperties() != null) {
Schema inner = (Schema) schema.getAdditionalProperties();
return String.format("Record<string, %s>%s", getTypeDeclaration(inner), optionalSuffix);
} else if (schema instanceof ComposedSchema) {
return getTypeDeclarationFromComposedSchema((ComposedSchema) schema, optionalSuffix);
} else {
return super.getTypeDeclaration(schema) + optionalSuffix;
}
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project hippo by NHS-digital-website.
the class SchemaHelperTest method schemaWithItemsWithNoXOf.
private Schema<?> schemaWithItemsWithNoXOf() {
final ComposedSchema items = new ComposedSchema();
items.title("items object");
return new ObjectSchema().properties(ImmutableMap.of("array-schema", new ArraySchema().items(items)));
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue343Parameter.
@Test
public void testIssue343Parameter() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " description: bleh\n" + " version: 2.0.0\n" + " title: Test\n" + "paths:\n" + " /foo:\n" + " post:\n" + " parameters:\n" + " - in: query\n" + " name: skip\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " multipleOf: 3\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: object\n" + " additionalProperties:\n" + " type: string\n" + " required: true\n" + "components:\n" + " schemas:\n" + " Fun:\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int32\n" + " multipleOf: 5\n" + " mySet:\n" + " type: array\n" + " uniqueItems: true\n" + " items:\n" + " type: string";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
QueryParameter qp = (QueryParameter) openAPI.getPaths().get("/foo").getPost().getParameters().get(0);
assertEquals(new BigDecimal("3"), qp.getSchema().getMultipleOf());
RequestBody bp = openAPI.getPaths().get("/foo").getPost().getRequestBody();
Schema schema = bp.getContent().get("application/json").getSchema();
assertTrue(schema.getAdditionalProperties() != null);
IntegerSchema id = (IntegerSchema) openAPI.getComponents().getSchemas().get("Fun").getProperties().get("id");
assertEquals(id.getMultipleOf(), new BigDecimal("5"));
ArraySchema ap = (ArraySchema) openAPI.getComponents().getSchemas().get("Fun").getProperties().get("mySet");
assertTrue(ap.getUniqueItems());
}
Aggregations