OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][WEBCLIENT] First referenced object in oneOf doesn't have its properties added to the composed class

Open
#20,931 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (actual)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

We're expecting that all properties of objects referenced in a oneOf should be added to the generated composed class when using the webclient library. Instead the first object referenced will never have its properties added to the composed class.

Running Verbose logging on the 7.14.0-SNAPSHOT version indicates that the properties of the first object in a oneOf are in the allVars, optionalVars, readWriteVars, and nonNullableVars. But not the vars property in the logged JSON.

openapi-generator version

7.11.0 through 7.14.0-SNAPSHOT of the Maven plugin, haven't tried older versions yet to determine if its a regression.
7.14.0-SNAPSHOT with a locally built version of the cli version.

OpenAPI declaration file content or url

https://gist.githubusercontent.com/Yajirushi12/e681738f2bd9a6aa26af04886c78770d/raw/0d6600dda04553a6d2d09eaa789da01e0f93d9a0/test.yml

Generation Details

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i https://gist.githubusercontent.com/Yajirushi12/e681738f2bd9a6aa26af04886c78770d/raw/0d6600dda04553a6d2d09eaa789da01e0f93d9a0/test.yml -g java -o samples/client/brokenOneOf --library webclient

the default library seems to work properly for Java, at least in that it doesn't compose the properties into a single class so its not susceptible to this bug

Steps to reproduce

Run the above generation. Modifying the order of the references in the oneOf in either the schemas object or the response body definition will result in the object that's first first in the list never having its property added to the composed class

Related issues/PRs

I didn't see any that looked related to not generating in this way, though I might be wrong.

Suggest a fix

Working on getting approval to use employer time to develop a fix for this, not sure exactly where the problem is in the generation process though it seems like it might be originating from a problem related to copying properties and dealing with the parent of the object in the DefaultCodegen file somewhere.

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 running the Java webclient generation command against the linked OpenAPI declaration and compare the generated composed class when the oneOf reference order changes. Trace the model-property handling through DefaultCodegen and the CLI generation path; done means every referenced object's properties, including the first reference, appears in the composed class and a regression test covers the ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.