Java Code Examples for org.eclipse.microprofile.openapi.models.media.Schema#items()
The following examples show how to use
org.eclipse.microprofile.openapi.models.media.Schema#items() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaFactory.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Introspect into the given Class to generate a Schema model. The boolean indicates * whether this class type should be turned into a reference. * * @param index the index of classes being scanned * @param type the implementation type of the item to scan * @param schemaReferenceSupported */ static Schema readClassSchema(IndexView index, Type type, boolean schemaReferenceSupported) { if (type == null) { return null; } Schema schema; if (type.kind() == Type.Kind.ARRAY) { schema = new SchemaImpl().type(SchemaType.ARRAY); ArrayType array = type.asArrayType(); int dimensions = array.dimensions(); Type componentType = array.component(); if (dimensions > 1) { // Recurse using a new array type with dimensions decremented schema.items(readClassSchema(index, ArrayType.create(componentType, dimensions - 1), schemaReferenceSupported)); } else { // Recurse using the type of the array elements schema.items(readClassSchema(index, componentType, schemaReferenceSupported)); } } else if (type.kind() == Type.Kind.PRIMITIVE) { schema = OpenApiDataObjectScanner.process(type.asPrimitiveType()); } else { schema = introspectClassToSchema(index, type.asClassType(), schemaReferenceSupported); } return schema; }
Example 2
Source File: SchemaFactory.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Converts a Jandex type to a {@link Schema} model. * * @param index the index of classes being scanned * @param type the implementation type of the item to scan * @param extensions list of AnnotationScannerExtensions * @return Schema model */ public static Schema typeToSchema(IndexView index, Type type, List<AnnotationScannerExtension> extensions) { Schema schema = null; AnnotationScanner annotationScanner = CurrentScannerInfo.getCurrentAnnotationScanner(); if (TypeUtil.isOptional(type)) { // Recurse using the optional's type return typeToSchema(index, TypeUtil.getOptionalType(type), extensions); } else if (annotationScanner.isWrapperType(type)) { // Recurse using the wrapped type return typeToSchema(index, annotationScanner.unwrapType(type), extensions); } else if (type.kind() == Type.Kind.ARRAY) { schema = new SchemaImpl().type(SchemaType.ARRAY); ArrayType array = type.asArrayType(); int dimensions = array.dimensions(); Type componentType = array.component(); if (dimensions > 1) { // Recurse using a new array type with dimensions decremented schema.items(typeToSchema(index, ArrayType.create(componentType, dimensions - 1), extensions)); } else { // Recurse using the type of the array elements schema.items(typeToSchema(index, componentType, extensions)); } } else if (type.kind() == Type.Kind.CLASS) { schema = introspectClassToSchema(index, type.asClassType(), true); } else if (type.kind() == Type.Kind.PRIMITIVE) { schema = OpenApiDataObjectScanner.process(type.asPrimitiveType()); } else { schema = otherTypeToSchema(index, type, extensions); } return schema; }
Example 3
Source File: SchemaFactory.java From smallrye-open-api with Apache License 2.0 | 5 votes |
private static Schema otherTypeToSchema(IndexView index, Type type, List<AnnotationScannerExtension> extensions) { if (TypeUtil.isA(index, type, MutinyConstants.MULTI_TYPE)) { // Treat as an Array Schema schema = new SchemaImpl().type(SchemaType.ARRAY); Type componentType = type.asParameterizedType().arguments().get(0); // Recurse using the type of the array elements schema.items(typeToSchema(index, componentType, extensions)); return schema; } else { Type asyncType = resolveAsyncType(index, type, extensions); return schemaRegistration(index, asyncType, OpenApiDataObjectScanner.process(index, asyncType)); } }
Example 4
Source File: TypeProcessor.java From smallrye-open-api with Apache License 2.0 | 4 votes |
public Type processType() { // If it's a terminal type. if (isTerminalType(type)) { return type; } if (type.kind() == Type.Kind.WILDCARD_TYPE) { type = TypeUtil.resolveWildcard(type.asWildcardType()); } if (type.kind() == Type.Kind.ARRAY) { DataObjectLogging.log.processingArray(type); ArrayType arrayType = type.asArrayType(); // Array-type schema Schema arrSchema = new SchemaImpl(); schema.type(Schema.SchemaType.ARRAY); // Only use component (excludes the special name formatting for arrays). TypeUtil.applyTypeAttributes(arrayType.component(), arrSchema); // If it's not a terminal type, then push for later inspection. if (!isTerminalType(arrayType.component()) && index.containsClass(type)) { pushToStack(type, arrSchema); } arrSchema = SchemaRegistry.checkRegistration(arrayType.component(), typeResolver, arrSchema); while (arrayType.dimensions() > 1) { Schema parentArrSchema = new SchemaImpl(); parentArrSchema.setType(Schema.SchemaType.ARRAY); parentArrSchema.items(arrSchema); arrSchema = parentArrSchema; arrayType = ArrayType.create(arrayType.component(), arrayType.dimensions() - 1); } schema.items(arrSchema); return arrayType; } if (TypeUtil.isOptional(type)) { Type optType = TypeUtil.getOptionalType(type); if (!isTerminalType(optType) && index.containsClass(optType)) { pushToStack(optType); } return optType; } if (isA(type, ENUM_TYPE) && index.containsClass(type)) { MergeUtil.mergeObjects(schema, SchemaFactory.enumToSchema(index, type)); return STRING_TYPE; } if (type.kind() == Type.Kind.PARAMETERIZED_TYPE) { // Parameterized type (e.g. Foo<A, B>) return readParameterizedType(type.asParameterizedType()); } if (type.kind() == Type.Kind.TYPE_VARIABLE || type.kind() == Type.Kind.UNRESOLVED_TYPE_VARIABLE) { // Resolve type variable to real variable. return resolveTypeVariable(schema, type); } // Raw Collection if (isA(type, COLLECTION_TYPE)) { return ARRAY_TYPE_OBJECT; } // Raw Iterable if (isA(type, ITERABLE_TYPE)) { return ARRAY_TYPE_OBJECT; } // Raw Map if (isA(type, MAP_TYPE)) { return OBJECT_TYPE; } // Simple case: bare class or primitive type. if (index.containsClass(type)) { pushToStack(type); } else { // If the type is not in Jandex then we don't have easy access to it. // Future work could consider separate code to traverse classes reachable from this classloader. DataObjectLogging.log.typeNotInJandexIndex(type); } return type; }