OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] [Spring] - OneOf API-first Code Generation Not Working
Nobody has claimed this yet.
- 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 (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
Description
- I know this issue might have been raised in the past few years for several times. I have a simple openapi spec with 1 GET point to return a
OneOftype of response. The generated code does not compile. - My spec is return a
contact-infowhich is either aemailor atelephoneNumber. - The generated code for
contact-infois referring a class namedOneOftelephoneNumberemail. But that class is not generated. And the maven compile failed. - the same problem also show up for
anyOfdefinition.
openapi-generator version
I have tried many versions including the latest release 5.1.1 and the 5.2.0-SNAPSHOT. This error shows up on all the versions.
OpenAPI declaration file content or url
https://github.com/bnlcnd/poc-anyof-oneof/blob/main/anyof-oneof.yaml
Generation Details
the POM file can be found here
https://github.com/bnlcnd/poc-anyof-oneof/blob/main/pom.xml
Steps to reproduce
- git clone the repository https://github.com/bnlcnd/poc-anyof-oneof
- run the command under the root folder of the repo :
mvn clean package
Suggest a fix
This issue seems lingering around for several years. Maybe it's time to fix it for both oneOf and anyOf.
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
Clone the linked poc-anyof-oneof repository and run mvn clean package from its root, using anyof-oneof.yaml and pom.xml as the reproduction inputs. Inspect the generated Spring code and the missing OneOftelephoneNumberemail reference, then trace the oneOf and anyOf generation paths. Done means the generated project compiles for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100