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

Add enum_items to discriminated union #741

Conversation

pulasthibandara
Copy link
Contributor

This specifies the discriminator property of the discriminated union as a string literal. As OpenApi doesn't support string literals its common practice to define a literal as an enum of one option. (reference: OAI/OpenAPI-Specification#1313 (comment))

This helps with code generators as it generates a type-safe discriminated union. Following is a Typescript example.

With enum defined:

ex: 

type Animal =
   | { type: 'Dog', bark: string }
   | { type: 'Cat', name: string }

Without enum defined ("type" looses its literals):

ex: 

type Animal =
   | { type: string, bark: string }
   | { type: string, name: string }

@sunli829 sunli829 force-pushed the master branch 4 times, most recently from 0c16a9b to f6bec88 Compare March 30, 2024 09:25
@sunli829 sunli829 merged commit ed73384 into poem-web:master May 11, 2024
7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants