We believe in the expressive power of sum types. Sum types are an easy way to express polymorphism that is easy to statically verify and therefore very resilient to errors and mistakes. Languages like Rust and Swift get this right. OpenAPI has a polymorphism concept using the oneOf field, but it’s quite cumbersome. We can do better.

In a similar vein, we believe in the rigor of monadic optionals. Tony Hoare, recognized as the originator of the concept of null references, has since decried them as “the billion dollar mistake”. Unfortunately, JSON only supports the concept of null (and similarly an “undefined” state for something omitted entirely). We believe that this state of affairs can be improved, and that can’t be done in the context of OpenAPI.

Sum Types

How do we specify these in the schema?

This is relevant to Alternative serialization medium

Value Unions

This also encompasses Typescript-style value unions or “enum literals”, like "foo" | "bar". Do we want to allow these to span across types?

Monadic Optionals

Discourse

Some people would have to be sold on this. The main draws are

Questions

How do we handle nested optionals in languages / media that do not have monadic optionals? It’s important to consider this in the context of the Partial (Lax) Operator

This question exists on both the medium side and implementation side

For media, we have these options

At the project level, we would want a preference for this. It should probably be coalesce by default, since that’s what everyone will expect, but maybe we allow users to opt into sum types. This would also ease the transition