OpenAPITools / OpenAPITools/openapi-generator

Adapter of type listed in anyOf isn't resolved

Open
#13,687 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

getDelegateAdapter goes through the list of adapters, but skips mentioned adapter (in this case this adapter). And this and TypeToken.get({{.}}.class refers to different model types.

https://github.com/OpenAPITools/openapi-generator/blob/69f79fb7892948590a9ffe46754c47ddd2634be1/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache#L47

This leads to getDelegateAdapter tries to find this adapter first and only after that it starts searching adapter for TypeToken.get({{.}}.class by proceeding iterating through adapters list. But if TypeToken.get({{.}}.class adapter is listed before this adapter - custom type adapter for TypeToken.get({{.}}.class is never found... It makes clients randomly break depending on chosen names for model (as they are sorted).

Not sure is my explanation clear, TL;DR; probably getDelegateAdapter should be replaced by getAdapter here?

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 with modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache at line 47 and inspect how getDelegateAdapter handles the adapter list for anyOf models. Reproduce the failure with an adapter listed before the current adapter, then verify that generated clients consistently find the TypeToken adapter regardless of model-name ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.