Package com.github.chhorz.openapi.common
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
Abstract annotation processor to provide some common functionality for all specific OpenAPI annotation processors.
- Author:
- chhorz
-
Field Summary
Modifier and TypeFieldDescriptionprotected Elements
protected com.github.chhorz.javadoc.JavaDocParser
protected LogUtils
protected OpenAPI
protected ParserProperties
protected ProcessingUtils
protected GeneratorPropertyLoader
protected ResponseUtils
protected SchemaUtils
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected com.github.chhorz.javadoc.JavaDocParser
Initializes a new instance of the external JavaDocParser.protected boolean
exclude
(ExecutableElement executableElement) Checks if the given method should be excluded from the generated OpenAPI file.protected String
getOperationId
(ExecutableElement executableElement) Creates an OpenAPI operation id from a java method executableElement.protected String
getOperationId
(ExecutableElement executableElement, OpenAPI openAPI) getSecurityInformation
(ExecutableElement executableElement, OpenAPI openAPI, com.github.chhorz.javadoc.JavaDoc javaDoc, OpenAPI openApiAnnotation) Creates a map of security information for a give method.protected abstract Stream<Class<? extends Annotation>>
Create a stream of all supported annotation classesReturns a set of all annotation processor options that will be recognized by the implementations of this interface.Creates a list of tags from the given input sources.protected void
init
(ProcessingEnvironment processingEnv, List<Class<?>> baseClasses) protected OpenAPI
initializeFromProperties
(GeneratorPropertyLoader propertyLoader) Initializes a new OpenAPI domain object with the information from the configuration file.static boolean
isClassAvailable
(String className) Check if the given class is available on the classpath.readOpenApiFile
(ParserProperties parserProperties) Loads an existing OpenAPI schema file.protected void
runPostProcessors
(ParserProperties parserProperties, OpenAPI openApi) Runs all registered post processors from the service loader.Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, init, isInitialized, process
-
Field Details
-
elements
-
propertyLoader
-
parserProperties
-
logUtils
-
schemaUtils
-
processingUtils
-
responseUtils
-
javaDocParser
protected com.github.chhorz.javadoc.JavaDocParser javaDocParser -
openApi
-
-
Constructor Details
-
OpenAPIProcessor
public OpenAPIProcessor()
-
-
Method Details
-
init
-
getSupportedAnnotationClasses
Create a stream of all supported annotation classes- Returns:
- stream of class elements.
-
getSupportedAnnotationTypes
- Specified by:
getSupportedAnnotationTypes
in interfaceProcessor
- Overrides:
getSupportedAnnotationTypes
in classAbstractProcessor
-
getSupportedSourceVersion
- Specified by:
getSupportedSourceVersion
in interfaceProcessor
- Overrides:
getSupportedSourceVersion
in classAbstractProcessor
-
getSupportedOptions
Returns a set of all annotation processor options that will be recognized by the implementations of this interface.- Specified by:
getSupportedOptions
in interfaceProcessor
- Overrides:
getSupportedOptions
in classAbstractProcessor
- Returns:
- a set of annotation processor compiler options
-
initializeFromProperties
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
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
-
exclude
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 elementopenApiAnnotation
- theOpenAPI
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 methodopenAPI
- the openapi object with the current parsed datajavaDoc
- the javadoc comment from the current methodopenApiAnnotation
- the annotation from the current method- Returns:
- map of security information
-
runPostProcessors
Runs all registered post processors from the service loader.- Parameters:
parserProperties
- the configuration properties form the configuration fileopenApi
- the generated OpenAPI domain object
-
readOpenApiFile
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
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
-