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<io.swagger.v3.oas.annotations.OpenAPIDefinition,Object>

@SupportedOptions({"micronaut.openapi.enabled","micronaut.openapi.server.context.path","micronaut.openapi.property.naming.strategy","micronaut.openapi.views.spec","micronaut.openapi.filename","micronaut.openapi.json.format","micronaut.openapi.environments","micronaut.environment.enabled","micronaut.openapi.field.visibility.level","micronaut.openapi.config.file.locations","micronaut.openapi.target.file","micronaut.openapi.views.dest.dir","micronaut.openapi.additional.files","micronaut.openapi.config.file","micronaut.openapi.security.enabled"}) public class OpenApiApplicationVisitor extends Object implements io.micronaut.inject.visitor.TypeElementVisitor<io.swagger.v3.oas.annotations.OpenAPIDefinition,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
    Modifier and Type
    Field
    Description
    static final String
    Config file locations.
    static final String
    Is this property true, properties wll be loaded in the standard way from application.yml.
    static final String
    System property that specifies the location of additional swagger YAML and JSON files to read from.
    static final String
    System property that enables setting the open api config file.
    static final String
    System property for server context path.
    static final String
    System property that enables or disables open api annotation processing.
    static final String
    The name of the entry for Endpoint class tags in the context.
    static final String
    The name of the entry for Endpoint security requirements in the context.
    static final String
    The name of the entry for Endpoint servers in the context.
    static final String
    Active micronaut environments which will be used for @Requires annotations.
    static final String
    Prefix for expandable properties.
    static final String
    System property that specifies the schema classes fields visibility level.
    static final String
    The name of the result swagger file.
    static final String
    Is this property true, output file format will be JSON, otherwise YAML.
    static final String
    System property for naming strategy.
    static final String
    System property that specifies the default security schema name, if it's not specified by annotation SecurityScheme.
    static final String
    Is this property true, micronaut-openapi will process micronaut-security proerties and annotations to construct openapi security schema.
    static final String
    System property that enables setting the target file to write to.
    static final String
    System property that specifies the path where the generated UI elements will be located.
    static final String
    System property for views specification.
    static final String
    Default openapi config file.

    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.Element element, io.swagger.v3.oas.models.media.Schema schemaToBind, io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.ArraySchema> schemaAnn)
    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)
    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)
    Binds the schema for the given element.
    static String
    expandProperties(String s, List<Map.Entry<String,String>> properties, io.micronaut.inject.visitor.VisitorContext context)
     
    void
    finish(io.micronaut.inject.visitor.VisitorContext context)
     
    static List<String>
    getActiveEnvs(io.micronaut.inject.visitor.VisitorContext context)
     
    static boolean
    getBooleanProperty(String property, boolean defaultValue, io.micronaut.inject.visitor.VisitorContext context)
     
    static String
    getConfigurationProperty(String key, io.micronaut.inject.visitor.VisitorContext context)
     
    static io.micronaut.inject.ast.ClassElement
    getCustomSchema(String className, Map<String,io.micronaut.inject.ast.ClassElement> typeArgs, io.micronaut.inject.visitor.VisitorContext context)
     
    static @Nullable io.micronaut.context.env.Environment
    getEnv(io.micronaut.inject.visitor.VisitorContext context)
     
    getExpandableProperties(io.micronaut.inject.visitor.VisitorContext context)
     
    int
     
    static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.SchemaDecorator
    getSchemaDecoration(String packageName, io.micronaut.inject.visitor.VisitorContext context)
     
    getSecurityProperties(io.micronaut.inject.visitor.VisitorContext context)
     
    protected boolean
    isElementNotNullable(io.micronaut.inject.ast.Element element, @Nullable io.micronaut.inject.ast.Element classElement)
     
    static boolean
    isOpenApiEnabled(io.micronaut.inject.visitor.VisitorContext context)
     
    static String
     
    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.
    static Properties
    readOpenApiConfigFile(io.micronaut.inject.visitor.VisitorContext context)
     
    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)
    Reads schema.
    static String
    replacePlaceholders(String value, io.micronaut.inject.visitor.VisitorContext context)
     
    static Path
    resolve(io.micronaut.inject.visitor.VisitorContext context, Path path)
     
    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)
    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, JavadocDescription fieldJavadoc, JavadocDescription classJavadoc)
    Resolves the schema for the given type element.
    toValueMap(Map<CharSequence,Object> values, io.micronaut.inject.visitor.VisitorContext context)
    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, getSupportedOptions, getVisitorKind, start, visitConstructor, visitEnumConstant, visitField, visitMethod
  • Field Details

    • MICRONAUT_OPENAPI_ENABLED

      public static final String MICRONAUT_OPENAPI_ENABLED
      System property that enables or disables open api annotation processing.
      Default: true
      See Also:
    • MICRONAUT_OPENAPI_CONFIG_FILE

      public static final String MICRONAUT_OPENAPI_CONFIG_FILE
      System property that enables setting the open api config file.
      See Also:
    • MICRONAUT_OPENAPI_EXPAND_PREFIX

      public static final String MICRONAUT_OPENAPI_EXPAND_PREFIX
      Prefix for expandable properties.
      See Also:
    • MICRONAUT_OPENAPI_CONTEXT_SERVER_PATH

      public static final String MICRONAUT_OPENAPI_CONTEXT_SERVER_PATH
      System property for server context path.
      See Also:
    • MICRONAUT_OPENAPI_PROPERTY_NAMING_STRATEGY

      public static final String MICRONAUT_OPENAPI_PROPERTY_NAMING_STRATEGY
      System property for naming strategy. One jackson PropertyNamingStrategy.
      See Also:
    • MICRONAUT_OPENAPI_VIEWS_SPEC

      public static final String MICRONAUT_OPENAPI_VIEWS_SPEC
      System property for views specification.
      See Also:
    • MICRONAUT_OPENAPI_TARGET_FILE

      public static final String MICRONAUT_OPENAPI_TARGET_FILE
      System property that enables setting the target file to write to.
      See Also:
    • MICRONAUT_OPENAPI_VIEWS_DEST_DIR

      public static final String MICRONAUT_OPENAPI_VIEWS_DEST_DIR
      System property that specifies the path where the generated UI elements will be located.
      See Also:
    • MICRONAUT_OPENAPI_ADDITIONAL_FILES

      public static final String MICRONAUT_OPENAPI_ADDITIONAL_FILES
      System property that specifies the location of additional swagger YAML and JSON files to read from.
      See Also:
    • MICRONAUT_OPENAPI_SECURITY_DEFAULT_SCHEMA_NAME

      public static final String MICRONAUT_OPENAPI_SECURITY_DEFAULT_SCHEMA_NAME
      System property that specifies the default security schema name, if it's not specified by annotation SecurityScheme.
      See Also:
    • MICRONAUT_OPENAPI_FIELD_VISIBILITY_LEVEL

      public static final String MICRONAUT_OPENAPI_FIELD_VISIBILITY_LEVEL
      System property that specifies the schema classes fields visibility level. By default, only public fields visibile.

      Available values:

      PRIVATE PACKAGE PROTECTED PUBLIC
      See Also:
    • OPENAPI_CONFIG_FILE

      public static final String OPENAPI_CONFIG_FILE
      Default openapi config file.
      See Also:
    • MICRONAUT_OPENAPI_ENDPOINT_CLASS_TAGS

      public static final String MICRONAUT_OPENAPI_ENDPOINT_CLASS_TAGS
      The name of the entry for Endpoint class tags in the context.
      See Also:
    • MICRONAUT_OPENAPI_ENDPOINT_SERVERS

      public static final String MICRONAUT_OPENAPI_ENDPOINT_SERVERS
      The name of the entry for Endpoint servers in the context.
      See Also:
    • MICRONAUT_OPENAPI_ENDPOINT_SECURITY_REQUIREMENTS

      public static final String MICRONAUT_OPENAPI_ENDPOINT_SECURITY_REQUIREMENTS
      The name of the entry for Endpoint security requirements in the context.
      See Also:
    • MICRONAUT_OPENAPI_JSON_FORMAT

      public static final String MICRONAUT_OPENAPI_JSON_FORMAT
      Is this property true, output file format will be JSON, otherwise YAML.
      See Also:
    • MICRONAUT_OPENAPI_FILENAME

      public static final String MICRONAUT_OPENAPI_FILENAME
      The name of the result swagger file.

      Default filename is <info.title>-<info.version>.yml. If info annotation not set, filename will be swagger.yml.

      See Also:
    • MICRONAUT_OPENAPI_ENVIRONMENTS

      public static final String MICRONAUT_OPENAPI_ENVIRONMENTS
      Active micronaut environments which will be used for @Requires annotations.
      See Also:
    • MICRONAUT_ENVIRONMENT_ENABLED

      public static final String MICRONAUT_ENVIRONMENT_ENABLED
      Is this property true, properties wll be loaded in the standard way from application.yml. Also, environments from "micronaut.openapi.environments" property will set as additional environments, if you want to set specific environment name for openAPI generator.
      Default value is "true".
      See Also:
    • MICRONAUT_OPENAPI_SECURITY_ENABLED

      public static final String MICRONAUT_OPENAPI_SECURITY_ENABLED
      Is this property true, micronaut-openapi will process micronaut-security proerties and annotations to construct openapi security schema.
      Default value is "true".
      See Also:
    • MICRONAUT_CONFIG_FILE_LOCATIONS

      public static final String MICRONAUT_CONFIG_FILE_LOCATIONS
      Config file locations. By default, micronaut-openapi search config in standard path: <project_path>/src/main/resources/

      You can set your custom paths separated by ','. To set absolute paths use prefix 'file:', classpath paths use prefix 'classpath:' or use prefix 'project:' to set paths from project directory.

      See Also:
  • Constructor Details

    • OpenApiApplicationVisitor

      public OpenApiApplicationVisitor()
  • Method Details

    • isOpenApiEnabled

      public static boolean isOpenApiEnabled(io.micronaut.inject.visitor.VisitorContext context)
    • 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<io.swagger.v3.oas.annotations.OpenAPIDefinition,Object>
    • getSchemaDecoration

      public static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.SchemaDecorator getSchemaDecoration(String packageName, io.micronaut.inject.visitor.VisitorContext context)
    • getCustomSchema

      public static io.micronaut.inject.ast.ClassElement getCustomSchema(String className, Map<String,io.micronaut.inject.ast.ClassElement> typeArgs, io.micronaut.inject.visitor.VisitorContext context)
    • getConfigurationProperty

      public static String getConfigurationProperty(String key, io.micronaut.inject.visitor.VisitorContext context)
    • getSecurityProperties

      public static SecurityProperties getSecurityProperties(io.micronaut.inject.visitor.VisitorContext context)
    • getBooleanProperty

      public static boolean getBooleanProperty(String property, boolean defaultValue, io.micronaut.inject.visitor.VisitorContext context)
    • getEnv

      @Nullable public static @Nullable io.micronaut.context.env.Environment getEnv(io.micronaut.inject.visitor.VisitorContext context)
    • getActiveEnvs

      public static List<String> getActiveEnvs(io.micronaut.inject.visitor.VisitorContext context)
    • resolve

      public static Path resolve(io.micronaut.inject.visitor.VisitorContext context, Path path)
    • readOpenApiConfigFile

      public static Properties readOpenApiConfigFile(io.micronaut.inject.visitor.VisitorContext context)
    • 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<Map.Entry<String,String>> properties, io.micronaut.inject.visitor.VisitorContext context)
    • replacePlaceholders

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

      public static List<Map.Entry<String,String>> getExpandableProperties(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<io.swagger.v3.oas.annotations.OpenAPIDefinition,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)
      Convert the values to a map.
      Parameters:
      values - The values
      context - The visitor context
      Returns:
      The map
    • prependIfMissing

      public static String prependIfMissing(String str, String prefix)
    • 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)
      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
      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, 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
      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
    • isElementNotNullable

      protected boolean isElementNotNullable(io.micronaut.inject.ast.Element element, @Nullable @Nullable io.micronaut.inject.ast.Element classElement)
    • 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)
      Binds the schema for the given element.
      Parameters:
      context - The context
      element - The element
      elementType - The element type
      schemaToBind - The schema to bind
      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)
      Binds the schema for the given element.
      Parameters:
      context - The context
      element - The element
      schemaToBind - The schema to bind
      schemaAnn - The schema 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)
      Binds the array schema for the given element.
      Parameters:
      context - The context
      element - The element
      schemaToBind - The schema to bind
      schemaAnn - The schema 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) throws com.fasterxml.jackson.core.JsonProcessingException
      Reads schema.
      Parameters:
      schemaValue - annotation value
      openAPI - The OpenApi
      context - The VisitorContext
      type - type element
      typeArgs - type arguments
      mediaTypes - The media types of schema
      Returns:
      New schema instance
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - when Json parsing fails
    • 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.