Package io.micronaut.openapi.visitor
Class AbstractOpenApiEndpointVisitor
- java.lang.Object
-
- io.micronaut.openapi.visitor.AbstractOpenApiEndpointVisitor
-
- Direct Known Subclasses:
OpenApiControllerVisitor,OpenApiEndpointVisitor
public abstract class AbstractOpenApiEndpointVisitor extends java.lang.ObjectATypeElementVisitorthe builds the Swagger model from Micronaut controllers at compile time.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description protected io.swagger.v3.oas.models.ExternalDocumentationclassExternalDocsprotected java.util.List<io.swagger.v3.oas.models.tags.Tag>classTagsstatic java.lang.StringCOMPONENTS_CALLBACKS_PREFIXprotected static java.lang.StringCONTEXT_CHILD_OP_ID_PREFIXprotected static java.lang.StringCONTEXT_CHILD_OP_ID_SUFFIXprotected static java.lang.StringCONTEXT_CHILD_OP_ID_SUFFIX_ADD_ALWAYSprotected static java.lang.StringCONTEXT_CHILD_PATHprotected static java.lang.StringIS_PROCESS_PARENT_CLASS
-
Constructor Summary
Constructors Constructor Description AbstractOpenApiEndpointVisitor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected io.swagger.v3.oas.models.media.SchemabindArraySchemaAnnotationValue(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.SchemabindSchemaAnnotationValue(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.SchemabindSchemaForElement(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.Element element, io.micronaut.inject.ast.ClassElement elementType, io.swagger.v3.oas.models.media.Schema schemaToBind)Binds the schema for the given element.protected abstract java.util.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 java.util.List<io.micronaut.http.MediaType>consumesMediaTypes(io.micronaut.inject.ast.MethodElement element)Returns the consumes media types.protected abstract java.lang.Stringdescription(io.micronaut.inject.ast.MethodElement element)Returns the description for the element.protected abstract io.micronaut.http.HttpMethodhttpMethod(io.micronaut.inject.ast.MethodElement element)Returns the HttpMethod of the element.protected abstract booleanignore(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)Returns true if the specified element should not be processed.protected abstract booleanignore(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)Returns true if the specified element should not be processed.protected booleanisElementNotNullable(io.micronaut.inject.ast.Element element, io.micronaut.inject.ast.Element classElement)protected abstract java.util.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 java.util.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 voidprocessJavaxValidationAnnotations(io.micronaut.inject.ast.Element element, io.micronaut.inject.ast.ClassElement elementType, io.swagger.v3.oas.models.media.Schema schemaToBind)protected <T,A extends java.lang.annotation.Annotation>
java.util.List<T>processOpenApiAnnotation(io.micronaut.inject.ast.Element element, io.micronaut.inject.visitor.VisitorContext context, java.lang.Class<A> annotationType, java.lang.Class<T> modelType, java.util.List<T> tagList)Converts annotation to model.protected voidprocessSchemaProperty(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.Element element, io.micronaut.inject.ast.ClassElement elementType, 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 voidprocessSecuritySchemes(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)ProcessesSecuritySchemeannotations.protected abstract java.util.List<io.micronaut.http.MediaType>producesMediaTypes(io.micronaut.inject.ast.MethodElement element)Returns the produces media types.protected io.swagger.v3.oas.models.media.SchemareadSchema(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, io.micronaut.inject.ast.Element type, java.util.List<io.micronaut.http.MediaType> mediaTypes)Reads schema.protected io.swagger.v3.oas.models.media.SchemaresolveSchema(io.micronaut.inject.ast.Element definingElement, io.micronaut.inject.ast.ClassElement type, io.micronaut.inject.visitor.VisitorContext context, java.util.List<io.micronaut.http.MediaType> mediaTypes)Resolves the schema for the given type element.protected io.swagger.v3.oas.models.media.SchemaresolveSchema(io.swagger.v3.oas.models.OpenAPI openAPI, io.micronaut.inject.ast.Element definingElement, io.micronaut.inject.ast.ClassElement type, io.micronaut.inject.visitor.VisitorContext context, java.util.List<io.micronaut.http.MediaType> mediaTypes, JavadocDescription fieldJavadoc, JavadocDescription classJavadoc)Resolves the schema for the given type element.protected java.util.Map<java.lang.CharSequence,java.lang.Object>toValueMap(java.util.Map<java.lang.CharSequence,java.lang.Object> values, io.micronaut.inject.visitor.VisitorContext context)Convert the values to a map.protected abstract java.util.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.voidvisitClass(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context)Executed when a class is encountered that matches the generic class.voidvisitMethod(io.micronaut.inject.ast.MethodElement element, io.micronaut.inject.visitor.VisitorContext context)Executed when a method is encountered that matches the generic element.
-
-
-
Field Detail
-
COMPONENTS_CALLBACKS_PREFIX
public static final java.lang.String COMPONENTS_CALLBACKS_PREFIX
- See Also:
- Constant Field Values
-
CONTEXT_CHILD_PATH
protected static final java.lang.String CONTEXT_CHILD_PATH
- See Also:
- Constant Field Values
-
CONTEXT_CHILD_OP_ID_PREFIX
protected static final java.lang.String CONTEXT_CHILD_OP_ID_PREFIX
- See Also:
- Constant Field Values
-
CONTEXT_CHILD_OP_ID_SUFFIX
protected static final java.lang.String CONTEXT_CHILD_OP_ID_SUFFIX
- See Also:
- Constant Field Values
-
CONTEXT_CHILD_OP_ID_SUFFIX_ADD_ALWAYS
protected static final java.lang.String CONTEXT_CHILD_OP_ID_SUFFIX_ADD_ALWAYS
- See Also:
- Constant Field Values
-
IS_PROCESS_PARENT_CLASS
protected static final java.lang.String IS_PROCESS_PARENT_CLASS
- See Also:
- Constant Field Values
-
classTags
protected java.util.List<io.swagger.v3.oas.models.tags.Tag> classTags
-
classExternalDocs
protected io.swagger.v3.oas.models.ExternalDocumentation classExternalDocs
-
-
Method Detail
-
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 elementcontext- The visitor context
-
methodSecurityRequirements
protected abstract java.util.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 java.util.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 java.util.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 java.util.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 java.util.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 java.util.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 java.lang.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 elementcontext- The visitor context
-
toValueMap
protected java.util.Map<java.lang.CharSequence,java.lang.Object> toValueMap(java.util.Map<java.lang.CharSequence,java.lang.Object> values, io.micronaut.inject.visitor.VisitorContext context)Convert the values to a map.- Parameters:
values- The valuescontext- The visitor context- Returns:
- The map
-
resolveSchema
@Nullable protected 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, java.util.List<io.micronaut.http.MediaType> mediaTypes)Resolves the schema for the given type element.- Parameters:
definingElement- The defining elementtype- The type elementcontext- The contextmediaTypes- An optional media type- Returns:
- The schema or null if it cannot be resolved
-
resolveSchema
@Nullable protected 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, java.util.List<io.micronaut.http.MediaType> mediaTypes, 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 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.Element 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.- Parameters:
context- The visitor contextelement- The elementelementType- The element typeclassElement- The class elementparentSchema- The parent schemapropertySchema- The property schema
-
isElementNotNullable
protected boolean isElementNotNullable(io.micronaut.inject.ast.Element element, @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.Element 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 contextelement- The elementelementType- The element typeschemaToBind- 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 contextelement- The elementschemaToBind- The schema to bindschemaAnn- 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 contextelement- The elementschemaToBind- The schema to bindschemaAnn- 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 io.micronaut.inject.ast.Element type, java.util.List<io.micronaut.http.MediaType> mediaTypes) throws com.fasterxml.jackson.core.JsonProcessingExceptionReads schema.- Parameters:
schemaValue- annotation valueopenAPI- The OpenApicontext- The VisitorContexttype- The elementmediaTypes- 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)ProcessesSecuritySchemeannotations.- Parameters:
element- The elementcontext- The visitor context
-
processOpenApiAnnotation
protected <T,A extends java.lang.annotation.Annotation> java.util.List<T> processOpenApiAnnotation(io.micronaut.inject.ast.Element element, io.micronaut.inject.visitor.VisitorContext context, java.lang.Class<A> annotationType, java.lang.Class<T> modelType, java.util.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.
-
-