Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [JAVA] OneOf polymorphism code wasn't generated correctly #7414

Open
5 of 6 tasks
swrnm opened this issue Sep 14, 2020 · 4 comments
Open
5 of 6 tasks

[BUG] [JAVA] OneOf polymorphism code wasn't generated correctly #7414

swrnm opened this issue Sep 14, 2020 · 4 comments

Comments

@swrnm
Copy link

swrnm commented Sep 14, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

I used open-api generator for creating Java client. In one of the endpoint, I used oneOf which must follow polymorphism property to generate codes. It generated a OneOfBody empty interface and two classes ObjectA and ObjectB which implements OneOfBody. So ideally the endpoint's method should expect the OneOfBody parameter but it expects a Body parameter which is an empty class implementing OneOfBody. So this way, passing ObjectA OR ObjectB seems impossible.

openapi-generator version

4.3.1

OpenAPI declaration file content or url

https://gist.github.com/swarnim-sib/94a6ad4b31f63d1c6ad45b8de5961333

Generation Details

openapi-generator generate -i ~/Documents/Project/api/client/file.yml -g java -o ~/JavaClient

Steps to reproduce
  • Take any yml file, for example Swagger Petstore example and add configurations mentioned here (related to oneOf)
  • Run openapi-generator script mentioned above to generate Java client
  • Check files, OneOfBody.java, possibly Body.java, and API class mentioned in above endpoint
Related issues/PRs
Suggest a fix
  • If we could tell the API classes to accept OneOfBody parameters instead of Body parameters then ObjectA and ObjectB could be type casted to OneOfBody and the API class would process the passed parameters OR
  • If we could define a method in OneOfBody interface which could be used for typecasting between ObjectA/ObjectB and Body then too the API method could accept the parameter and would process it
@auto-labeler
Copy link

auto-labeler bot commented Sep 14, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Sep 15, 2020

Please try the jersey2 library of the java client generator in the latest master as it has better support for oneOf and anyOf.

@swrnm
Copy link
Author

swrnm commented Sep 15, 2020

Hi @wing328
Thanks for the quick response.

Actually, we use the same YAML file to generate multiple clients. And facing the same issue in C#, Python, PHP, and Nodejs wrappers too. Would you please suggest alternatives of jersey2 for other wrappers too? If not, maybe we can consider it a bug?

Just for the confirmation, are you talking about including jersey2 in Java client's files or the open-api generator's master branch and creating wrappers using that? If talking about secondary, then definitely all the wrappers' issues will be fixed.
But in that case, do we have to include the library in the latest master and create openapi-generator's jar first, right?

@wing328
Copy link
Member

wing328 commented Sep 15, 2020

PHP, and Nodejs

No oneOf support at the moment. Would you or your team be willing to sponsor the enhancement? Example

Or you or your team is willing to contributing the enhancement?

For C#, that's something I'm working on. No ETA

For python, please try the python-experimental generator in the latest master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants