OpenAPI Compiler Infrastructure
With schema infrastructure solid, we moved up a layer to OpenAPI. Not parsing in the trivial sense—full compiler infrastructure for semantic analysis, traversal, transformation, and tree-shaking of API specifications.
The Typeclass Pattern, Again
December’s schema compiler used a keyword-centric architecture: each keyword knows how to parse, validate, traverse, and transform itself. OpenAPI has a different structure—a fixed object hierarchy rather than extensible keywords—but the same pattern applies.
Each OpenAPI object type implements a common behavioral interface. Operations know how to handle themselves. Parameters know how to handle themselves. Responses, security schemes, media types—all of them. Add a new capability like tree-shaking or type generation, and every object type participates automatically. No central dispatch to modify. No switch statements growing with each new concern.
Two Layers, Clean Delegation
OpenAPI embeds JSON Schema but isn’t JSON Schema. An operation contains parameters. Parameters contain schemas. When processing hits a schema, the OpenAPI layer delegates to the schema compiler’s keyword-based machinery, then resumes OpenAPI-aware processing afterward.
This boundary matters. A properties key inside a schema means subschemas to traverse. The same key in example data means nothing—just data to preserve. Format boundaries mark where interpretation rules change. The compiler switches semantic context at these boundaries automatically.
Tree-Shaking Across Layers
Given an operation, extract only what it needs. Follow parameter references. Follow schema references within those parameters. Follow security scheme references. The tree shaker doesn’t care which layer owns which reference—it follows them all and organizes output by OpenAPI component type.
An 8MB specification becomes ~5KB per extracted operation. Only the schemas, parameters, responses, and security schemes that operation actually uses. This is what enables serving operation-specific specs to AI agents without overwhelming context windows.
Version Abstraction
The compiler handles OpenAPI 3.0 and 3.1 uniformly. Version differences—schema dialect, nullable semantics, structural variations—normalize during parsing. Same infrastructure, same capabilities, regardless of which version the input uses.