Class AbstractOpenApiEndpointVisitor

java.lang.Object
io.micronaut.openapi.visitor.AbstractOpenApiEndpointVisitor
Direct Known Subclasses:
OpenApiControllerVisitor, OpenApiEndpointVisitor

public abstract class AbstractOpenApiEndpointVisitor extends Object
A TypeElementVisitor the builds the Swagger model from Micronaut controllers at compile time.
Since:
1.0
Author:
graemerocher
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected io.swagger.v3.oas.models.ExternalDocumentation
     
    protected List<io.swagger.v3.oas.models.tags.Tag>
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
  • 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.Element 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.Element 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.
    protected abstract List<io.swagger.v3.oas.models.tags.Tag>
    classTags(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
    Returns the class tags.
    protected abstract List<io.micronaut.http.MediaType>
    consumesMediaTypes(io.micronaut.inject.ast.MethodElement element)
    Returns the consumes media types.
    protected abstract String
    description(io.micronaut.inject.ast.MethodElement element)
    Returns the description for the element.
    protected abstract io.micronaut.http.HttpMethod
    httpMethod(io.micronaut.inject.ast.MethodElement element)
    Returns the HttpMethod of the element.
    protected abstract boolean
    ignore(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
    Returns true if the specified element should not be processed.
    protected abstract boolean
    ignore(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
    Returns true if the specified element should not be processed.
    protected abstract List<io.swagger.v3.oas.models.security.SecurityRequirement>
    methodSecurityRequirements(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
    Returns the security requirements at method level.
    protected abstract List<io.swagger.v3.oas.models.servers.Server>
    methodServers(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
    Returns the servers at method level.
    protected void
    processJavaxValidationAnnotations(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.Element 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 abstract List<io.micronaut.http.MediaType>
    producesMediaTypes(io.micronaut.inject.ast.MethodElement element)
    Returns the produces media types.
    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, List<io.micronaut.http.MediaType> mediaTypes, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
    Reads schema.
    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.
    toValueMap(Map<CharSequence,Object> values, io.micronaut.inject.visitor.VisitorContext context, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass)
    Convert the values to a map.
    protected abstract List<io.micronaut.http.uri.UriMatchTemplate>
    uriMatchTemplates(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
    Returns the uri paths of the element.
    void
    visitClass(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
    Executed when a class is encountered that matches the generic class.
    void
    visitMethod(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
    Executed when a method is encountered that matches the generic element.

    Methods inherited from class java.lang.Object

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

    • CONTEXT_CHILD_PATH

      protected static final String CONTEXT_CHILD_PATH
      See Also:
    • CONTEXT_CHILD_OP_ID_PREFIX

      protected static final String CONTEXT_CHILD_OP_ID_PREFIX
      See Also:
    • CONTEXT_CHILD_OP_ID_SUFFIX

      protected static final String CONTEXT_CHILD_OP_ID_SUFFIX
      See Also:
    • CONTEXT_CHILD_OP_ID_SUFFIX_ADD_ALWAYS

      protected static final String CONTEXT_CHILD_OP_ID_SUFFIX_ADD_ALWAYS
      See Also:
    • IS_PROCESS_PARENT_CLASS

      protected static final String IS_PROCESS_PARENT_CLASS
      See Also:
    • classTags

      protected List<io.swagger.v3.oas.models.tags.Tag> classTags
    • classExternalDocs

      protected io.swagger.v3.oas.models.ExternalDocumentation classExternalDocs
  • Constructor Details

    • AbstractOpenApiEndpointVisitor

      public AbstractOpenApiEndpointVisitor()
  • Method Details

    • visitClass

      public void visitClass(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
      Executed when a class is encountered that matches the generic class.
      Parameters:
      element - The element
      context - The visitor context
    • methodSecurityRequirements

      protected abstract List<io.swagger.v3.oas.models.security.SecurityRequirement> methodSecurityRequirements(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
      Returns the security requirements at method level.
      Parameters:
      element - The MethodElement.
      context - The context.
      Returns:
      The security requirements.
    • methodServers

      protected abstract List<io.swagger.v3.oas.models.servers.Server> methodServers(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
      Returns the servers at method level.
      Parameters:
      element - The MethodElement.
      context - The context.
      Returns:
      The servers.
    • classTags

      protected abstract List<io.swagger.v3.oas.models.tags.Tag> classTags(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
      Returns the class tags.
      Parameters:
      element - The ClassElement.
      context - The context.
      Returns:
      The class tags.
    • ignore

      protected abstract boolean ignore(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)
      Returns true if the specified element should not be processed.
      Parameters:
      element - The ClassElement.
      context - The context.
      Returns:
      true if the specified element should not be processed.
    • ignore

      protected abstract boolean ignore(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
      Returns true if the specified element should not be processed.
      Parameters:
      element - The ClassElement.
      context - The context.
      Returns:
      true if the specified element should not be processed.
    • httpMethod

      protected abstract io.micronaut.http.HttpMethod httpMethod(io.micronaut.inject.ast.MethodElement element)
      Returns the HttpMethod of the element.
      Parameters:
      element - The MethodElement.
      Returns:
      The HttpMethod of the element.
    • uriMatchTemplates

      protected abstract List<io.micronaut.http.uri.UriMatchTemplate> uriMatchTemplates(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
      Returns the uri paths of the element.
      Parameters:
      element - The MethodElement.
      context - The context
      Returns:
      The uri paths of the element.
    • consumesMediaTypes

      protected abstract List<io.micronaut.http.MediaType> consumesMediaTypes(io.micronaut.inject.ast.MethodElement element)
      Returns the consumes media types.
      Parameters:
      element - The MethodElement.
      Returns:
      The consumes media types.
    • producesMediaTypes

      protected abstract List<io.micronaut.http.MediaType> producesMediaTypes(io.micronaut.inject.ast.MethodElement element)
      Returns the produces media types.
      Parameters:
      element - The MethodElement.
      Returns:
      The produces media types.
    • description

      protected abstract String description(io.micronaut.inject.ast.MethodElement element)
      Returns the description for the element.
      Parameters:
      element - The MethodElement.
      Returns:
      The description for the element.
    • visitMethod

      public void visitMethod(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)
      Executed when a method is encountered that matches the generic element.
      Parameters:
      element - The element
      context - The visitor context
    • 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.Element 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
    • processJavaxValidationAnnotations

      protected void processJavaxValidationAnnotations(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.Element 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.Element 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, 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.