Class OpenApiApplicationVisitor

java.lang.Object
io.micronaut.openapi.visitor.OpenApiApplicationVisitor
All Implemented Interfaces:
io.micronaut.core.order.Ordered, io.micronaut.core.util.Toggleable, io.micronaut.inject.visitor.TypeElementVisitor<Object,Object>

public class OpenApiApplicationVisitor extends Object implements io.micronaut.inject.visitor.TypeElementVisitor<Object,Object>
Visits the application class.
Since:
1.0
Author:
graemerocher
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.micronaut.inject.visitor.TypeElementVisitor

    io.micronaut.inject.visitor.TypeElementVisitor.VisitorKind
  • Field Summary

    Fields inherited from interface io.micronaut.core.order.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected io.swagger.v3.oas.models.media.Schema<?>
    bindArraySchemaAnnotationValue(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.TypedElement element, io.swagger.v3.oas.models.media.Schema<?> schemaToBind, io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.ArraySchema> schemaAnn, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
    Binds the array schema for the given element.
    protected io.swagger.v3.oas.models.media.Schema<?>
    bindSchemaAnnotationValue(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.TypedElement element, io.swagger.v3.oas.models.media.Schema<?> schemaToBind, io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.Schema> schemaAnn, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
    Binds the schema for the given element.
    protected io.swagger.v3.oas.models.media.Schema<?>
    bindSchemaForElement(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.TypedElement element, io.micronaut.inject.ast.ClassElement elementType, io.swagger.v3.oas.models.media.Schema<?> schemaToBind, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
    Binds the schema for the given element.
    static String
    expandProperties(String s, List<Pair<String,String>> properties, io.micronaut.inject.visitor.VisitorContext context)
     
    void
    finish(io.micronaut.inject.visitor.VisitorContext context)
     
    int
     
     
    protected void
    processJakartaValidationAnnotations(io.micronaut.inject.ast.Element element, io.micronaut.inject.ast.ClassElement elementType, io.swagger.v3.oas.models.media.Schema<?> schemaToBind)
     
    protected <T, A extends Annotation>
    List<T>
    processOpenApiAnnotation(io.micronaut.inject.ast.Element element, io.micronaut.inject.visitor.VisitorContext context, Class<A> annotationType, Class<T> modelType, List<T> tagList)
    Converts annotation to model.
    protected void
    processSchemaProperty(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.TypedElement element, io.micronaut.inject.ast.ClassElement elementType, @Nullable io.micronaut.inject.ast.ClassElement classElement, io.swagger.v3.oas.models.media.Schema<?> parentSchema, io.swagger.v3.oas.models.media.Schema<?> propertySchema)
    Processes a schema property.
    protected void
    processSecuritySchemes(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
    Processes SecurityScheme annotations.
    protected io.swagger.v3.oas.models.media.Schema<?>
    readSchema(io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.Schema> schemaValue, io.swagger.v3.oas.models.OpenAPI openAPI, io.micronaut.inject.visitor.VisitorContext context, @Nullable io.micronaut.inject.ast.Element type, Map<String,io.micronaut.inject.ast.ClassElement> typeArgs, @Nullable io.micronaut.inject.ast.Element definingElement, List<io.micronaut.http.MediaType> mediaTypes, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
    Reads schema.
    static String
    replacePlaceholders(String value, io.micronaut.inject.visitor.VisitorContext context)
     
    static com.fasterxml.jackson.databind.JsonNode
    resolvePlaceholders(com.fasterxml.jackson.databind.JsonNode node, UnaryOperator<String> propertyExpander)
     
    static com.fasterxml.jackson.databind.JsonNode
    resolvePlaceholders(com.fasterxml.jackson.databind.node.ArrayNode anode, UnaryOperator<String> propertyExpander)
     
    static com.fasterxml.jackson.databind.JsonNode
    resolvePlaceholders(com.fasterxml.jackson.databind.node.ObjectNode onode, UnaryOperator<String> propertyExpander)
     
    protected @Nullable io.swagger.v3.oas.models.media.Schema<?>
    resolveSchema(@Nullable io.micronaut.inject.ast.Element definingElement, io.micronaut.inject.ast.ClassElement type, io.micronaut.inject.visitor.VisitorContext context, List<io.micronaut.http.MediaType> mediaTypes, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
    Resolves the schema for the given type element.
    protected @Nullable io.swagger.v3.oas.models.media.Schema<?>
    resolveSchema(io.swagger.v3.oas.models.OpenAPI openApi, @Nullable io.micronaut.inject.ast.Element definingElement, io.micronaut.inject.ast.ClassElement type, io.micronaut.inject.visitor.VisitorContext context, List<io.micronaut.http.MediaType> mediaTypes, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass, JavadocDescription fieldJavadoc, JavadocDescription classJavadoc)
    Resolves the schema for the given type element.
    void
    start(io.micronaut.inject.visitor.VisitorContext context)
     
    toValueMap(Map<CharSequence,Object> values, io.micronaut.inject.visitor.VisitorContext context, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
    Convert the values to a map.
    void
    visitClass(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.micronaut.core.util.Toggleable

    isEnabled

    Methods inherited from interface io.micronaut.inject.visitor.TypeElementVisitor

    getClassType, getElementType, getSupportedAnnotationNames, getVisitorKind, visitConstructor, visitEnumConstant, visitField, visitMethod
  • Constructor Details

    • OpenApiApplicationVisitor

      public OpenApiApplicationVisitor()
  • Method Details

    • start

      public void start(io.micronaut.inject.visitor.VisitorContext context)
      Specified by:
      start in interface io.micronaut.inject.visitor.TypeElementVisitor<Object,Object>
    • getSupportedOptions

      public Set<String> getSupportedOptions()
      Specified by:
      getSupportedOptions in interface io.micronaut.inject.visitor.TypeElementVisitor<Object,Object>
    • visitClass

      public void visitClass(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
      Specified by:
      visitClass in interface io.micronaut.inject.visitor.TypeElementVisitor<Object,Object>
    • resolvePlaceholders

      public static com.fasterxml.jackson.databind.JsonNode resolvePlaceholders(com.fasterxml.jackson.databind.node.ArrayNode anode, UnaryOperator<String> propertyExpander)
    • resolvePlaceholders

      public static com.fasterxml.jackson.databind.JsonNode resolvePlaceholders(com.fasterxml.jackson.databind.node.ObjectNode onode, UnaryOperator<String> propertyExpander)
    • resolvePlaceholders

      public static com.fasterxml.jackson.databind.JsonNode resolvePlaceholders(com.fasterxml.jackson.databind.JsonNode node, UnaryOperator<String> propertyExpander)
    • expandProperties

      public static String expandProperties(String s, List<Pair<String,String>> properties, io.micronaut.inject.visitor.VisitorContext context)
    • replacePlaceholders

      public static String replacePlaceholders(String value, io.micronaut.inject.visitor.VisitorContext context)
    • finish

      public void finish(io.micronaut.inject.visitor.VisitorContext context)
      Specified by:
      finish in interface io.micronaut.inject.visitor.TypeElementVisitor<Object,Object>
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface io.micronaut.core.order.Ordered
    • toValueMap

      protected Map<CharSequence,Object> toValueMap(Map<CharSequence,Object> values, io.micronaut.inject.visitor.VisitorContext context, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
      Convert the values to a map.
      Parameters:
      values - The values
      context - The visitor context
      jsonViewClass - Class from JsonView annotation
      Returns:
      The map
    • resolveSchema

      @Nullable protected @Nullable io.swagger.v3.oas.models.media.Schema<?> resolveSchema(@Nullable @Nullable io.micronaut.inject.ast.Element definingElement, io.micronaut.inject.ast.ClassElement type, io.micronaut.inject.visitor.VisitorContext context, List<io.micronaut.http.MediaType> mediaTypes, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
      Resolves the schema for the given type element.
      Parameters:
      definingElement - The defining element
      type - The type element
      context - The context
      mediaTypes - An optional media type
      jsonViewClass - Class from JsonView annotation
      Returns:
      The schema or null if it cannot be resolved
    • resolveSchema

      @Nullable protected @Nullable io.swagger.v3.oas.models.media.Schema<?> resolveSchema(io.swagger.v3.oas.models.OpenAPI openApi, @Nullable @Nullable io.micronaut.inject.ast.Element definingElement, io.micronaut.inject.ast.ClassElement type, io.micronaut.inject.visitor.VisitorContext context, List<io.micronaut.http.MediaType> mediaTypes, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass, JavadocDescription fieldJavadoc, JavadocDescription classJavadoc)
      Resolves the schema for the given type element.
      Parameters:
      openApi - The OpenAPI object
      definingElement - The defining element
      type - The type element
      context - The context
      mediaTypes - An optional media type
      fieldJavadoc - Field-level java doc
      classJavadoc - Class-level java doc
      jsonViewClass - Class from JsonView annotation
      Returns:
      The schema or null if it cannot be resolved
    • processSchemaProperty

      protected void processSchemaProperty(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.TypedElement element, io.micronaut.inject.ast.ClassElement elementType, @Nullable @Nullable io.micronaut.inject.ast.ClassElement classElement, io.swagger.v3.oas.models.media.Schema<?> parentSchema, io.swagger.v3.oas.models.media.Schema<?> propertySchema)
      Processes a schema property.
      Parameters:
      context - The visitor context
      element - The element
      elementType - The element type
      classElement - The class element
      parentSchema - The parent schema
      propertySchema - The property schema
    • bindSchemaForElement

      protected io.swagger.v3.oas.models.media.Schema<?> bindSchemaForElement(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.TypedElement element, io.micronaut.inject.ast.ClassElement elementType, io.swagger.v3.oas.models.media.Schema<?> schemaToBind, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
      Binds the schema for the given element.
      Parameters:
      context - The context
      element - The element
      elementType - The element type
      schemaToBind - The schema to bind
      jsonViewClass - Class from JsonView annotation
      Returns:
      The bound schema
    • processJakartaValidationAnnotations

      protected void processJakartaValidationAnnotations(io.micronaut.inject.ast.Element element, io.micronaut.inject.ast.ClassElement elementType, io.swagger.v3.oas.models.media.Schema<?> schemaToBind)
    • bindSchemaAnnotationValue

      protected io.swagger.v3.oas.models.media.Schema<?> bindSchemaAnnotationValue(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.TypedElement element, io.swagger.v3.oas.models.media.Schema<?> schemaToBind, io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.Schema> schemaAnn, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
      Binds the schema for the given element.
      Parameters:
      context - The context
      element - The element
      schemaToBind - The schema to bind
      schemaAnn - The schema annotation
      jsonViewClass - Class from JsonView annotation
      Returns:
      The bound schema
    • bindArraySchemaAnnotationValue

      protected io.swagger.v3.oas.models.media.Schema<?> bindArraySchemaAnnotationValue(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.TypedElement element, io.swagger.v3.oas.models.media.Schema<?> schemaToBind, io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.ArraySchema> schemaAnn, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
      Binds the array schema for the given element.
      Parameters:
      context - The context
      element - The element
      schemaToBind - The schema to bind
      schemaAnn - The schema annotation
      jsonViewClass - Class from JsonView annotation
      Returns:
      The bound schema
    • readSchema

      protected io.swagger.v3.oas.models.media.Schema<?> readSchema(io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.Schema> schemaValue, io.swagger.v3.oas.models.OpenAPI openAPI, io.micronaut.inject.visitor.VisitorContext context, @Nullable @Nullable io.micronaut.inject.ast.Element type, Map<String,io.micronaut.inject.ast.ClassElement> typeArgs, @Nullable @Nullable io.micronaut.inject.ast.Element definingElement, List<io.micronaut.http.MediaType> mediaTypes, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
      Reads schema.
      Parameters:
      schemaValue - annotation value
      openAPI - The OpenApi
      context - The VisitorContext
      type - type element
      typeArgs - type arguments
      mediaTypes - The media types of schema
      jsonViewClass - Class from JsonView annotation
      Returns:
      New schema instance
    • processSecuritySchemes

      protected void processSecuritySchemes(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
      Processes SecurityScheme annotations.
      Parameters:
      element - The element
      context - The visitor context
    • processOpenApiAnnotation

      protected <T, A extends Annotation> List<T> processOpenApiAnnotation(io.micronaut.inject.ast.Element element, io.micronaut.inject.visitor.VisitorContext context, Class<A> annotationType, Class<T> modelType, List<T> tagList)
      Converts annotation to model.
      Type Parameters:
      T - The model type.
      A - The annotation type.
      Parameters:
      element - The element to process.
      context - The context.
      annotationType - The annotation type.
      modelType - The model type.
      tagList - The initial list of models.
      Returns:
      A list of model objects.