Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oneOf support via Discriminated Unions #87

Open
rrichardson opened this issue May 28, 2020 · 1 comment
Open

oneOf support via Discriminated Unions #87

rrichardson opened this issue May 28, 2020 · 1 comment

Comments

@rrichardson
Copy link

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;
@MikeRalphson
Copy link
Contributor

It would be helpful if you could give an example of what needs providing in the model to be able to support this in the templates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants