Skip to content

codewithagents/openapi-zod-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

210 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeWithAgents OpenAPI

CI CodeQL codecov License: MIT

OpenAPI to TypeScript you actually own. Native fetch client, React Query hooks, and Zod schemas you can extend, from one OpenAPI 3.1 spec. Zero runtime dependencies.

You consume a REST API. You need TypeScript types, a fetch client, form error mapping, and React Query hooks. Instead of hand-writing all of this (and keeping it in sync every time the spec changes), you run one command. Everything here is a devDependency or generates code that only depends on what your project already has.

Unlike most generators, the output is not a black box you regenerate and forget. The Zod schema file is bootstrapped once and then yours to extend, regen never overwrites it, and the generated client uses only native fetch. See how it compares to hey-api, orval, kubb, and openapi-fetch.


Packages

Package Version Coverage Description
@codewithagents/api-errors npm codecov Map API error responses to form field errors, framework-agnostic core + React Hook Form adapter
openapi-zod-ts npm codecov Generate TypeScript models + native fetch client + Zod schemas from an OpenAPI 3.x spec
@codewithagents/openapi-react-query npm codecov Generate typed React Query v5 hooks: useQuery, useMutation, key factories
@codewithagents/openapi-server npm codecov Generate a framework-agnostic service interface from OpenAPI 3.x. Optional Hono router included, or skip it and wire to any framework you choose

Each package has its own README with full usage docs and configuration reference.


Full pipeline

One spec, four generators:

spec/api.json
  ├── openapi-zod-ts          → models.ts, client.ts       (TypeScript types + fetch client)
  ├── openapi-server       → service.ts                 (framework-agnostic service interface)
  │                          router.ts                  (optional — Hono, or wire to any framework)
  └── openapi-react-query  → hooks.ts                   (React Query v5 hooks)

You write: your business logic (implement the service interface). Everything else is generated and stays in sync when the spec changes.


Philosophy

Zero footprint. Every package is a devDependency or generates code that uses only what your project already has. We never add a runtime dependency you didn't choose.

Latest only. TypeScript 6 (actively supported), OpenAPI 3.x (3.1.1 primary target), Zod v4, React Query v5. No legacy shims, no backports. Opinionated cuts mean less code, faster iteration, and a clear upgrade path.

You own the output. The Zod schema file is bootstrapped once and never overwritten. Add your own validation rules, error messages, and business logic. The generator treats your file as source of truth.

Readable output. Generated code looks like code you'd write yourself — no opaque abstractions, no minified magic. You can read it, review it, and commit it.

Agent-friendly. One devDependency, one command, a fully-typed API client with runtime validation. Designed to work well when an AI agent is building or maintaining your project.


How it compares

hey-api, orval, kubb, and openapi-fetch are all good, actively maintained tools, and in some areas more featureful than this one. The honest trade-off: we are smaller and more opinionated, and we trade breadth for ownership and stability.

openapi-zod-ts hey-api orval kubb openapi-fetch
Runtime library added to your app None (native fetch) None (bundled) Mutator (often axios) Client of choice ~6 kb required
Zod schema file you own, never overwritten Yes No No No n/a
Runtime request + response validation Yes Yes Yes Yes No
React Query hooks Yes (React) Yes (multi) Yes (multi) Yes (React, Vue, SWR) Companion pkg
Server-side service interface + router Yes No No No No
Mocks (MSW / faker) No Yes Yes Yes No
Swagger 2.0 No No Yes Yes No
Stable 1.0 Yes No (0.x) Yes Yes Yes

Pick something else if your frontend is Vue/Svelte/Angular (hey-api, orval, kubb), you need generated mocks (orval, kubb), you have a Swagger 2.0 spec (orval, kubb), or you want the largest ecosystem (hey-api). Full breakdown, including where the alternatives win: How it compares.


Why quality matters

Code generators have a wide blast radius. A subtle regression in the generator touches every project that runs it. These are the layers we use to catch problems before they reach you.

Near-100% test coverage. All four packages run at 100% statements, functions, and lines. Branches sit at 99%+ across the board. The remaining gap is a handful of genuinely unreachable defensive guards (?? fallback patterns where the fallback can never trigger by construction). Coverage is tracked per-package via Codecov and blocks PRs when it drops.

128 real-world OpenAPI specs. The generator runs against a compatibility matrix of 128 publicly available specs: Stripe, GitHub, Google Calendar, Spotify, Twitter/X, OpenAI, Adyen, Slack, Vercel, Cloudflare, Twilio, Plaid, Notion, Jira, Okta, and more. 128/128 generate without errors on every PR. The 13 showcase specs (1Password Connect, Adyen Checkout, Adyen Legal Entity, Canada Holidays, Dev.to, Exchange Rate, Open-Meteo, OpenAI, Petstore, Redocly Museum, Resend, Spotify, Twitter) have committed output and are drift-checked on every relevant PR. If anything regresses, CI fails.

Smoke tests against live public APIs. The generated client code fires real HTTP requests against public no-auth APIs (Open-Meteo, Canada Holidays, Exchange Rate API, D&D 5e) on every push to main and weekly on a schedule. This is the generated code itself making network calls, not just checking that it compiles. If the generator produces a client that breaks at runtime, the smoke suite catches it.

Mutation testing with Stryker. openapi-zod-ts and openapi-react-query run Stryker mutation tests locally. Mutation testing deliberately introduces bugs into the source code and verifies that the test suite catches them. High line coverage that doesn't actually catch regressions shows up here.

Full-stack E2E tests. The petstore package is a complete runnable full-stack app: one spec drives generated types, fetch client, React Query hooks, a Hono server with Zod validation, and end-to-end Playwright tests. Every PR runs the full round-trip — spec change to browser assertion.

Static analysis on every PR. Fallow runs on every pull request and posts inline review comments flagging dead code, duplication, and unresolved imports introduced by the diff. CodeQL handles security scanning.

See examples/README.md for the full compatibility breakdown.


Contributing

See CONTRIBUTING.md.


Sponsors

This project is MIT-licensed and free to use. If it saves you time, consider sponsoring:

GitHub Sponsors


License

MIT © codewithagents

About

Glue packages for TypeScript — connecting OpenAPI, forms, validation and React Query

Topics

Resources

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Contributors

Languages