Skip to content

Introduction

A TypeScript OpenAPI toolchain that turns a spec into everything you need: types, a fetch client, React Query hooks, Zod schemas, a server-side service interface, and form error mapping. Every generated file compiles under strict: true with zero runtime wrapper dependencies. The pipeline is tested against 128 real-world specs (Stripe, GitHub, Spotify, OpenAI, and more) on every PR.

The CodeWithAgents OpenAPI package pipeline An OpenAPI spec feeds openapi-gen, which produces TypeScript types, Zod schemas, and a fetch client. The fetch client feeds openapi-react-query for React Query hooks and openapi-server for a typed service interface and router. api-errors is a runtime package that maps any API error shape to form field errors. OpenAPI spec openapi-gen TypeScript types models.ts Zod schemas yours to extend Fetch client client.ts openapi-react-query React Query v5 hooks openapi-server service interface + router api-errors Runtime, no codegen. Maps any API error shape to form fields.

Everything flows from a single spec. One source of truth. When the spec changes, re-run the generator and the TypeScript compiler tells you exactly what broke.

PackageWhat it does
@codewithagents/openapi-genGenerates TypeScript interfaces, a native fetch client, and optional Zod schemas
@codewithagents/openapi-react-queryGenerates typed React Query v5 hooks from the client openapi-gen produces
@codewithagents/openapi-serverGenerates a typed service interface and optional Hono, Express, or Fastify router
@codewithagents/api-errorsMaps API error responses to form field errors at runtime (no codegen step)

Each package is independent. Use only the ones your project needs. They share one spec and one output directory when used together.

Built for TypeScript projects that want end-to-end type safety from an OpenAPI spec. It works with any HTTP framework on the server side and any React setup on the client. The generated output is plain TypeScript: no axios, no wrapper libraries, nothing added to your runtime bundle beyond what you already use.

If your team maintains an OpenAPI spec, the toolchain turns it into a first-class TypeScript artifact at codegen time rather than leaving the gap between spec and code to manual effort.

  • Node.js 18 or later
  • An OpenAPI 3.1 spec (JSON or YAML). OpenAPI 3.0.x is best-effort.
  • TypeScript with strict: true recommended (all generated output passes it out of the box)

Follow the Quickstart to go from a spec file to a working typed client in a few minutes.