OpenAPITools / OpenAPITools/openapi-generator

[BUG][Jersey2][csharp-netcore]: Open API generator doesn't support oneof properties

Open
#11,191 2 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C# Client: Java Inline Schema Handling 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?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Open API generator's Jersey2, csharp-netcore and python support polymorphic(oneof) classes. But they don't support when a particular property is of oneof type(universeCategory).

Supported one:

  "Universe":{
    "type":"object",
    "properties":{
      "universeCategory":{
        "$ref":"#/components/schemas/UniverseCategory"
      }
    },
    "additionalProperties":false
  },
  "UniverseCategory":{
    "oneOf":[
      {
        "$ref":"#/components/schemas/HalfUniverse"
      },
      {
        "$ref":"#/components/schemas/FullUniverse"
      }
    ],
    "discriminator":{
      "propertyName":"source",
      "mapping":{
        "HalfUniverse":"#/components/schemas/HalfUniverse",
        "FullUniverse":"#/components/schemas/FullUniverse"
      }
    }
  }

Unsupported one:

  "Universe":{
    "type":"object",
    "properties":{
      "universeCategory":{
        "oneOf":[
          {
            "$ref":"#/components/schemas/FullUniverse"
          },
          {
            "$ref":"#/components/schemas/HalfUniverse"
          }
        ],
        "discriminator":{
          "propertyName":"source",
          "mapping":{
            "FullUniverse":"#/components/schemas/FullUniverse",
            "HalfUniverse":"#/components/schemas/HalfUniverse"
          }
        }
      }
    }
  }

Swachbuckle generates the Open API specification only in the second format(unsupported format as above) and it is not possible to generate SDK.

openapi-generator version

5.3.1

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/7988

Suggest a fix

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 by reproducing the two schema forms in the issue for the Jersey2, csharp-netcore, and python generators, then compare the generated output with the supported referenced oneOf schema. Review related issue 7988 and generation behavior; done means property-level oneOf schemas generate usable SDKs for the reported formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, openapi, python
Domain
api, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.