Package io.smallrye.openapi.runtime.util
Class TypeUtil
- java.lang.Object
-
- io.smallrye.openapi.runtime.util.TypeUtil
-
public class TypeUtil extends Object
- Author:
- Marc Savy <marc@rhymewithgravy.com>
-
-
Field Summary
Fields Modifier and Type Field Description static org.jboss.jandex.IndexViewjdkIndex
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanallowRegistration(AnnotationScannerContext context, org.jboss.jandex.Type classType)Determines if a type is eligible for registration.static voidapplyTypeAttributes(org.jboss.jandex.Type classType, org.eclipse.microprofile.openapi.models.media.Schema schema)Sets the default schema attributes for the given type on the provided schema instance.static voidclearMatchingDefaultAttributes(org.eclipse.microprofile.openapi.models.media.Schema fieldSchema, org.eclipse.microprofile.openapi.models.media.Schema typeSchema)Removes the known default schema attributes from the fieldSchema if they are also present and have the same value in the typeSchema.static booleanequalTypes(org.jboss.jandex.Type type1, org.jboss.jandex.Type type2)static booleanequalWrappedTypes(org.jboss.jandex.Type primitiveCandidate, org.jboss.jandex.Type wrappedCandidate)static org.jboss.jandex.TypegetBound(org.jboss.jandex.WildcardType wct)static org.jboss.jandex.ClassInfogetDeclaringClass(org.jboss.jandex.AnnotationTarget type)static org.jboss.jandex.DotNamegetName(org.jboss.jandex.Type type)static org.jboss.jandex.TypegetOptionalType(org.jboss.jandex.Type type)Unwraps the type parameter (generic or primitive) from the given optional type.static org.jboss.jandex.AnnotationInstancegetSchemaAnnotation(org.jboss.jandex.AnnotationTarget annotationTarget)static Map<String,Object>getTypeAttributes(org.jboss.jandex.Type classType)Retrieves the read-only Map of schema attributes for the given type.static booleanisA(AnnotationScannerContext context, org.jboss.jandex.Type testSubject, org.jboss.jandex.Type testObject)Test whether testSubject is an "instanceof" type testObject.static booleanisIncludedAllOf(AnnotationScannerContext context, org.jboss.jandex.ClassInfo annotatedClass, org.jboss.jandex.Type type)static booleanisIncludedAllOf(org.jboss.jandex.ClassInfo annotatedClass, org.jboss.jandex.Type type)static booleanisOptional(org.jboss.jandex.Type type)Determine if a given type is one of the following types:java.util.Optionaljava.util.OptionalDoublejava.util.OptionalIntjava.util.OptionalLongstatic booleanisPrimitiveWrapper(org.jboss.jandex.PrimitiveType primitive, org.jboss.jandex.Type wrapped)static booleanisTerminalType(org.jboss.jandex.Type type)static booleanisTypeOverridden(org.jboss.jandex.Type classType, org.jboss.jandex.AnnotationInstance schemaAnnotation)Check if the default schema type that applies to the provided classType differs from any value specified by the user via schemaAnnotation.static booleanisVoid(org.jboss.jandex.Type type)static booleanisWrappedType(org.jboss.jandex.Type type)static booleanknownJavaType(org.jboss.jandex.DotName name)static voidmapDeprecated(org.jboss.jandex.AnnotationTarget target, Supplier<Boolean> getDeprecated, Consumer<Boolean> setDeprecated)static org.jboss.jandex.TyperesolveWildcard(org.jboss.jandex.Type type)static org.jboss.jandex.TyperesolveWildcard(org.jboss.jandex.WildcardType wildcardType)static org.jboss.jandex.TypeunwrapType(org.jboss.jandex.Type type)
-
-
-
Method Detail
-
allowRegistration
public static boolean allowRegistration(AnnotationScannerContext context, org.jboss.jandex.Type classType)
Determines if a type is eligible for registration. If the schema type is array or object, the type must be in the provided index. Otherwise, only those types with defined properties beyond 'type' and 'format' are eligible.- Parameters:
context- scanning contextclassType- the type to check- Returns:
- true if the type may be registered in the SchemaRegistry, false otherwise.
-
knownJavaType
public static boolean knownJavaType(org.jboss.jandex.DotName name)
-
getTypeAttributes
public static Map<String,Object> getTypeAttributes(org.jboss.jandex.Type classType)
Retrieves the read-only Map of schema attributes for the given type.- Parameters:
classType- the type- Returns:
- Map of default schema attributes
-
isTypeOverridden
public static boolean isTypeOverridden(org.jboss.jandex.Type classType, org.jboss.jandex.AnnotationInstance schemaAnnotation)Check if the default schema type that applies to the provided classType differs from any value specified by the user via schemaAnnotation.- Parameters:
classType- class type to find a default schema typeschemaAnnotation- schema annotation (possibly null) which may have an overridden type value- Returns:
- true if the annotation has a type specified that is different from the default type for classType, otherwise false
-
applyTypeAttributes
public static void applyTypeAttributes(org.jboss.jandex.Type classType, org.eclipse.microprofile.openapi.models.media.Schema schema)Sets the default schema attributes for the given type on the provided schema instance.- Parameters:
classType- the typeschema- a writable schema to be updated with the type's default schema attributes
-
clearMatchingDefaultAttributes
public static void clearMatchingDefaultAttributes(org.eclipse.microprofile.openapi.models.media.Schema fieldSchema, org.eclipse.microprofile.openapi.models.media.Schema typeSchema)Removes the known default schema attributes from the fieldSchema if they are also present and have the same value in the typeSchema. This method reduces any duplicate attributes between the two schemas when they are in an 'allOf' composition.- Parameters:
fieldSchema- the schema for a field of the type described by typeSchematypeSchema- the schema for a class type
-
isA
public static boolean isA(AnnotationScannerContext context, org.jboss.jandex.Type testSubject, org.jboss.jandex.Type testObject)
Test whether testSubject is an "instanceof" type testObject.For example, test whether List is a Collection.
Attempts to work with both Jandex and using standard class.
- Parameters:
context- scanning contexttestSubject- type to testtestObject- type to test against- Returns:
- true if is of type
-
isTerminalType
public static boolean isTerminalType(org.jboss.jandex.Type type)
-
isWrappedType
public static boolean isWrappedType(org.jboss.jandex.Type type)
-
unwrapType
public static org.jboss.jandex.Type unwrapType(org.jboss.jandex.Type type)
-
isVoid
public static boolean isVoid(org.jboss.jandex.Type type)
-
isOptional
public static boolean isOptional(org.jboss.jandex.Type type)
Determine if a given type is one of the following types:java.util.Optionaljava.util.OptionalDoublejava.util.OptionalIntjava.util.OptionalLong
- Parameters:
type- the type to check- Returns:
- true if the type is one of the four optional types, otherwise false
-
getOptionalType
public static org.jboss.jandex.Type getOptionalType(org.jboss.jandex.Type type)
Unwraps the type parameter (generic or primitive) from the given optional type.- Parameters:
type- the type to unwrap- Returns:
- the generic type argument for
java.util.Optional, otherwise the optional primitive double, int, or long
-
getName
public static org.jboss.jandex.DotName getName(org.jboss.jandex.Type type)
-
getBound
public static org.jboss.jandex.Type getBound(org.jboss.jandex.WildcardType wct)
-
resolveWildcard
public static org.jboss.jandex.Type resolveWildcard(org.jboss.jandex.WildcardType wildcardType)
-
resolveWildcard
public static org.jboss.jandex.Type resolveWildcard(org.jboss.jandex.Type type)
-
equalTypes
public static boolean equalTypes(org.jboss.jandex.Type type1, org.jboss.jandex.Type type2)
-
equalWrappedTypes
public static boolean equalWrappedTypes(org.jboss.jandex.Type primitiveCandidate, org.jboss.jandex.Type wrappedCandidate)
-
isPrimitiveWrapper
public static boolean isPrimitiveWrapper(org.jboss.jandex.PrimitiveType primitive, org.jboss.jandex.Type wrapped)
-
getSchemaAnnotation
public static org.jboss.jandex.AnnotationInstance getSchemaAnnotation(org.jboss.jandex.AnnotationTarget annotationTarget)
-
isIncludedAllOf
public static boolean isIncludedAllOf(org.jboss.jandex.ClassInfo annotatedClass, org.jboss.jandex.Type type)
-
isIncludedAllOf
public static boolean isIncludedAllOf(AnnotationScannerContext context, org.jboss.jandex.ClassInfo annotatedClass, org.jboss.jandex.Type type)
-
getDeclaringClass
public static org.jboss.jandex.ClassInfo getDeclaringClass(org.jboss.jandex.AnnotationTarget type)
-
-