Package io.micronaut.openapi.visitor
Class SchemaDefinitionUtils
java.lang.Object
io.micronaut.openapi.visitor.SchemaDefinitionUtils
Methods to construct OpenPI schema definition.
- Since:
- 6.12.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static 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.static 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, boolean withProcessDeprecated) Binds the schema for the given element.static void
clean()
Cleanup context.static String
computeDefaultSchemaName
(String defaultSchemaName, io.micronaut.inject.ast.Element definingElement, io.micronaut.inject.ast.Element type, Map<String, io.micronaut.inject.ast.ClassElement> typeArgs, io.micronaut.inject.visitor.VisitorContext context, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) getEnumValues
(io.micronaut.inject.ast.EnumElement type, String schemaType, String schemaFormat, io.micronaut.inject.visitor.VisitorContext context) static @Nullable io.swagger.v3.oas.models.media.Schema<?>
getSchemaDefinition
(io.swagger.v3.oas.models.OpenAPI openAPI, io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.ClassElement 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) static 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.static 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 Map<CharSequence,
Object> resolveArraySchemaAnnotationValues
(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.core.annotation.AnnotationValue<?> av, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) static @Nullable io.swagger.v3.oas.models.media.Schema<?>
resolveSchema
(@Nullable io.micronaut.inject.ast.Element definingElement, @Nullable 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.static @Nullable io.swagger.v3.oas.models.media.Schema<?>
resolveSchema
(io.swagger.v3.oas.models.OpenAPI openApi, @Nullable io.micronaut.inject.ast.Element definingElement, @Nullable 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, @Nullable io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.Schema> schemaAnnValue) Resolves the schema for the given type element.static com.fasterxml.jackson.databind.JsonNode
toJson
(String annotationName, Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) Convert the given map to a JSON node.static com.fasterxml.jackson.databind.JsonNode
toJson
(Map<CharSequence, Object> values) static <T> T
toValue
(String annotationName, Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context, Class<T> type, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) Convert the given Map to a JSON node and then to the specified type.static Map<CharSequence,
Object> toValueMap
(String annotationName, Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context, @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) Convert the values to a map.
-
Method Details
-
clean
public static void clean()Cleanup context. -
readSchema
public static 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 argumentsdefiningElement
- defining elementmediaTypes
- The media types of schemajsonViewClass
- Class from JsonView annotation- Returns:
- New schema instance
-
getSchemaDefinition
@Nullable public static @Nullable io.swagger.v3.oas.models.media.Schema<?> getSchemaDefinition(io.swagger.v3.oas.models.OpenAPI openAPI, io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.ClassElement 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) -
computeDefaultSchemaName
public static String computeDefaultSchemaName(String defaultSchemaName, io.micronaut.inject.ast.Element definingElement, io.micronaut.inject.ast.Element type, Map<String, io.micronaut.inject.ast.ClassElement> typeArgs, io.micronaut.inject.visitor.VisitorContext context, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) -
getEnumValues
-
resolveSchema
@Nullable public static @Nullable io.swagger.v3.oas.models.media.Schema<?> resolveSchema(@Nullable @Nullable io.micronaut.inject.ast.Element definingElement, @Nullable @Nullable 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 public static @Nullable io.swagger.v3.oas.models.media.Schema<?> resolveSchema(io.swagger.v3.oas.models.OpenAPI openApi, @Nullable @Nullable io.micronaut.inject.ast.Element definingElement, @Nullable @Nullable 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, @Nullable @Nullable io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.media.Schema> schemaAnnValue) 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 annotationschemaAnnValue
- schema annotation value- Returns:
- The schema or null if it cannot be resolved
-
bindSchemaForElement
public static 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, boolean withProcessDeprecated) Binds the schema for the given element.- Parameters:
context
- The contextelement
- The elementelementType
- The element typeschemaToBind
- The schema to bindjsonViewClass
- Class from JsonView annotationwithProcessDeprecated
- Is need to process deprecates annotation- Returns:
- The bound schema
-
bindArraySchemaAnnotationValue
public static 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
-
toValueMap
public static Map<CharSequence,Object> toValueMap(String annotationName, 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:
annotationName
- annotation namevalues
- The valuescontext
- The visitor contextjsonViewClass
- Class from JsonView annotation- Returns:
- The map
-
resolveArraySchemaAnnotationValues
public static Map<CharSequence,Object> resolveArraySchemaAnnotationValues(io.micronaut.inject.visitor.VisitorContext context, io.micronaut.core.annotation.AnnotationValue<?> av, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) -
bindSchemaAnnotationValue
public static 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
-
toValue
public static <T> T toValue(String annotationName, Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context, Class<T> type, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) Convert the given Map to a JSON node and then to the specified type.- Type Parameters:
T
- The output class type- Parameters:
annotationName
- annotation namevalues
- The valuescontext
- The visitor contexttype
- The classjsonViewClass
- Class from JsonView annotation- Returns:
- The converted instance
-
toJson
public static com.fasterxml.jackson.databind.JsonNode toJson(String annotationName, Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context, @Nullable @Nullable io.micronaut.inject.ast.ClassElement jsonViewClass) Convert the given map to a JSON node.- Parameters:
annotationName
- annotation namevalues
- The valuescontext
- The visitor contextjsonViewClass
- Class from JsonView annotation- Returns:
- The node
-
toJson
-
processSchemaProperty
public static 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
-
getSchemaNameToClassNameMap
-