Package io.micronaut.openapi.visitor
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<Object,
Object>
public class OpenApiApplicationVisitor
extends Object
implements io.micronaut.inject.visitor.TypeElementVisitor<Object,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 inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
-
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.static String
expandProperties
(String s, List<Pair<String, String>> properties, io.micronaut.inject.visitor.VisitorContext context) void
finish
(io.micronaut.inject.visitor.VisitorContext context) int
getOrder()
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 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.static String
replacePlaceholders
(String value, io.micronaut.inject.visitor.VisitorContext context) 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, @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.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, getVisitorKind, visitConstructor, visitEnumConstant, visitField, visitMethod
-
Constructor Details
-
OpenApiApplicationVisitor
public OpenApiApplicationVisitor()
-
-
Method Details
-
start
public void start(io.micronaut.inject.visitor.VisitorContext context) -
getSupportedOptions
-
visitClass
public void visitClass(io.micronaut.inject.ast.ClassElement element, 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
-
replacePlaceholders
-
finish
public void finish(io.micronaut.inject.visitor.VisitorContext context) -
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceio.micronaut.core.order.Ordered
-
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.
-