Class PropertyNamingStrategyConverter

java.lang.Object
org.springdoc.core.converters.PropertyNamingStrategyConverter
All Implemented Interfaces:
io.swagger.v3.core.converter.ModelConverter

public class PropertyNamingStrategyConverter extends Object implements io.swagger.v3.core.converter.ModelConverter
Repairs schema property names that swagger-core leaves in their raw (untranslated) form when a Jackson PropertyNamingStrategy (for example SNAKE_CASE) is in effect.

swagger-core's ModelResolver carries a long-standing workaround (swagger-core#415) that overwrites the Jackson-translated property name with the raw member name whenever that member name starts with get/is followed by a lower-case character. For Java records the accessor is named exactly like the component (e.g. issuanceDate()), so a component such as issuanceDate is clobbered back to camelCase while sibling properties like familyName convert correctly. This converter restores the translated name.

The mapper used by the active ModelResolver is consulted so that the fix is self-consistent: it only renames a property when Jackson actually maps its internal name to a different external name and swagger-core emitted the internal name.

See: springdoc-openapi#3293
Author:
bnasslahsen
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates a new Property naming strategy converter.
  • Method Summary

    Modifier and Type
    Method
    Description
    io.swagger.v3.oas.models.media.Schema
    resolve(io.swagger.v3.core.converter.AnnotatedType type, io.swagger.v3.core.converter.ModelConverterContext context, Iterator<io.swagger.v3.core.converter.ModelConverter> chain)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.swagger.v3.core.converter.ModelConverter

    isOpenapi31
  • Constructor Details

    • PropertyNamingStrategyConverter

      public PropertyNamingStrategyConverter(ObjectMapperProvider springDocObjectMapper)
      Instantiates a new Property naming strategy converter.
      Parameters:
      springDocObjectMapper - the spring doc object mapper
  • Method Details

    • resolve

      public io.swagger.v3.oas.models.media.Schema resolve(io.swagger.v3.core.converter.AnnotatedType type, io.swagger.v3.core.converter.ModelConverterContext context, Iterator<io.swagger.v3.core.converter.ModelConverter> chain)
      Specified by:
      resolve in interface io.swagger.v3.core.converter.ModelConverter