Package io.micronaut.openapi.visitor
Class ConvertUtils
java.lang.Object
io.micronaut.openapi.visitor.ConvertUtils
Convert utilities methods.
- Since:
- 4.4.1
-
Field Summary
Modifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptioncheckEnumJsonValueType
(io.micronaut.inject.visitor.VisitorContext context, @NonNull io.micronaut.inject.ast.EnumElement type, @Nullable String schemaType, @Nullable String schemaFormat) Detect openapi type and format for enums.getTypeAndFormatByClass
(String className, boolean isArray) Detect openapi type and format by java class name.static io.swagger.v3.oas.models.security.SecurityRequirement
mapToSecurityRequirement
(io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.security.SecurityRequirement> r) Maps annotation value toSecurityRequirement
.static Object
normalizeValue
(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context) static Object
normalizeValue
(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context, boolean isMicronautFormat) static Object
parseByTypeAndFormat
(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context, boolean isMicronautFormat) Parse value by openapi type and format.parseJsonString
(Object object) resolveExtensions
(com.fasterxml.jackson.databind.JsonNode jn) static void
setDefaultValueObject
(io.swagger.v3.oas.models.media.Schema<?> schema, String defaultValue, @Nullable io.micronaut.inject.ast.Element element, @Nullable String schemaType, @Nullable String schemaFormat, boolean isMicronautFormat, io.micronaut.inject.visitor.VisitorContext context) static com.fasterxml.jackson.databind.JsonNode
toJson
(Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context) Convert the given map to a JSON node.static <T> T
toValue
(Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context, Class<T> type) Convert the given Map to a JSON node and then to the specified type.static Map<CharSequence,
Object> toValueMap
(Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context) static <T> T
treeToValue
(com.fasterxml.jackson.databind.JsonNode jn, Class<T> clazz, io.micronaut.inject.visitor.VisitorContext context) Converts Json node into a class' instance or throws 'com.fasterxml.jackson.core.JsonProcessingException', adds extensions if present.
-
Field Details
-
MAP_TYPE_REFERENCE
-
-
Method Details
-
toValue
public static <T> T toValue(Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context, Class<T> type) Convert the given Map to a JSON node and then to the specified type.- Type Parameters:
T
- The output class type- Parameters:
values
- The valuescontext
- The visitor contexttype
- The class- Returns:
- The converted instance
-
toJson
public static com.fasterxml.jackson.databind.JsonNode toJson(Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context) Convert the given map to a JSON node.- Parameters:
values
- The valuescontext
- The visitor context- Returns:
- The node
-
toValueMap
public static Map<CharSequence,Object> toValueMap(Map<CharSequence, Object> values, io.micronaut.inject.visitor.VisitorContext context) -
parseJsonString
-
treeToValue
public static <T> T treeToValue(com.fasterxml.jackson.databind.JsonNode jn, Class<T> clazz, io.micronaut.inject.visitor.VisitorContext context) throws com.fasterxml.jackson.core.JsonProcessingException Converts Json node into a class' instance or throws 'com.fasterxml.jackson.core.JsonProcessingException', adds extensions if present.- Type Parameters:
T
- The output class type- Parameters:
jn
- The json nodeclazz
- The output class instancecontext
- visitor context- Returns:
- The converted instance
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- if error
-
normalizeValue
public static Object normalizeValue(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
normalizeValue
public static Object normalizeValue(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context, boolean isMicronautFormat) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
resolveExtensions
-
mapToSecurityRequirement
public static io.swagger.v3.oas.models.security.SecurityRequirement mapToSecurityRequirement(io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.security.SecurityRequirement> r) Maps annotation value toSecurityRequirement
. Correct format is: custom_name: - custom_scope1 - custom_scope2- Parameters:
r
- The value ofSecurityRequirement
.- Returns:
- converted object.
-
setDefaultValueObject
public static void setDefaultValueObject(io.swagger.v3.oas.models.media.Schema<?> schema, String defaultValue, @Nullable @Nullable io.micronaut.inject.ast.Element element, @Nullable @Nullable String schemaType, @Nullable @Nullable String schemaFormat, boolean isMicronautFormat, io.micronaut.inject.visitor.VisitorContext context) -
checkEnumJsonValueType
@NonNull public static @NonNull Pair<String,String> checkEnumJsonValueType(io.micronaut.inject.visitor.VisitorContext context, @NonNull @NonNull io.micronaut.inject.ast.EnumElement type, @Nullable @Nullable String schemaType, @Nullable @Nullable String schemaFormat) Detect openapi type and format for enums.- Parameters:
context
- visitor contexttype
- enum elementschemaType
- type from swagger Schema annotationschemaFormat
- format from swagger Schema annotation- Returns:
- pair with openapi type and format
-
getTypeAndFormatByClass
Detect openapi type and format by java class name.- Parameters:
className
- java class nameisArray
- is it array- Returns:
- pair with openapi type and format
-
parseByTypeAndFormat
public static Object parseByTypeAndFormat(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context, boolean isMicronautFormat) Parse value by openapi type and format.- Parameters:
valueStr
- string value for parsetype
- openapi typeformat
- openapi valuecontext
- visitor contextisMicronautFormat
- is it micronaut format for arrays- Returns:
- parsed value
-