Class OpenAPIProcessor

java.lang.Object
javax.annotation.processing.AbstractProcessor
com.github.chhorz.openapi.common.OpenAPIProcessor
All Implemented Interfaces:
Processor
Direct Known Subclasses:
JaxRSOpenApiProcessor, SchemaOpenApiProcessor, SpringWebOpenApiProcessor

public abstract class OpenAPIProcessor extends AbstractProcessor
Abstract annotation processor to provide some common functionality for all specific OpenAPI annotation processors.
Author:
chhorz
  • Field Details

  • Constructor Details

    • OpenAPIProcessor

      public OpenAPIProcessor()
  • Method Details

    • init

      protected void init(ProcessingEnvironment processingEnv, List<Class<?>> baseClasses)
      See Also:
    • getSupportedAnnotationClasses

      protected abstract Stream<Class<? extends Annotation>> getSupportedAnnotationClasses()
      Create a stream of all supported annotation classes
      Returns:
      stream of class elements.
    • getSupportedAnnotationTypes

      public Set<String> getSupportedAnnotationTypes()
      Specified by:
      getSupportedAnnotationTypes in interface Processor
      Overrides:
      getSupportedAnnotationTypes in class AbstractProcessor
    • getSupportedSourceVersion

      public SourceVersion getSupportedSourceVersion()
      Specified by:
      getSupportedSourceVersion in interface Processor
      Overrides:
      getSupportedSourceVersion in class AbstractProcessor
    • getSupportedOptions

      public Set<String> getSupportedOptions()
      Returns a set of all annotation processor options that will be recognized by the implementations of this interface.
      Specified by:
      getSupportedOptions in interface Processor
      Overrides:
      getSupportedOptions in class AbstractProcessor
      Returns:
      a set of annotation processor compiler options
    • initializeFromProperties

      protected OpenAPI initializeFromProperties(GeneratorPropertyLoader propertyLoader)
      Initializes a new OpenAPI domain object with the information from the configuration file.
      Parameters:
      propertyLoader - the property loader that loads the properties from the configuration file
      Returns:
      a new instance of an OpenAPI domain object
    • createJavadocParser

      protected com.github.chhorz.javadoc.JavaDocParser createJavadocParser()
      Initializes a new instance of the external JavaDocParser. The parser will be configured with additional Javadoc tags and the Markdown converter.
      Returns:
      a new instance of the JavaDocParser
    • getOperationId

      protected String getOperationId(ExecutableElement executableElement)
      Creates an OpenAPI operation id from a java method executableElement.
      Parameters:
      executableElement - the executable executableElement that defines a specific method
      Returns:
      the OpenAPI operation id (should be unique)
    • getOperationId

      protected String getOperationId(ExecutableElement executableElement, OpenAPI openAPI)
    • exclude

      protected boolean exclude(ExecutableElement executableElement)
      Checks if the given method should be excluded from the generated OpenAPI file.
      Parameters:
      executableElement - the executable executableElement that defines a specific method
      Returns:
      a flag if the given method should be excluded
    • getTags

      protected List<String> getTags(com.github.chhorz.javadoc.JavaDoc javaDoc, OpenAPI openApiAnnotation)
      Creates a list of tags from the given input sources.
      Parameters:
      javaDoc - the Javadoc from the executable element
      openApiAnnotation - the OpenAPI annotation from the executable element
      Returns:
      a list of tags
    • getSecurityInformation

      protected List<Map<String,List<String>>> getSecurityInformation(ExecutableElement executableElement, OpenAPI openAPI, com.github.chhorz.javadoc.JavaDoc javaDoc, OpenAPI openApiAnnotation)
      Creates a map of security information for a give method.
      Parameters:
      executableElement - the current method
      openAPI - the openapi object with the current parsed data
      javaDoc - the javadoc comment from the current method
      openApiAnnotation - the annotation from the current method
      Returns:
      map of security information
    • runPostProcessors

      protected void runPostProcessors(ParserProperties parserProperties, OpenAPI openApi)
      Runs all registered post processors from the service loader.
      Parameters:
      parserProperties - the configuration properties form the configuration file
      openApi - the generated OpenAPI domain object
    • readOpenApiFile

      protected Optional<OpenAPI> readOpenApiFile(ParserProperties parserProperties)
      Loads an existing OpenAPI schema file.
      Parameters:
      parserProperties - the loaded configuration properties
      Returns:
      an OpenAPI domain object of the configured schema file from the properties
      See Also:
    • isClassAvailable

      public static boolean isClassAvailable(String className)
      Check if the given class is available on the classpath. This check is required for optional maven dependencies.
      Parameters:
      className - the full qualified class name
      Returns:
      true if the class is available on the classpath