Skip to content

oneOf support via Discriminated Unions #87

@rrichardson

Description

@rrichardson

Many of the target languages support Union types.
e.g. for TypeScript, I think oneOf could be rendered as Discriminated Unions.

Does openapi-codegen support these at the moment? I see one mention of it in the templates, inside of the htmlDocs2 template. It looks like it is just introspecting the root object, though. It would be nice to see them treated as a 1st class template object similar to enums and "generics"

Example

components:
  schemas:
    ObjA:
      properties: ...
    ObjB:
      properties: ...
    ObjC:
      properties: ...
    Foo:
      oneOf:
        - $ref: "#/components/schemas/ObjA"
        - $ref: "#/components/schemas/ObjB"
        - $ref: "#/components/schemas/ObjC"

Should result in

export type Foo =  ObjA | ObjB | ObjC;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions