swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Make ModelConverterContext swappable

Open nikita2206 opened this issue 1 year ago • 0 comments

Currently, the ModelConverterContext is instantiated statically from within the ModelConverters class. The context happens to contain some logic that seems to be hard (or impossible) to modify in any other way, other than by extending the ModelConverterContextImpl and overriding the resolve() method.

Problem

Namely, we would like to add clever handling of Optional<...> properties of objects, such that the OAS component that contains such property would specify nullable = true for it. However, because the ModelConverterContextImpl has the following line, we lose the information about Optional wrapper very early on, which makes it impossible for us to use the existing ModelConverter extension points to implement this:

AnnotatedType aType = ReferenceTypeUtils.unwrapReference(type);

Solution

If you don't see any immediate issues with this, I'd like to create a PR adding a ModelConverterContextFactory factory which will be settable on a ModelConverters singleton object, like the following:

ModelConverters.getInstance()
  .setContextFactory(converters -> new CustomContext(converters));

nikita2206 avatar Aug 14 '24 14:08 nikita2206