openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open saigiridhar21 opened this issue 4 years ago • 2 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] 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

saigiridhar21 avatar Dec 28 '21 12:12 saigiridhar21

Whoever uses Swashbuckle(C#) to generate the Open API schema, can use this workaround to generate the referenced schema instead of the inline schema for oneof properties. https://stackoverflow.com/a/70527804/3044493

saigiridhar21 avatar Dec 30 '21 10:12 saigiridhar21

This works in openapi-generator v6.2.0 in the python client so I am removing python from the title and the tag

spacether avatar Nov 16 '22 01:11 spacether