DEV Community

Cover image for Which OpenAPI Codegen Should You Choose in 2026? πŸ€” openapi-typescript vs Hey API vs Orval vs Kubb v5 πŸ”₯
nyaomaru for Necoz

Posted on AI-assisted

Which OpenAPI Codegen Should You Choose in 2026? πŸ€” openapi-typescript vs Hey API vs Orval vs Kubb v5 πŸ”₯

Real-world production insights on Kubb v5

Hoi hoi!

I'm @nyaomaru, a frontend engineer who loves TypeScript, OSS, and getting lost in forests of generated code. 🌳

Six months ago, I compared four OpenAPI code generators in this article πŸ‘‡

I chose Hey API.

I'm still using it in production, and I'm pretty happy with it.

But Kubb has changed a lot with v5! πŸš€

Faster generation? Better clients? A new plugin architecture?

Oh no. Time to go back into the forest. 🌳🌳🌳

Let's see what has changed!

open api test


🎯 TL;DR

Library Why I would choose it
openapi-typescript Types with minimal generated code
Hey API Clean SDKs and comfortable DX
Orval Flexible client, query, and mock generation
Kubb v5 Extensible code generation with much-improved clients

I'm keeping Hey API in my existing projects.

But for my next project? Kubb looks quite tempting. πŸ‘€


πŸ•°οΈ Six months later

Here are the versions I tested (Kubb plugins have their own versions) πŸ‘‡

Library May 2026 November 2026
openapi-typescript 7.13.0 7.13.0
Hey API 0.96.1 0.99.0
Orval 8.8.1 8.48.0
Kubb 4.37.2 5.20.2

Kubb had a major architectural overhaul, while Hey API and Orval continued improving their existing ecosystems.

Let's see what that actually means for us.


🏎️ How fast are they now?

For this investigation, I generated a synthetic OpenAPI specification using drf-spectacular.

  • 1,200 operations
  • 484 component schemas
  • 51,878 lines
  • Approximately 1.28 MB

I reran the previous versions using this new specification.

All measurements below are from the same Ryzen 9 7900 machine running WSL2 and Node.js 26. Each result is the median of eight measured executions after one warm-up.

Types only

Generating 484 shared component schemas

Library Time Peak RSS (max)
openapi-typescript 438 ms 191 MiB
Hey API 527 ms 240 MiB
Orval 866 ms 145 MiB
Kubb 337 ms 156 MiB

Wait, Kubb?! 😳

Types + Fetch SDK

I benchmarked both old and current versions on the same synthetic schema and machine.

Library Old version Current version Reduction
Hey API 7,406 ms 1,329 ms 82.1%
Orval 3,457 ms 1,723 ms 50.2%
Kubb 6,236 ms 1,155 ms 81.5%

That's a massive improvement for both Hey API and Kubb.

openapi-typescript took 751 ms to generate the full operation types, but it uses a generic runtime client rather than generating an SDK for every endpoint, so I've kept it separate.

Generation scopes and output structures still differ, and these aren't measurements against the original production API.

Also, generation isn't everything. A single TypeScript compilation took approximately 2.44 seconds for Hey API and 3.80 seconds for Kubb.

Fast generation doesn't necessarily mean faster everything.

Still, impressive work! πŸš€


🌳 How big is the forest?

Here's the generated output for the full specification.

Library Files Source size
openapi-typescript 1 1.45 MB
Hey API 16 1.78 MB
Orval 1,926 2.18 MB
Kubb 2,897 3.13 MB

A house, a small town, a forest, and a very ambitious forest.

openapi-typescript/
  types.ts

hey-api/
  types.gen.ts
  sdk.gen.ts
  client.gen.ts
  client/
  core/

orval/
  api.ts
  schemas/

kubb/
  clients/
  types/
  .kubb/
Enter fullscreen mode Exit fullscreen mode

I still prefer Hey API's relatively compact structure.

But Kubb's distributed files aren't necessarily a bad thing. Smaller individual files can make generated code easier to navigate and review.

These are generated source sizes, by the wayβ€”not application bundle sizes.


πŸ§‘β€πŸ’» Let's actually call an API

Suppose we have three endpoints πŸ‘‡

GET  /users
GET  /users/{id}
POST /users
Enter fullscreen mode Exit fullscreen mode

openapi-typescript

Using its official companion, openapi-fetch

const client = createClient<paths>({
  baseUrl: BASE_URL,
});

client.GET("/users", {
  params: { query: { limit: 2 } },
});

client.GET("/users/{id}", {
  params: { path: { id: "1" } },
});

client.POST("/users", {
  body: { id: "1", name: "Ada" },
});
Enter fullscreen mode Exit fullscreen mode

No generated function for every endpoint.

Just typed URLs, HTTP methods, and a generic client.

Small. Simple. Useful. πŸ‘

Hey API

getUsers({
  query: { limit: 2 },
});

getUser({
  path: { id: "1" },
});

createUser({
  body: { id: "1", name: "Ada" },
});
Enter fullscreen mode Exit fullscreen mode

This is one of the main reasons I chose Hey API.

I don't need to remember the argument order of 1,200 functions.

Just query, path, and body.

My little brain is happy. 😸🧠

Orval

With useNamedParameters: true

getUsers({ limit: 2 });

getUser({ id: "1" });

createUser({
  id: "1",
  name: "Ada",
});
Enter fullscreen mode Exit fullscreen mode

Request options can be passed separately, and custom mutators allow you to centralize transport logic. πŸ‘

Kubb v5

getUsers({
  query: { limit: 2 },
});

getUser({
  path: { id: "1" },
});

createUser({
  body: { id: "1", name: "Ada" },
});
Enter fullscreen mode Exit fullscreen mode

This looks familiar. πŸ‘€

Kubb now gives me the consistent request structure I like in Hey API.

One of my previous concerns is gone. πŸ˜ΈπŸš€


⚠️ What happens when things explode?

Let's say our API returns

  • 200: User[]
  • 400: { message: string }
  • 409: { conflict: string }

I like result-based error handling, but sometimes I also want exceptions.

More importantly, I want TypeScript to know which error I'm dealing with.

openapi-fetch

const result = await list();

if (
  result.response.status === 400 &&
  result.error !== undefined &&
  "message" in result.error
) {
  console.log(result.error.message);
}
Enter fullscreen mode Exit fullscreen mode

Hey API

const result = await list();

if (
  result.response?.status === 400 &&
  result.error !== undefined &&
  "message" in result.error
) {
  console.log(result.error.message);
}
Enter fullscreen mode Exit fullscreen mode

You get typed error responses, but checking the nested HTTP status alone doesn't narrow the error body.

Orval

const result = await list();

if (result.status === 400) {
  console.log(result.data.message);
}

if (result.status === 409) {
  console.log(result.data.conflict);
}
Enter fullscreen mode Exit fullscreen mode

Nice!

The top-level status acts as a discriminant. 😸

Kubb v5

const result = await getUsers({
  throwOnError: false,
});

if (result.status === 400) {
  if ("message" in result.error) {
    console.log(result.error.message);
  }
}
Enter fullscreen mode Exit fullscreen mode

Kubb also provides status-based narrowing. The additional guard handles the possible empty error body. πŸ‘

To throw or not to throw

  • Hey API
await getUsers({
  throwOnError: true,
});
Enter fullscreen mode Exit fullscreen mode
  • Kubb
await getUsers({
  throwOnError: true,
});
Enter fullscreen mode Exit fullscreen mode

Hey API defaults to result-style HTTP errors in the tested SDK; Kubb defaults to throwing. Both let me choose.

Or, with Kubb

const users = await getUsers({
  throwOnError: false,
}).unwrap();
Enter fullscreen mode Exit fullscreen mode

I particularly like this little .unwrap().

Give me the data or reject. Thank you very much!

There are still differences in what each client considers an error.

Behavior Hey API Kubb
Result-style HTTP errors βœ… βœ…
Configurable throwing βœ… βœ…
Status-discriminated result β€” βœ…
.unwrap() β€” βœ…
Network failure in nonthrowing mode Returned error in tests Rejected in tests

Nonthrowing HTTP mode doesn't mean nothing can throw!


πŸͺ What about TanStack Query?

All four have a way to integrate with TanStack Query.

// openapi-react-query
$api.queryOptions("get", "/users");

// Hey API
getUsersOptions();

// Orval
getGetUsersQueryOptions();

// Kubb
getUsersQueryOptions();
Enter fullscreen mode Exit fullscreen mode

One interesting difference appeared in the runtime tests:

Library HTTP 400 in tested query configuration
openapi-react-query Rejects
Hey API Rejects
Orval Resolves by default
Kubb Rejects by default

TanStack Query needs a rejected promise to recognize a failed request.

For Orval's tested Fetch configuration, enabling override.fetch.forceSuccessResponse: true changes that behavior.

Not a deal-breaker. Just something worth configuring before your query happily reports that everything is fine while your API is on fire. πŸ”₯


🀯 The enum problem, again

Remember those little enums that caused so much trouble last time?

They're back.

Consider these schema fragments:

BlankEnum:
  type: string
  enum: [""]

NullEnum:
  enum: [null]
Enter fullscreen mode Exit fullscreen mode

Here's what happened:

Case openapi-typescript Hey API Orval Kubb
Empty-string enum (3.0 fixture) βœ… βœ… βœ… βœ…
Null-only enum (3.1 fixture) βœ… ❌ βœ… βœ…

Kubb's previous blank-enum issue is fixed! πŸŽ‰

Its v4 already handled the tested null-only case correctly, so that isn't a new v5 improvement.

Interestingly, Hey API still has a problem with the null-only enum.

type NullEnum = never;
Enter fullscreen mode Exit fullscreen mode

Oops.

Adding type: 'null' fixes the TypeScript type, but the generated Zod validator can still accept unrelated values.

The verified workaround for this OpenAPI 3.1 case is:

NullEnum:
  type: "null"
Enter fullscreen mode Exit fullscreen mode

Now we get the correct type and validator:

type NullEnum = null;

const zNullEnum = z.null();
Enter fullscreen mode Exit fullscreen mode

There's also an existing upstream issue.

It's a specific edge case, not a general problem with nullable properties.
But this is why I test generated types instead of simply trusting them.


πŸ›‘οΈ Type safety at runtime

TypeScript is wonderful. Unfortunately, my backend doesn't care. 😹

All four default clients accepted invalid response data in my tests. With runtime validation, all four rejected it.

Library Validation
openapi-typescript Manual
Hey API Generated Zod
Orval Generated Zod
Kubb Generated Zod

Encoding and decoding

Kubb has another interesting feature: directional transformations.

const result = await postTimestamp({
  body: { at: new Date() },
});

const date: Date = result.data.at;
Enter fullscreen mode Exit fullscreen mode

With inferred: 'codec' and a custom datetime printer, Kubb generated the ISO string ↔ Date transformations and integrated them into the client.

These are directional Zod transforms, not native bidirectional z.codec objects.

Less glue code. Happy cats. 🐈

Server-Sent Events

Both Hey API and Kubb handled typed SSE in my tests.

// Hey API
const { stream } = await heyEvents();

for await (const event of stream) {
  console.log(event.value);
}
Enter fullscreen mode Exit fullscreen mode
// Kubb
const { stream } = await kubbEvents();

for await (const event of stream) {
  console.log(event.data.value);
}
Enter fullscreen mode Exit fullscreen mode

Different wrappers, same typed streaming goodness.


🧰 The ecosystem

Feature openapi-typescript Hey API Orval Kubb
Fetch βœ… βœ… βœ… βœ…
Axios β€” βœ… βœ… βœ…
React Query βœ… βœ… βœ… βœ…
SWR β€” βœ… βœ… βœ…
Zod generation β€” βœ… βœ… βœ…
Faker / MSW β€” βœ… βœ… βœ…
Native custom plugins β€” βœ… β€” βœ…

These are official integrations and companions, not necessarily built-in features. Other extension mechanisms exist.

One correction from my previous comparison: Hey API also supports Faker, MSW, and SWR. I verified Faker/MSW behavior and SWR generation.

The ecosystems are getting crowded. In a good way! 😸


πŸ—οΈ Kubb v5: More than an OpenAPI generator?

This is where Kubb gets interesting.

OpenAPI
   ↓
Unified AST
   ↓
Plugins + Resolvers + Macros
   ↓
Generated code
Enter fullscreen mode Exit fullscreen mode

Kubb v5 lets plugins share a normalized AST instead of independently parsing the specification.

But what does that actually give us?

Resolvers

Let's say my project requires an Api prefix and .model.ts filenames.

import { pluginTs, resolverTs } from '@kubb/plugin-ts';

pluginTs({
  resolver: {
    name(name) {
      return `Api${resolverTs.name(name)}`;
    },
    file: {
      baseName({ name, extname }) {
        return `${name}.model${extname}`;
      },
    },
  },
});
Enter fullscreen mode Exit fullscreen mode

The result?

- GetUsersOptions
+ ApiGetUsersOptions
Enter fullscreen mode Exit fullscreen mode

Even better, the Fetch plugin automatically imports the renamed type from the renamed file.

No regex magic. No broken imports. Strict TypeScript compilation passed.

Macros

I also tested removing descriptions from TypeScript output while preserving them in Zod output.

It worked. Each plugin can transform its own AST without affecting the others.

Kubb Kit and Registry

Kubb Kit lets developers build custom generators using the same infrastructure as official plugins.

And the Kubb Registry lets the community distribute extensions.

Kubb registry Β· Kubb

The list of Kubb extensions that the Kubb CLI, Kubb Studio and kubb.dev read. It is a set of static JSON documents under one base URL.

favicon kubb.dev

Hey API also supports custom plugins, so extensibility isn't unique to Kubb.

But the combination of shared AST, resolvers, macros, and Kit makes Kubb particularly interesting for building a company-wide generation platform.


πŸ€– AI can grow a forest overnight

AI makes generating code faster. Keeping it consistent? Not so much.

Imagine five AI agents building five features, each inventing different API wrappers and error handling.

Congratulations! Five different forests. πŸŒ³πŸŒ΄πŸŒ²πŸŽ‹πŸŒ΅

Why keep telling AI the same rules when we can encode them into a shared generator?

Let AI help build the plugins. Let deterministic codegen enforce the conventions.

One shared plugin can serve ten projects instead of ten AI agents reinventing the same thing.

Maybe the best use of AI isn't generating more code. It's building better tools that generate code for us.

And that's exactly why Kubb's architecture caught my attention.


🌱 Maintaining the forest

I also tested how generated code changes when the API evolves.

Library Changed files Added / removed lines
openapi-typescript 1 +2 / βˆ’2
Hey API 3 +9 / βˆ’9
Orval 3 +14 / βˆ’14
Kubb 6 +59 / βˆ’59

These results are from renaming one operationId.

All four generated identical output with unchanged input, and breaking schema changes were caught by application type checks.

More files aren't necessarily worse. Just keep your forest under control! 🌳


🀝 Kubb Studio

Kubb also introduced Kubb Studio, a separate collaboration service.

Kubb Studio Β· Generate typed clients from your API spec

Generate TypeScript clients, TanStack Query hooks and Zod schemas from your API spec on your own machines. Review every change, then ship from CI. Start free.

favicon kubb.studio

It offers UI-based plugin configuration, generated-file comments, and npm snapshots through GitHub Actions.

That could help frontend teams work against upcoming backend contracts before release.

I haven't tested it hands-on yet, but it's an interesting direction!

πŸ““ Side by side

openapi-typescript Hey API Orval Kubb v5
Approach Types SDK Configurable generators Extensible generators
Request style Typed URL Named options Configurable Named options
Output Minimal Compact Configurable Distributed
Errors Result Result / Throw Status / Throw Result / Throw / Unwrap
Validation Manual Generated Generated Generated
Extensions Scripts / AST Plugins Transformers / hooks Kit / Resolvers / Macros

πŸš€ Back out of the forest

Six months ago, I chose Hey API. And I'm keeping it.

But Kubb v5 surprised me.

It's faster, its clients have improved, and its architecture offers something beyond a ready-made SDK.

In the AI era, I think shared development foundations matter more than ever.

For my next large frontend project, I'd love to give Kubb a try.

Six months ago, I wanted a smaller forest.

Now, I want to design how it grows.

Before AI plants another million trees. πŸŒ³πŸ€–

Thanks for reading! πŸ™ŒπŸ’š

Top comments (7)

Collapse
 
johnnylemonny profile image
𝗝𝗼𝗡𝗻 Necoz •

Great practical comparison! Framing the choice around operational trade-offs like file count, IDE indexing, and error models instead of just feature checklists is what actually matters once an API grows past a few hundred operations.

The distinction between a lightweight type generator like openapi-typescript and fuller platforms like Orval or Kubb is spot on. For larger codebases, having a consistent { path, query, body } signature and a predictable result-style error model like hey-api offers really pays off over shorter per-endpoint call sites.

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Thanks, John!! πŸ˜ΈπŸ’š

Exactly! Once you have hundreds of endpoints, consistency matters much more than saving a few lines of code.

That's one of the reasons I've been so comfortable with Hey API in production.
But Kubb v5 is making me curious again! 😹

Collapse
 
johnclentoira profile image
john Clent Oira •

Great comparison! I appreciate how you've brought these different OpenAPI code generation tools together.
One thing I'm particularly curious about is long-term maintainability in large projects. When multiple backend teams frequently update their API specifications, generated code changes can become difficult to manage.
Which of these tools would you recommend for a large microservices architecture? And how would you handle breaking API changes automatically within a CI/CD pipeline without disrupting existing frontend applications?
I'd love to hear your perspective on this. Thanks for sharing such a useful comparison! πŸ™Œ

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Thanks for the great question! πŸ™Œ

I can only speak confidently about Hey API from production experience, as I haven't used Kubb in a real project yet. 😸

In my current project, I set up an automated workflow like this:

  1. When the backend changes, the OpenAPI YAML is automatically generated.
  2. Hey API generates the clients and types from that specification.
  3. If the generated code contains changes, PRs are automatically created in the relevant frontend repositories.

This works across multiple backend services and frontend repositories, and so far, we haven't encountered any major issues. It's incredibly convenient! πŸ‘

For breaking API changes, I would separate automatic code generation from automatic merging. Type checking, tests, and builds in the frontend CI pipeline can help catch incompatible changes before they reach production.

Of course, breaking changes still require coordination between backend and frontend teams.

So, based on my production experience, I'd confidently recommend Hey API for a microservices architecture. πŸš€

As for Kubb v5, I can't yet make the same claim about its long-term maintainability in production.

However, based on this investigation, I think it's absolutely worth considering, especially if you want to standardize code generation across multiple teams and projects through shared plugins and conventions.

I'm quite excited about its potential! 😸

Collapse
 
johnclentoira profile image
john Clent Oira •

Thanks for sharing your production experience! I really like your approach of separating automated code generation from automatic merging.
That brings up another interesting question. How do you detect breaking API changes that don't necessarily cause TypeScript compilation errors, such as changes in response behavior, validation rules, or business logic? Do you also use contract testing alongside your CI/CD pipeline to catch these issues?
I'd love to hear how your team handles this in practice. Really appreciate the discussion! 😊

Thread Thread
 
nyaomaru profile image
nyaomaru Necoz •

These kinds of behavioral changes are much harder to detect through type checking or code generation alone.

In our current workflow, we run an AI-powered code review on the automatically generated PRs in the frontend repositories. This helps us identify potential compatibility issues that TypeScript might not catch.

Of course, AI review isn't a guarantee, especially when business logic changes aren't reflected in the API specification. Human review and communication between backend and frontend teams are still important.

It's not a perfect solution, but it's a useful additional layer! πŸ™Œ

Thread Thread
 
johnclentoira profile image
john Clent Oira •

That's a really interesting approach! I appreciate your transparency about the limitations of AI-powered code reviews. Combining AI assistance with human expertise seems like a practical balance.
One question that comes to mind: if the AI reviewer only receives the generated frontend code changes, how does it detect behavioral changes in the backend that aren't reflected in the OpenAPI specification? Have you considered providing the AI reviewer with backend implementation changes as additional context?
I think this could be particularly valuable for complex microservices where a seemingly minor backend change can have unexpected downstream effects.
Really enjoying this technical discussion. Thanks for sharing your experience! 😊