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 <[email protected]>
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
allowRegistration(AnnotationScannerContext context, org.jboss.jandex.Type classType)
Determines if a type is eligible for registration.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.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.static boolean
equalTypes(org.jboss.jandex.Type type1, org.jboss.jandex.Type type2)
static boolean
equalWrappedTypes(org.jboss.jandex.Type primitiveCandidate, org.jboss.jandex.Type wrappedCandidate)
static org.jboss.jandex.AnnotationInstance
getAnnotation(org.jboss.jandex.AnnotationTarget annotationTarget, Collection<org.jboss.jandex.DotName> annotationNames)
static org.jboss.jandex.AnnotationInstance
getAnnotation(org.jboss.jandex.AnnotationTarget annotationTarget, org.jboss.jandex.DotName annotationName)
static org.jboss.jandex.AnnotationInstance
getAnnotation(org.jboss.jandex.ClassInfo field, org.jboss.jandex.DotName annotationName)
static org.jboss.jandex.AnnotationInstance
getAnnotation(org.jboss.jandex.FieldInfo field, org.jboss.jandex.DotName annotationName)
static org.jboss.jandex.AnnotationInstance
getAnnotation(org.jboss.jandex.Type type, org.jboss.jandex.DotName annotationName)
static Collection<org.jboss.jandex.AnnotationInstance>
getAnnotations(org.jboss.jandex.AnnotationTarget type)
static <T> T
getAnnotationValue(org.jboss.jandex.AnnotationTarget target, List<org.jboss.jandex.DotName> annotationNames)
static <T> T
getAnnotationValue(org.jboss.jandex.AnnotationTarget target, List<org.jboss.jandex.DotName> annotationNames, String propertyName)
static <T> T
getAnnotationValue(org.jboss.jandex.AnnotationTarget target, List<org.jboss.jandex.DotName> annotationNames, String propertyName, T defaultValue)
Convenience method to retrieve the named parameter from an annotation bound to the target.static <T> T
getAnnotationValue(org.jboss.jandex.AnnotationTarget target, org.jboss.jandex.DotName annotationName)
Convenience method to retrieve the "value" parameter from an annotation bound to the target.static <T> T
getAnnotationValue(org.jboss.jandex.AnnotationTarget target, org.jboss.jandex.DotName annotationName, String propertyName)
Convenience method to retrieve the named parameter from an annotation bound to the target.static <T> T
getAnnotationValue(org.jboss.jandex.AnnotationTarget target, org.jboss.jandex.DotName annotationName, String propertyName, T defaultValue)
Convenience method to retrieve the named parameter from an annotation bound to the target.static org.jboss.jandex.Type
getBound(org.jboss.jandex.WildcardType wct)
static org.jboss.jandex.ClassInfo
getDeclaringClass(org.jboss.jandex.AnnotationTarget type)
static org.jboss.jandex.DotName
getName(org.jboss.jandex.Type type)
static org.jboss.jandex.Type
getOptionalType(org.jboss.jandex.Type type)
Unwraps the type parameter (generic or primitive) from the given optional type.static org.jboss.jandex.AnnotationInstance
getSchemaAnnotation(org.jboss.jandex.AnnotationTarget annotationTarget)
static org.jboss.jandex.AnnotationInstance
getSchemaAnnotation(org.jboss.jandex.ClassInfo field)
static org.jboss.jandex.AnnotationInstance
getSchemaAnnotation(org.jboss.jandex.FieldInfo field)
static org.jboss.jandex.AnnotationInstance
getSchemaAnnotation(org.jboss.jandex.Type type)
static Map<String,Object>
getTypeAttributes(org.jboss.jandex.Type classType)
Retrieves the read-only Map of schema attributes for the given type.static boolean
hasAnnotation(org.jboss.jandex.AnnotationTarget target, List<org.jboss.jandex.DotName> annotationNames)
static boolean
hasAnnotation(org.jboss.jandex.AnnotationTarget target, org.jboss.jandex.DotName annotationName)
static boolean
isA(AnnotationScannerContext context, org.jboss.jandex.Type testSubject, org.jboss.jandex.Type testObject)
Test whether testSubject is an "instanceof" type testObject.static boolean
isIncludedAllOf(org.jboss.jandex.ClassInfo annotatedClass, org.jboss.jandex.Type type)
static boolean
isOptional(org.jboss.jandex.Type type)
Determine if a given type is one of the following types:java.util.Optional
java.util.OptionalDouble
java.util.OptionalInt
java.util.OptionalLong
static boolean
isPrimitiveWrapper(org.jboss.jandex.PrimitiveType primitive, org.jboss.jandex.Type wrapped)
static boolean
isTerminalType(org.jboss.jandex.Type type)
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.static boolean
isVoid(org.jboss.jandex.Type type)
static boolean
isWrappedType(org.jboss.jandex.Type type)
static boolean
knownJavaType(org.jboss.jandex.DotName name)
static org.jboss.jandex.Type
resolveWildcard(org.jboss.jandex.Type type)
static org.jboss.jandex.Type
resolveWildcard(org.jboss.jandex.WildcardType wildcardType)
static org.jboss.jandex.Type
unwrapType(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.Optional
java.util.OptionalDouble
java.util.OptionalInt
java.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)
-
getSchemaAnnotation
public static org.jboss.jandex.AnnotationInstance getSchemaAnnotation(org.jboss.jandex.ClassInfo field)
-
getSchemaAnnotation
public static org.jboss.jandex.AnnotationInstance getSchemaAnnotation(org.jboss.jandex.FieldInfo field)
-
getSchemaAnnotation
public static org.jboss.jandex.AnnotationInstance getSchemaAnnotation(org.jboss.jandex.Type type)
-
isIncludedAllOf
public static boolean isIncludedAllOf(org.jboss.jandex.ClassInfo annotatedClass, org.jboss.jandex.Type type)
-
hasAnnotation
public static boolean hasAnnotation(org.jboss.jandex.AnnotationTarget target, List<org.jboss.jandex.DotName> annotationNames)
-
hasAnnotation
public static boolean hasAnnotation(org.jboss.jandex.AnnotationTarget target, org.jboss.jandex.DotName annotationName)
-
getAnnotation
public static org.jboss.jandex.AnnotationInstance getAnnotation(org.jboss.jandex.AnnotationTarget annotationTarget, org.jboss.jandex.DotName annotationName)
-
getAnnotation
public static org.jboss.jandex.AnnotationInstance getAnnotation(org.jboss.jandex.AnnotationTarget annotationTarget, Collection<org.jboss.jandex.DotName> annotationNames)
-
getAnnotationValue
public static <T> T getAnnotationValue(org.jboss.jandex.AnnotationTarget target, org.jboss.jandex.DotName annotationName)
Convenience method to retrieve the "value" parameter from an annotation bound to the target. The value will be unwrapped from its containingAnnotationValue
.- Type Parameters:
T
- the type of the parameter being retrieved- Parameters:
target
- the target object annotated with the annotation named by annotationNameannotationName
- name of the annotation from which to retrieve the value- Returns:
- an unwrapped annotation parameter value
-
getAnnotationValue
public static <T> T getAnnotationValue(org.jboss.jandex.AnnotationTarget target, List<org.jboss.jandex.DotName> annotationNames)
-
getAnnotationValue
public static <T> T getAnnotationValue(org.jboss.jandex.AnnotationTarget target, org.jboss.jandex.DotName annotationName, String propertyName)
Convenience method to retrieve the named parameter from an annotation bound to the target. The value will be unwrapped from its containingAnnotationValue
.- Type Parameters:
T
- the type of the parameter being retrieved- Parameters:
target
- the target object annotated with the annotation named by annotationNameannotationName
- name of the annotation from which to retrieve the valuepropertyName
- the name of the parameter/property in the annotation- Returns:
- an unwrapped annotation parameter value
-
getAnnotationValue
public static <T> T getAnnotationValue(org.jboss.jandex.AnnotationTarget target, List<org.jboss.jandex.DotName> annotationNames, String propertyName)
-
getAnnotationValue
public static <T> T getAnnotationValue(org.jboss.jandex.AnnotationTarget target, List<org.jboss.jandex.DotName> annotationNames, String propertyName, T defaultValue)
Convenience method to retrieve the named parameter from an annotation bound to the target. The value will be unwrapped from its containingAnnotationValue
.- Type Parameters:
T
- the type of the parameter being retrieved- Parameters:
target
- the target object annotated with the annotation named by annotationNameannotationNames
- names of the annotations from which to retrieve the valuepropertyName
- the name of the parameter/property in the annotationdefaultValue
- a default value to return if either the annotation or the value are missing- Returns:
- an unwrapped annotation parameter value
-
getAnnotationValue
public static <T> T getAnnotationValue(org.jboss.jandex.AnnotationTarget target, org.jboss.jandex.DotName annotationName, String propertyName, T defaultValue)
Convenience method to retrieve the named parameter from an annotation bound to the target. The value will be unwrapped from its containingAnnotationValue
.- Type Parameters:
T
- the type of the parameter being retrieved- Parameters:
target
- the target object annotated with the annotation named by annotationNameannotationName
- name of the annotation from which to retrieve the valuepropertyName
- the name of the parameter/property in the annotationdefaultValue
- a default value to return if either the annotation or the value are missing- Returns:
- an unwrapped annotation parameter value
-
getAnnotations
public static Collection<org.jboss.jandex.AnnotationInstance> getAnnotations(org.jboss.jandex.AnnotationTarget type)
-
getDeclaringClass
public static org.jboss.jandex.ClassInfo getDeclaringClass(org.jboss.jandex.AnnotationTarget type)
-
getAnnotation
public static org.jboss.jandex.AnnotationInstance getAnnotation(org.jboss.jandex.Type type, org.jboss.jandex.DotName annotationName)
-
getAnnotation
public static org.jboss.jandex.AnnotationInstance getAnnotation(org.jboss.jandex.ClassInfo field, org.jboss.jandex.DotName annotationName)
-
getAnnotation
public static org.jboss.jandex.AnnotationInstance getAnnotation(org.jboss.jandex.FieldInfo field, org.jboss.jandex.DotName annotationName)
-
-