speakeasy
speakeasy copied to clipboard
[SPE-3165] Support Open Enums
Currently, all our targets generate SDKs which use closed enums. When an SDK sees a new value for an enum field, it will typically throw or error in some way. This property of enums is sometimes desirable. However, there are several instance where "open" enums are more desirable and will often aid in building more evolvable APIs.
We should support marking enums as open and coalesce new/unrecognised values to some "unknown" member.
A proposed approach to modelling this in OpenAPI:
A custom x-speakeasy-enum-fallback
directive specifies an existing member to use as fallback when processing unrecognised values.
payment_status:
type: string
enum:
- unknown
- created
- submitted
- successful
x-speakeasy-enum-fallback: unknown
API authors that want to maintain the original value may decide to declare another field as a plain type: string which contains an unmodified copy.