Interface OpenApiMapperProvider

All Known Implementing Classes:
JacksonOpenApiMapperProvider

public interface OpenApiMapperProvider
Service provider that supplies the 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 Details

    • getName

      String getName()
      Returns:
      The provider name, used to select it with "micronaut.openapi.mapper", for example jackson or serde.
    • getMapper

      io.micronaut.json.JsonMapper getMapper(OpenApiMapperType type, OpenApiVersion version)
      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 are JsonNode instances.

      Parameters:
      type - The mapper type
      version - 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 than valueToUpdate: with Jackson, a type whose deserializer cannot merge into an existing instance (such as Schema) is read into a new one, and the visitor must continue with that. The default implementation updates the value in place with updateValueFromTree and returns it, which is what a provider whose deserializers always merge should do.

      Type Parameters:
      T - The value type
      Parameters:
      mapper - A mapper obtained from getMapper(OpenApiMapperType, OpenApiVersion)
      valueToUpdate - The value to update
      tree - The tree to read
      Returns:
      The updated value
      Throws:
      IOException - if the tree cannot be read
    • findNamingStrategy

      default Optional<UnaryOperator<String>> findNamingStrategy(String name)
      Resolves one of the well-known property naming strategies, such as SNAKE_CASE or KEBAB_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 @JsonNaming annotation.
      Parameters:
      className - The fully qualified class name of the strategy
      classLoader - 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