swagger-api / swagger-api/swagger-core
Make ModelConverterContext swappable
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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