Home / Companies / WorkOS / Blog / Post Details
Content Deep Dive

How to build a custom SDK generator with oagen

Blog post from WorkOS

Post Details
Company
Date Published
Author
Maria Paktiti
Word Count
3,732
Language
English
Hacker News Points
-
Summary

The described process focuses on using oagen, a framework designed for generating SDKs from OpenAPI specifications, which aims to address issues of drift and inconsistency in codebases by treating the generation of SDKs as a compilation problem. Unlike traditional OpenAPI tools, oagen offers a framework for building custom generators, providing developers with full control over the generated output through user-defined emitter code. It uses a typed intermediate representation (IR) as a stable contract between the parser and emitters, ensuring consistency and reducing redundancy across different language outputs. The tutorial illustrates building a Python SDK generator, detailing each step from parsing the OpenAPI spec to creating emitter functions that handle models, enums, services, and client classes. The architecture allows for flexibility and extensibility, enabling emitters to adapt easily to changes in the API specification while maintaining a consistent SDK interface. The approach leverages TypeScript's type system to ensure comprehensive handling of all possible data types, preventing runtime errors. The framework also supports testing with fixture specs and offers a diff command to track API changes, which can facilitate the management of breaking changes without forcing immediate updates on SDK users.