Building a High-Performance OpenAPI Parser in Go
4 days ago
- #API Development
- #Go
- #OpenAPI
- Speakeasy built a high-performance OpenAPI parser in Go to handle thousands of OpenAPI specifications daily.
- Existing Go libraries had limitations: some were fast but loosely modeled, others were accurate but untyped.
- The new library provides a precise model of OpenAPI with high performance for reading, validating, and transforming specs.
- Key challenges included OpenAPI's complexity, dynamic types, and recursive/circular references.
- The architecture uses a reflection-based marshaller to separate model definition from deserialization logic.
- Performance optimizations include stable internal representations and minimized allocations.
- Dynamic types are handled with type-safe abstractions like EitherValue.
- Robust reference resolution handles deeply nested, cross-file, and circular references.
- The library supports OpenAPI 3.x, Swagger 2.0, Arazzo, and Overlays with shared core models.
- Includes a CLI tool for bundling, inlining, overlaying, optimizing, sanitizing, and exploring OpenAPI documents.
- Examples show reading, validating, traversing, mutating, and upgrading OpenAPI documents programmatically.