Under the Hood: Building a High-Performance OpenAPI Parser in Go
Blog post from Speakeasy
At Speakeasy, the need to process thousands of OpenAPI specifications daily led to the creation of a custom high-performance OpenAPI parser in Go, designed to address limitations in existing libraries. The newly introduced library, github.com/speakeasy-api/openapi, offers precise modeling of the specification and high-performance capabilities for reading, validating, mutating, and transforming specs at scale, handling complex aspects such as dynamic types and reference resolution in OpenAPI documents. Utilizing a reflection-based marshaller, the library supports multiple OpenAPI versions, Swagger, Arazzo, and Overlays, emphasizing correctness and developer experience. It features a "Porcelain vs. Plumbing" design for optimized internal performance while providing a clean API, and accommodates reference resolution, validation, and complex spec handling with a unified ecosystem approach. Additionally, the library includes a comprehensive CLI tool that mirrors its core capabilities, facilitating tasks like bundling, inlining, and sanitizing specs, and ensuring seamless integration into Go programs or CI pipelines.