OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] [Spring] - OneOf API-first Code Generation Not Working

Open
#9,601 2 comments 3 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 (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 OneOf type of response. The generated code does not compile.
  • My spec is return a contact-info which is either a email or a telephoneNumber.
  • The generated code for contact-info is referring a class named OneOftelephoneNumberemail. But that class is not generated. And the maven compile failed.
  • the same problem also show up for anyOf definition.
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
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.