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 final org.jboss.jandex.IndexView
     
  • Method Summary

    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, org.jboss.jandex.AnnotationInstance schemaAnnotation)
    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.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(AnnotationScannerContext context, 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 boolean
    isA(AnnotationScannerContext context, org.jboss.jandex.Type testSubject, org.jboss.jandex.Type testObject)
    Test whether testSubject is an "instanceof" type testObject.
    static boolean
    isAllOf(AnnotationScannerContext context, org.jboss.jandex.ClassInfo annotatedClass, org.jboss.jandex.Type type)
     
    static boolean
    isIncludedAllOf(AnnotationScannerContext context, 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(AnnotationScannerContext context, 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 void
    mapDeprecated(AnnotationScannerContext context, org.jboss.jandex.AnnotationTarget target, Supplier<Boolean> getDeprecated, Consumer<Boolean> setDeprecated)
     
    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)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • jdkIndex

      public static final org.jboss.jandex.IndexView jdkIndex
  • Method Details

    • 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 context
      classType - 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(AnnotationScannerContext context, 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 type
      schemaAnnotation - 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, org.jboss.jandex.AnnotationInstance schemaAnnotation)
      Sets the default schema attributes for the given type on the provided schema instance.
      Parameters:
      classType - the type
      schema - 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 typeSchema
      typeSchema - 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 context
      testSubject - type to test
      testObject - 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(AnnotationScannerContext context, org.jboss.jandex.AnnotationTarget annotationTarget)
    • isIncludedAllOf

      public static boolean isIncludedAllOf(AnnotationScannerContext context, org.jboss.jandex.ClassInfo annotatedClass, org.jboss.jandex.Type type)
    • isAllOf

      public static boolean isAllOf(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)
    • mapDeprecated

      public static void mapDeprecated(AnnotationScannerContext context, org.jboss.jandex.AnnotationTarget target, Supplier<Boolean> getDeprecated, Consumer<Boolean> setDeprecated)