Interface OpenApiMapperProvider
- All Known Implementing Classes:
JacksonOpenApiMapperProvider
JsonMapper implementations used by the OpenAPI visitor
to read, write and convert OpenAPI model objects.
Implementations are discovered with ServiceLoader. When more than one provider is
available, the one to use is selected with the "micronaut.openapi.mapper" property.
- Since:
- 8.0.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault Optional<UnaryOperator<String>> findNamingStrategy(String name) Resolves one of the well-known property naming strategies, such asSNAKE_CASEorKEBAB_CASE.default Optional<UnaryOperator<String>> findNamingStrategyClass(String className, ClassLoader classLoader) Resolves a naming strategy declared by class name, for example from a@JsonNamingannotation.io.micronaut.json.JsonMappergetMapper(OpenApiMapperType type, OpenApiVersion version) Returns the mapper for the given type and OpenAPI version.getName()default <T> TupdateValue(io.micronaut.json.JsonMapper mapper, T valueToUpdate, io.micronaut.json.tree.JsonNode tree) Updates an existing value from a tree and returns the result.
-
Method Details
-
getName
String getName()- Returns:
- The provider name, used to select it with "micronaut.openapi.mapper", for example
jacksonorserde.
-
getMapper
Returns the mapper for the given type and OpenAPI version.The returned mapper must serialize the OpenAPI model classes (swagger-models) according to the OpenAPI specification: extensions written as top-level
x-properties, enums written by their specification value and so on. Trees exchanged with the visitor areJsonNodeinstances.- Parameters:
type- The mapper typeversion- The OpenAPI version of the document- Returns:
- The mapper
-
updateValue
default <T> T updateValue(io.micronaut.json.JsonMapper mapper, T valueToUpdate, io.micronaut.json.tree.JsonNode tree) throws IOException Updates an existing value from a tree and returns the result.The visitor uses this instead of
JsonMapper.updateValueFromTree(Object, JsonNode)because the result may be a different instance thanvalueToUpdate: with Jackson, a type whose deserializer cannot merge into an existing instance (such asSchema) is read into a new one, and the visitor must continue with that. The default implementation updates the value in place withupdateValueFromTreeand returns it, which is what a provider whose deserializers always merge should do.- Type Parameters:
T- The value type- Parameters:
mapper- A mapper obtained fromgetMapper(OpenApiMapperType, OpenApiVersion)valueToUpdate- The value to updatetree- The tree to read- Returns:
- The updated value
- Throws:
IOException- if the tree cannot be read
-
findNamingStrategy
Resolves one of the well-known property naming strategies, such asSNAKE_CASEorKEBAB_CASE.- Parameters:
name- The upper case strategy name- Returns:
- The function translating a property name, or empty if the strategy is unknown
-
findNamingStrategyClass
default Optional<UnaryOperator<String>> findNamingStrategyClass(String className, ClassLoader classLoader) Resolves a naming strategy declared by class name, for example from a@JsonNamingannotation.- Parameters:
className- The fully qualified class name of the strategyclassLoader- The class loader to load it with- Returns:
- The function translating a property name, or empty if the provider cannot apply that strategy, in which case the visitor warns and keeps the property names unchanged
-