swagger-api / swagger-api/swagger-core

Make ModelConverterContext swappable

Open
#4,718 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

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));

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading ModelConverters and ModelConverterContextImpl, focusing on how the context is instantiated and where ReferenceTypeUtils.unwrapReference(type) is called. Trace the existing ModelConverter extension points and determine how a settable context factory could preserve the Optional information; the work is done when callers can supply a custom context through ModelConverters.getInstance().

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.