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<io.swagger.v3.oas.annotations.OpenAPIDefinition,
Object>
@SupportedOptions({"micronaut.openapi.enabled","micronaut.openapi.server.context.path","micronaut.openapi.property.naming.strategy","micronaut.openapi.views.spec","micronaut.openapi.filename","micronaut.openapi.json.format","micronaut.openapi.environments","micronaut.environment.enabled","micronaut.openapi.field.visibility.level","micronaut.openapi.config.file.locations","micronaut.openapi.target.file","micronaut.openapi.views.dest.dir","micronaut.openapi.additional.files","micronaut.openapi.config.file","micronaut.openapi.security.enabled","micronaut.openapi.versioning.enabled"})
public class OpenApiApplicationVisitor
extends Object
implements io.micronaut.inject.visitor.TypeElementVisitor<io.swagger.v3.oas.annotations.OpenAPIDefinition,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
FieldsModifier and TypeFieldDescriptionstatic final String
Config file locations.static final String
Is this property true, properties wll be loaded in the standard way from application.yml.static final String
Final calculated openapi filenames.static final String
System property that specifies the location of additional swagger YAML and JSON files to read from.static final String
System property that enables setting the open api config file.static final String
System property for server context path.static final String
System property that enables or disables open api annotation processing.static final String
The name of the entry for Endpoint class tags in the context.static final String
The name of the entry for Endpoint security requirements in the context.static final String
The name of the entry for Endpoint servers in the context.static final String
Active micronaut environments which will be used for @Requires annotations.static final String
Prefix for expandable properties.static final String
System property that specifies the schema classes fields visibility level.static final String
The name of the result swagger file.static final String
Is this property true, output file format will be JSON, otherwise YAML.static final String
System property for naming strategy.static final String
System property that specifies the default security schema name, if it's not specified by annotation SecurityScheme.static final String
Is this property true, micronaut-openapi will process micronaut-security properties and annotations to construct openapi security schema.static final String
System property that enables setting the target file to write to.static final String
Is this property true, micronaut-openapi will process micronaut-router versioning prpoerties and annotations.static final String
System property that specifies the path where the generated UI elements will be located.static final String
System property for views specification.static final String
Loaded micronaut-http server context path property.static final String
Default openapi config file.Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.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.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) Binds the schema for the given element.static String
expandProperties
(String s, List<Map.Entry<String, String>> properties, io.micronaut.inject.visitor.VisitorContext context) void
finish
(io.micronaut.inject.visitor.VisitorContext context) getActiveEnvs
(io.micronaut.inject.visitor.VisitorContext context) static boolean
getBooleanProperty
(String property, boolean defaultValue, io.micronaut.inject.visitor.VisitorContext context) static String
getConfigurationProperty
(String key, io.micronaut.inject.visitor.VisitorContext context) static io.micronaut.inject.ast.ClassElement
getCustomSchema
(String className, Map<String, io.micronaut.inject.ast.ClassElement> typeArgs, io.micronaut.inject.visitor.VisitorContext context) static @Nullable io.micronaut.context.env.Environment
getEnv
(io.micronaut.inject.visitor.VisitorContext context) getExpandableProperties
(io.micronaut.inject.visitor.VisitorContext context) static GroupProperties
getGroupProperties
(String groupName, io.micronaut.inject.visitor.VisitorContext context) static Map<String,
GroupProperties> getGroupsPropertiesMap
(io.micronaut.inject.visitor.VisitorContext context) getListStringsProperty
(String property, List<String> defaultValue, io.micronaut.inject.visitor.VisitorContext context) int
getOrder()
static RouterVersioningProperties
getRouterVersioningProperties
(io.micronaut.inject.visitor.VisitorContext context) static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.SchemaDecorator
getSchemaDecoration
(String packageName, io.micronaut.inject.visitor.VisitorContext context) static SecurityProperties
getSecurityProperties
(io.micronaut.inject.visitor.VisitorContext context) protected boolean
isElementNotNullable
(io.micronaut.inject.ast.Element element, @Nullable io.micronaut.inject.ast.Element classElement) static boolean
isOpenApiEnabled
(io.micronaut.inject.visitor.VisitorContext context) protected void
processJavaxValidationAnnotations
(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.Element 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.static Properties
readOpenApiConfigFile
(io.micronaut.inject.visitor.VisitorContext context) 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, List<io.micronaut.http.MediaType> mediaTypes) Reads schema.static String
replacePlaceholders
(String value, io.micronaut.inject.visitor.VisitorContext context) static Path
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) 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, JavadocDescription fieldJavadoc, JavadocDescription classJavadoc) Resolves the schema for the given type element.protected Map<CharSequence,
Object> toValueMap
(Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context) 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, getSupportedOptions, getVisitorKind, start, visitConstructor, visitEnumConstant, visitField, visitMethod
-
Field Details
-
MICRONAUT_OPENAPI_ENABLED
System property that enables or disables open api annotation processing.
Default: true- See Also:
-
MICRONAUT_OPENAPI_CONFIG_FILE
System property that enables setting the open api config file.- See Also:
-
MICRONAUT_OPENAPI_EXPAND_PREFIX
Prefix for expandable properties.- See Also:
-
MICRONAUT_OPENAPI_CONTEXT_SERVER_PATH
System property for server context path.- See Also:
-
MICRONAUT_OPENAPI_PROPERTY_NAMING_STRATEGY
System property for naming strategy. One jackson PropertyNamingStrategy.- See Also:
-
MICRONAUT_OPENAPI_VIEWS_SPEC
System property for views specification.- See Also:
-
MICRONAUT_OPENAPI_TARGET_FILE
System property that enables setting the target file to write to.- See Also:
-
MICRONAUT_OPENAPI_VIEWS_DEST_DIR
System property that specifies the path where the generated UI elements will be located.- See Also:
-
MICRONAUT_OPENAPI_ADDITIONAL_FILES
System property that specifies the location of additional swagger YAML and JSON files to read from.- See Also:
-
MICRONAUT_OPENAPI_SECURITY_DEFAULT_SCHEMA_NAME
System property that specifies the default security schema name, if it's not specified by annotation SecurityScheme.- See Also:
-
MICRONAUT_OPENAPI_FIELD_VISIBILITY_LEVEL
System property that specifies the schema classes fields visibility level. By default, only public fields visibile.Available values:
PRIVATE PACKAGE PROTECTED PUBLIC- See Also:
-
OPENAPI_CONFIG_FILE
Default openapi config file.- See Also:
-
MICRONAUT_OPENAPI_ENDPOINT_CLASS_TAGS
The name of the entry for Endpoint class tags in the context.- See Also:
-
MICRONAUT_OPENAPI_ENDPOINT_SERVERS
The name of the entry for Endpoint servers in the context.- See Also:
-
MICRONAUT_OPENAPI_ENDPOINT_SECURITY_REQUIREMENTS
The name of the entry for Endpoint security requirements in the context.- See Also:
-
MICRONAUT_OPENAPI_JSON_FORMAT
Is this property true, output file format will be JSON, otherwise YAML.- See Also:
-
MICRONAUT_OPENAPI_FILENAME
The name of the result swagger file.Default filename is <info.title>-<info.version>.yml. If info annotation not set, filename will be swagger.yml.
- See Also:
-
MICRONAUT_OPENAPI_ENVIRONMENTS
Active micronaut environments which will be used for @Requires annotations.- See Also:
-
MICRONAUT_ENVIRONMENT_ENABLED
Is this property true, properties wll be loaded in the standard way from application.yml. Also, environments from "micronaut.openapi.environments" property will set as additional environments, if you want to set specific environment name for openAPI generator.
Default value is "true".- See Also:
-
MICRONAUT_OPENAPI_SECURITY_ENABLED
Is this property true, micronaut-openapi will process micronaut-security properties and annotations to construct openapi security schema.
Default value is "true".- See Also:
-
MICRONAUT_OPENAPI_VERSIONING_ENABLED
Is this property true, micronaut-openapi will process micronaut-router versioning prpoerties and annotations.
Default value is "true".- See Also:
-
MICRONAUT_CONFIG_FILE_LOCATIONS
Config file locations. By default, micronaut-openapi search config in standard path: <project_path>/src/main/resources/You can set your custom paths separated by ','. To set absolute paths use prefix 'file:', classpath paths use prefix 'classpath:' or use prefix 'project:' to set paths from project directory.
- See Also:
-
MICRONAUT_SERVER_CONTEXT_PATH
Loaded micronaut-http server context path property.- See Also:
-
MICRONAUT_INTERNAL_OPENAPI_FILENAMES
Final calculated openapi filenames.- See Also:
-
-
Constructor Details
-
OpenApiApplicationVisitor
public OpenApiApplicationVisitor()
-
-
Method Details
-
isOpenApiEnabled
public static boolean isOpenApiEnabled(io.micronaut.inject.visitor.VisitorContext context) -
visitClass
public void visitClass(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.visitor.VisitorContext context) - Specified by:
visitClass
in interfaceio.micronaut.inject.visitor.TypeElementVisitor<io.swagger.v3.oas.annotations.OpenAPIDefinition,
Object>
-
getSchemaDecoration
public static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.SchemaDecorator getSchemaDecoration(String packageName, io.micronaut.inject.visitor.VisitorContext context) -
getCustomSchema
-
getConfigurationProperty
-
getSecurityProperties
public static SecurityProperties getSecurityProperties(io.micronaut.inject.visitor.VisitorContext context) -
getRouterVersioningProperties
public static RouterVersioningProperties getRouterVersioningProperties(io.micronaut.inject.visitor.VisitorContext context) -
getGroupProperties
public static GroupProperties getGroupProperties(String groupName, io.micronaut.inject.visitor.VisitorContext context) -
getGroupsPropertiesMap
public static Map<String,GroupProperties> getGroupsPropertiesMap(io.micronaut.inject.visitor.VisitorContext context) -
getBooleanProperty
public static boolean getBooleanProperty(String property, boolean defaultValue, io.micronaut.inject.visitor.VisitorContext context) -
getListStringsProperty
-
getEnv
@Nullable public static @Nullable io.micronaut.context.env.Environment getEnv(io.micronaut.inject.visitor.VisitorContext context) -
getActiveEnvs
-
resolve
-
readOpenApiConfigFile
-
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
-
getExpandableProperties
-
finish
public void finish(io.micronaut.inject.visitor.VisitorContext context) - Specified by:
finish
in interfaceio.micronaut.inject.visitor.TypeElementVisitor<io.swagger.v3.oas.annotations.OpenAPIDefinition,
Object>
-
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) Convert the values to a map.- Parameters:
values
- The valuescontext
- The visitor context- 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) 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 @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, 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.TypedElement element, io.micronaut.inject.ast.ClassElement elementType, @Nullable @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 @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.TypedElement 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 @Nullable io.micronaut.inject.ast.Element type, Map<String, io.micronaut.inject.ast.ClassElement> typeArgs, List<io.micronaut.http.MediaType> mediaTypes) throws com.fasterxml.jackson.core.JsonProcessingExceptionReads schema.- Parameters:
schemaValue
- annotation valueopenAPI
- The OpenApicontext
- The VisitorContexttype
- type elementtypeArgs
- type argumentsmediaTypes
- 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) 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.
-