Skip to main content

Cleaner, Safer Code with Discriminated Unions

· 12 min read
Steve Konves
Basketry maintainer

Learn how to improve your code quality and type safety with discriminated unions, and use Basketry to streamline the process.

What are discriminated unions?

Discriminated unions, also known as tagged unions or algebraic data types, are a powerful feature in many modern programming languages that allow you to define a type that can take on several different but related forms.

Photo of a large, white sign with the letters 'UNION' against a light blue sky, mounted on top of a white brick building.

Basketry turns 0.1.0! 🧺 🎉

· 6 min read
Steve Konves
Basketry maintainer

Evolving an ecosystem with new features, fixes, and improvements.

Basketry is the pluggable, service-oriented code-generation pipeline for any language. It starts with a Service Definition (think Swagger/OpenAPI, API Blueprint, etc.) and generates code for your APIs and the applications that consume them.

Group of people raising their glasses in a toast at a festive celebration, surrounded by golden confetti and warm lighting.

Evolving a pluggable toolchain

The Basketry project is the 3rd or 4th iteration of a toolchain I’ve maintained for the better part of a decade for designing, building, and testing APIs. It started back in the Swagger 2.0 days as a simple tool for defining ExpressJS routes using a “Swagger doc.” The code and architecture are now almost unrecognizable from its long-lost ancestor and it now supports multiple versions of OpenAPI as well as multiple target languages. But nevertheless, it did indeed begin its life as a narrowly focused Swagger v2 tool. For this reason, until recently, it has lacked some features and data structures more closely associated with OpenAPI v3.

Introducing Basketry

· 7 min read
Steve Konves
Basketry maintainer

Basketry is the pluggable, service-oriented code-generation pipeline for any language. It starts with a Service Definition (think Swagger/OpenAPI, API Blueprint, etc.) and generates code for your APIs.

Let's unpack that.

Basketry is Pluggable

Basketry isn't one single tool but rather a collection of small tools that work together as a pluggable pipeline. Individually, each component follows the mantra of "do one thing and do it well." Together, they comprise a powerful system for building service-oriented code.

A Basketry pipeline as a whole reads a Service Definition and outputs a set of code files. It does so by composing three types of components: Parsers, Rules, and Generators.

Basketry overview