Package io.micronaut.openapi.visitor
Class OpenApiControllerVisitor
java.lang.Object
io.micronaut.openapi.visitor.AbstractOpenApiEndpointVisitor
io.micronaut.openapi.visitor.OpenApiControllerVisitor
- All Implemented Interfaces:
io.micronaut.core.order.Ordered
,io.micronaut.core.util.Toggleable
,io.micronaut.inject.visitor.TypeElementVisitor<Object,
io.micronaut.http.annotation.HttpMethodMapping>
@SupportedOptions("micronaut.openapi.enabled")
public class OpenApiControllerVisitor
extends AbstractOpenApiEndpointVisitor
implements io.micronaut.inject.visitor.TypeElementVisitor<Object,io.micronaut.http.annotation.HttpMethodMapping>
A
TypeElementVisitor
the builds the Swagger model from Micronaut controllers at compile time.- 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 class io.micronaut.openapi.visitor.AbstractOpenApiEndpointVisitor
classExternalDocs, classTags
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionOpenApiControllerVisitor
(List<io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.tags.Tag>> additionalTags, List<io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.security.SecurityRequirement>> additionalSecurityRequirements, String customUri) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.protected 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 List<io.micronaut.http.MediaType>
consumesMediaTypes
(io.micronaut.inject.ast.MethodElement element) Returns the consumes media types.protected String
description
(io.micronaut.inject.ast.MethodElement element) Returns the description for the element.int
getOrder()
protected io.micronaut.http.HttpMethod
httpMethod
(io.micronaut.inject.ast.MethodElement element) Returns the HttpMethod of the element.protected 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 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 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 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
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) ProcessesSecurityScheme
annotations.protected 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, @Nullable io.micronaut.inject.ast.Element definingElement, 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.void
start
(io.micronaut.inject.visitor.VisitorContext context) protected Map<CharSequence,
Object> 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 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.Methods inherited from class io.micronaut.openapi.visitor.AbstractOpenApiEndpointVisitor
visitClass, visitMethod
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
finish, getClassType, getElementType, getSupportedAnnotationNames, getSupportedOptions, getVisitorKind, visitClass, visitConstructor, visitEnumConstant, visitField, visitMethod
-
Constructor Details
-
OpenApiControllerVisitor
public OpenApiControllerVisitor() -
OpenApiControllerVisitor
-
-
Method Details
-
start
public void start(io.micronaut.inject.visitor.VisitorContext context) - Specified by:
start
in interfaceio.micronaut.inject.visitor.TypeElementVisitor<Object,
io.micronaut.http.annotation.HttpMethodMapping>
-
ignore
protected boolean ignore(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context) Description copied from class:AbstractOpenApiEndpointVisitor
Returns true if the specified element should not be processed.- Specified by:
ignore
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The ClassElement.context
- The context.- Returns:
- true if the specified element should not be processed.
-
ignore
protected boolean ignore(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context) Description copied from class:AbstractOpenApiEndpointVisitor
Returns true if the specified element should not be processed.- Specified by:
ignore
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The ClassElement.context
- The context.- Returns:
- true if the specified element should not be processed.
-
httpMethod
protected io.micronaut.http.HttpMethod httpMethod(io.micronaut.inject.ast.MethodElement element) Description copied from class:AbstractOpenApiEndpointVisitor
Returns the HttpMethod of the element.- Specified by:
httpMethod
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The MethodElement.- Returns:
- The HttpMethod of the element.
-
consumesMediaTypes
protected List<io.micronaut.http.MediaType> consumesMediaTypes(io.micronaut.inject.ast.MethodElement element) Description copied from class:AbstractOpenApiEndpointVisitor
Returns the consumes media types.- Specified by:
consumesMediaTypes
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The MethodElement.- Returns:
- The consumes media types.
-
producesMediaTypes
protected List<io.micronaut.http.MediaType> producesMediaTypes(io.micronaut.inject.ast.MethodElement element) Description copied from class:AbstractOpenApiEndpointVisitor
Returns the produces media types.- Specified by:
producesMediaTypes
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The MethodElement.- Returns:
- The produces media types.
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceio.micronaut.core.order.Ordered
-
uriMatchTemplates
protected List<io.micronaut.http.uri.UriMatchTemplate> uriMatchTemplates(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context) Description copied from class:AbstractOpenApiEndpointVisitor
Returns the uri paths of the element.- Specified by:
uriMatchTemplates
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The MethodElement.context
- The context- Returns:
- The uri paths of the element.
-
description
Description copied from class:AbstractOpenApiEndpointVisitor
Returns the description for the element.- Specified by:
description
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The MethodElement.- Returns:
- The description for the element.
-
classTags
protected List<io.swagger.v3.oas.models.tags.Tag> classTags(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context) Description copied from class:AbstractOpenApiEndpointVisitor
Returns the class tags.- Specified by:
classTags
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The ClassElement.context
- The context.- Returns:
- The class tags.
-
methodServers
protected List<io.swagger.v3.oas.models.servers.Server> methodServers(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context) Description copied from class:AbstractOpenApiEndpointVisitor
Returns the servers at method level.- Specified by:
methodServers
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The MethodElement.context
- The context.- Returns:
- The servers.
-
methodSecurityRequirements
protected List<io.swagger.v3.oas.models.security.SecurityRequirement> methodSecurityRequirements(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context) Description copied from class:AbstractOpenApiEndpointVisitor
Returns the security requirements at method level.- Specified by:
methodSecurityRequirements
in classAbstractOpenApiEndpointVisitor
- Parameters:
element
- The MethodElement.context
- The context.- Returns:
- The security requirements.
-
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 valuescontext
- The visitor contextjsonViewClass
- 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 elementtype
- The type elementcontext
- The contextmediaTypes
- An optional media typejsonViewClass
- 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 objectdefiningElement
- The defining elementtype
- The type elementcontext
- The contextmediaTypes
- An optional media typefieldJavadoc
- Field-level java docclassJavadoc
- Class-level java docjsonViewClass
- 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 contextelement
- The elementelementType
- The element typeclassElement
- The class elementparentSchema
- The parent schemapropertySchema
- 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 contextelement
- The elementelementType
- The element typeschemaToBind
- The schema to bindjsonViewClass
- 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 contextelement
- The elementschemaToBind
- The schema to bindschemaAnn
- The schema annotationjsonViewClass
- 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 contextelement
- The elementschemaToBind
- The schema to bindschemaAnn
- The schema annotationjsonViewClass
- 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 valueopenAPI
- The OpenApicontext
- The VisitorContexttype
- type elementtypeArgs
- type argumentsmediaTypes
- The media types of schemajsonViewClass
- Class from JsonView annotation- Returns:
- New schema instance
-
processSecuritySchemes
protected void processSecuritySchemes(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context) ProcessesSecurityScheme
annotations.- Parameters:
element
- The elementcontext
- 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.
-