Originally published on tamiz.pro.
In 2026, generating TypeScript types and clients from an OpenAPI spec is no longer a nice-to-have — it's the difference between shipping fast and shipping bugs. But the ecosystem has exploded. Four tools dominate the conversation: openapi-typescript, Hey API, Orval, and Kubb v5. Each takes a radically different approach. This article compares them head-to-head with real code, real configs, and real trade-offs so you can pick the right one for your project.
- 1. Why Codegen Still Matters in 2026
- 2. The Contenders at a Glance
- 3. Hands-On Setup and Generated Output
- 4. Side-by-Side Comparison Table
- 5. Trade-Off Analysis
- 6. When to Use Which
- 7. Frequently Asked Questions
1. Why Codegen Still Matters in 2026
Hand-writing API types is a losing battle. Your backend evolves, endpoints get deprecated, response shapes change, and your TypeScript types drift further from reality every sprint. The result: runtime errors that should have been caught at compile time, endless any casts, and a codebase that resists refactoring.
Code generation solves this by making your OpenAPI spec the single source of truth. When the spec changes, you regenerate, and the compiler immediately flags every call site that needs updating. In 2026, OpenAPI 3.1 is the baseline — it supports type unions, null values, and const schemas, which means generated types are far more precise than they were with 3.0. But precision is only half the story. The other half is what the generator does with those types: does it just emit interfaces, or does it also emit a runtime client, hooks, mocks, and Zod schemas?
That's where the four tools diverge. Let's look at each one.
2. The Contenders at a Glance
openapi-typescript
What it is: A zero-dependency, Node-based CLI that transforms an OpenAPI spec into a single .d.ts file of TypeScript types. No runtime code, no client, no hooks — just types.
Key features:
- Blazing fast (parses with
@apidevtools/swagger-parserinternally, but the output is pure type declarations). - Works with any HTTP client (fetch, axios, ky, etc.) because it only gives you types.
- Supports OpenAPI 3.0 and 3.1.
- Minimal config: one command, one output file.
npm install -D openapi-typescript
npx openapi-typescript https://petstore3.swagger.io/api/v3/openapi.json -o src/types/petstore.d.ts
import type { paths } from './src/types/petstore';
type Pet = paths['/pet/{petId}']['get']['responses']['200']['content']['application/json'];
Hey API
What it is: A modern, type-safe client generator with a plugin system. It generates a typed fetch/axios client, plus optional React Query / TanStack Query hooks, and even Zod schemas for runtime validation. The CLI is called @hey-api/cli.
Key features:
- Generates a runtime client (fetch or axios) with fully typed methods.
- First-class TanStack Query / React Query integration.
- Supports OpenAPI 3.1, including
$refresolution andoneOf/anyOf. - Modular: you can opt into plugins like
@hey-api/sdk,@hey-api/react-query,@hey-api/zod. - Config lives in a single
hey-api.config.tsfile.
npm install -D @hey-api/cli @hey-api/client-fetch
npx @hey-api/cli openapi -i https://petstore3.swagger.io/api/v3/openapi.json -o src/client
import { client } from './src/client';
const pet = await client.get('/pet/{petId}', { path: { petId: 1 } });
Orval
What it is: The most feature-complete generator in this list. It can output types, React Query/SWR/Axios/Fetch clients, MSW mocks, and even a full test harness. It's been around for years and has a huge community.
Key features:
- Supports React Query, SWR, Axios, Fetch, and custom clients.
- Generates MSW mock handlers automatically.
- Deeply configurable via
orval.config.tswith per-endpoint overrides. - Handles OpenAPI 3.0 and 3.1 (with some caveats).
- Mature and battle-tested; used by thousands of projects.
npm install -D orval
// orval.config.ts
import { defineConfig } from 'orval';
export default defineConfig({
petstore: {
input: 'https://petstore3.swagger.io/api/v3/openapi.json',
output: {
target: './src/api',
client: 'react-query',
mock: true,
},
},
});
import { useGetPetById } from './src/api/petstore';
const { data } = useGetPetById(1);
Kubb v5
What it is: A plugin-based codegen framework that hit v5 in late 2025. It's built on top of @kubb/core and uses a plugin architecture similar to Vite or Rollup. You compose plugins to build exactly the output you want: types, clients, mocks, TanStack Query hooks, Zod schemas, and more.
Key features:
- Plugin architecture:
@kubb/swagger,@kubb/swagger-ts,@kubb/swagger-client,@kubb/swagger-tanstack-query,@kubb/swagger-zod. - Output is highly customizable — you control file naming, folder structure, and code style.
- Supports OpenAPI 3.1 and even handles
oneOf/anyOfwith discriminated unions. - Fast, TypeScript-first, and actively maintained.
npm install -D @kubb/core @kubb/cli
// kubb.config.ts
import { defineConfig } from '@kubb/core';
export default defineConfig({
root: '.',
input: {
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
},
output: {
path: './src/gen',
},
plugins: [
'@kubb/swagger',
'@kubb/swagger-ts',
'@kubb/swagger-client',
'@kubb/swagger-tanstack-query',
],
});
import { useGetPetById } from './src/gen/hooks/useGetPetById';
const { data } = useGetPetById({ path: { petId: 1 } });
3. Hands-On Setup and Generated Output
Let's use a real OpenAPI spec — the classic Petstore v3 — and run each tool against it. We'll compare the generated output for a single endpoint: GET /pet/{petId}.
openapi-typescript: Types Only
Run the CLI:
npx openapi-typescript https://petstore3.swagger.io/api/v3/openapi.json -o src/types/petstore.d.ts
The generated .d.ts contains a paths interface. To use it, you manually wire up fetch or axios:
import type { paths } from './src/types/petstore';
type PetResponse = paths['/pet/{petId}']['get']['responses']['200']['content']['application/json'];
async function getPet(petId: number): Promise<PetResponse> {
const res = await fetch(`https://petstore3.swagger.io/api/v3/pet/${petId}`);
return res.json() as PetResponse;
}
Pros: Zero runtime cost, tiny bundle, full control over your HTTP layer. Cons: You write the client yourself — no hooks, no mocks, no validation.
Hey API: Typed Client + Hooks
Run the CLI:
npx @hey-api/cli openapi -i https://petstore3.swagger.io/api/v3/openapi.json -o src/client
This generates a client.ts with a client object. The generated method signature is fully typed:
import { client } from './src/client';
const pet = await client.get('/pet/{petId}', {
path: { petId: 1 },
});
// pet is typed as Pet
If you install the React Query plugin, you also get hooks:
npm install @hey-api/react-query
import { useGetPetById } from './src/client/hooks';
function PetCard({ id }: { id: number }) {
const { data, isLoading } = useGetPetById({ path: { petId: id } });
// ...
}
Pros: Type-safe runtime client, optional hooks, clean API. Cons: Less configurable than Orval or Kubb; you're tied to the generated client shape.
Orval: Everything but the Kitchen Sink
Create orval.config.ts and run:
npx orval --config orval.config.ts
Orval generates a full React Query hook with automatic query keys, plus an MSW mock handler if you enable mock: true:
import { useGetPetById } from './src/api/petstore';
import { getGetPetByIdMock } from './src/api/petstore.msw';
function PetCard({ id }: { id: number }) {
const { data, isLoading } = useGetPetById(id);
// ...
}
Pros: Most comprehensive out-of-the-box; mocks, hooks, and clients all generated. Cons: Config can get verbose; generated code is often large and opinionated.
Kubb v5: Plugin Composition
Create kubb.config.ts and run:
npx kubb --config kubb.config.ts
Kubb generates a file per operation, with a hook file and a client file:
import { useGetPetById } from './src/gen/hooks/useGetPetById';
import { getPetById } from './src/gen/clients/getPetById';
// Direct client call
const pet = await getPetById({ path: { petId: 1 } });
// React Query hook
function PetCard({ id }: { id: number }) {
const { data } = useGetPetById({ path: { petId: id } });
}
Pros: Maximum flexibility; you can add or remove plugins to get exactly what you need. Cons: Steeper learning curve; more configuration than the others.
4. Side-by-Side Comparison Table
| Feature | openapi-typescript | Hey API | Orval | Kubb v5 |
|---|---|---|---|---|
| Output type | Types only (.d.ts) |
Types + runtime client | Types + client + mocks | Types + client + hooks + mocks (via plugins) |
| OpenAPI 3.1 support | ✅ | ✅ | ⚠️ (partial) | ✅ |
| Runtime client included | ❌ | ✅ (fetch/axios) | ✅ (fetch/axios/ky) | ✅ (via plugin) |
| React Query / TanStack Query | ❌ | ✅ (plugin) | ✅ (built-in) | ✅ (plugin) |
| MSW mocks | ❌ | ❌ (planned) | ✅ | ✅ (via plugin) |
| Zod schema generation | ❌ | ✅ (plugin) | ❌ | ✅ (plugin) |
| Custom HTTP layer | ✅ (you write it) | ⚠️ (limited) | ⚠️ (limited) | ✅ (via plugin) |
| Config complexity | Very low | Low | Medium | High |
| Bundle size (generated) | ~0 KB (types only) | ~5–10 KB | ~15–30 KB | ~10–20 KB (depends on plugins) |
| Generation speed | Very fast | Fast | Moderate | Fast |
| Community & maintenance | Mature, stable | Growing, active | Mature, active | Newer, active |
| Learning curve | Low | Low–medium | Medium | Medium–high |
5. Trade-Off Analysis
When you only need types: openapi-typescript
If your team already has a battle-tested HTTP client (a custom fetch wrapper, axios interceptors, ky, etc.) and you just want to eliminate the any casts, openapi-typescript is the perfect fit. It's the lightest tool here — no runtime code, no hooks, no mocks. You get precise types and you keep full control of your network layer. The downside is that you have to manually maintain the mapping between endpoints and your client methods. For small to medium projects, that's fine. For large codebases with hundreds of endpoints, it becomes tedious.
When you want a clean, typed client without configuration overhead: Hey API
Hey API hits the sweet spot for most teams. It generates a typed client object that works with fetch or axios, and it has a first-class React Query plugin. The API surface is minimal and readable. You don't need to write your own client; you just import client and call methods. The main limitation is customization — if you need to inject custom headers, retries, or interceptors, you have to configure the client manually, and the generated code is less flexible than Orval or Kubb. Still, for the majority of projects, Hey API offers the best effort-to-value ratio.
When you need mocks, tests, and multiple clients: Orval
Orval is the Swiss Army knife. If you're building a large application with a test suite that needs MSW mocks, or you need to generate both React Query and SWR clients from the same spec, Orval does it all out of the box. Its config is verbose, but it's also the most mature — you'll find answers to almost any question on Stack Overflow. The trade-off is that generated code can be heavy, and you may end up with a lot of files you don't need. If your team values convention over configuration, Orval is a solid choice.
When you need ultimate flexibility and a future-proof setup: Kubb v5
Kubb v5 is for teams that treat codegen as a first-class part of their build pipeline. Its plugin architecture means you can add Zod schemas for runtime validation, TanStack Query hooks for data fetching, and MSW mocks for testing — all from the same spec. The output is highly customizable; you can control file naming, folder structure, and even the code style of generated files. The cost is complexity: you'll spend time learning the plugin system and writing config. But if you're building a large monorepo or a platform with multiple apps consuming the same API, Kubb's flexibility pays off.
6. When to Use Which
- Use openapi-typescript if: You already have a custom HTTP client, you only care about type safety, and you want zero runtime dependencies. Best for small projects or libraries.
- Use Hey API if: You want a typed fetch/axios client with optional React Query hooks, and you prefer a minimal, readable API. Best for medium-sized apps and startups.
- Use Orval if: You need mocks, multiple clients (React Query + SWR), or you're in a large enterprise codebase with a test suite. Best for teams that value maturity and out-of-the-box features.
- Use Kubb v5 if: You want a plugin-based, highly customizable pipeline, need Zod validation, or you're building a monorepo with multiple consumers. Best for platform teams and power users.
7. Frequently Asked Questions
Can I use these tools with my existing fetch wrapper?
Yes — openapi-typescript is designed for this. Hey API, Orval, and Kubb v5 also let you configure a custom HTTP client, but you'll need to adjust your wrapper to match their generated interfaces. For example, Orval supports a client option where you can pass your own axios or fetch implementation.
Which tool has the best TypeScript inference?
openapi-typescript produces the most precise types because it generates pure type declarations with no runtime indirection. However, Hey API and Kubb v5 are close behind — they infer types directly from the generated client methods. Orval is slightly less precise because it wraps the client in a generic QueryFunction that can lose some inference in edge cases.
Do these tools support OpenAPI 3.1?
All four support OpenAPI 3.1, but with varying degrees of completeness. openapi-typescript, Hey API, and Kubb v5 handle 3.1 features like type unions and const schemas well. Orval has partial support — it may not correctly resolve some oneOf/anyOf schemas, so you may need to use @apidevtools/swagger-parser to pre-process the spec. Always test with your actual spec before committing.
Looking for more deep dives on TypeScript tooling? Check out Tamiz's Insights or explore the main site.
Top comments (0)