Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7414
Closed
Open
Issue created Sep 14, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

Created by: swrnm

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
  • https://github.com/OpenAPITools/openapi-generator/issues/5565
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
Assignee
Assign to
Time tracking