OpenAPITools / OpenAPITools/openapi-generator

[BUG][SPRING CONTROLLER] Bug generating OneOf inside property of a schema generates broken class (OneOfObjectNameObjectName)

Open
#5,971 1 comment 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?
    YES
  • Have you validated the input using an OpenAPI validator (example)?
    YES
  • What's the version of OpenAPI Generator used?
    4.3.0 and swagger openapi: "3.0.0"
  • Have you search for related issues/PRs?
    For example https://github.com/OpenAPITools/openapi-generator/issues/5730
  • What's the actual output vs expected output?
    Actual: OneOfObjectAObjectB
    Expected: interface of these objects

I generate code by openapi-generator-maven-plugin 4.3.0 and in this situation:

MyObject:
      type: object
      properties:
        field:
          oneOf:
            - $ref: '#/components/schemas/ObjectA'
            - $ref: '#/components/schemas/ObjectB'

By <generatorName>spring</generatorName> get:

public class MyObject {
  @JsonProperty("field")
  private OneOfObjectAObjectB  field = null;
}

This class OneOfObjectAObjectB isn't created. mvn package failed.

BUT by <generatorName>java</generatorName> (pom.xml) get:

public class MyObject {
  @JsonProperty("field")
  private MyObjectFieldOneOf  field = null;
}

And this works for client! It creates interface MyObjectFieldOneOf for objects ObjectA and ObjectB that implement this created interface MyObjectFieldOneOf

I use spring and java generatorName for controllers and clients respectively. I tried all variants of configs in pom.xml to fixed this.

In earlier versions (than 4.3.0) generation models for client doesn't work. I glad that bug generation for client fixed in 4.3.0. We are waiting for spring controller correction :))))

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 with the minimal OpenAPI schema in the issue and compare the Spring and Java generator outputs for the nested oneOf property using version 4.3.0. Trace the Spring controller model-generation entry point and verify completion when the generated type is defined and mvn package succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.