What are the best tools for generating TypeScript types from an OpenAPI specification?

What are the best tools for generating TypeScript types from an OpenAPI specification? #

TypeScript has become the dominant language for frontend and full-stack JavaScript development, and one of its most powerful features is its static type system. When working with REST APIs described by OpenAPI specifications, generating TypeScript types directly from the spec eliminates an entire class of runtime errors caused by type mismatches between the API and its consumers. Rather than manually maintaining type definitions that can drift from the actual API, teams can generate them automatically and keep them in sync as the API evolves. This article surveys the best tools available for generating TypeScript types from OpenAPI specifications.

Why Generate TypeScript Types from OpenAPI? #

Manually writing TypeScript interfaces for API request and response bodies is error-prone and tedious. When the API changes, manually-maintained types may not be updated in sync, leading to silent runtime bugs that TypeScript’s type system would have caught. Generating types from the OpenAPI specification ensures:

  • Accuracy — types exactly reflect the API schema as described in the specification.
  • Consistency — every consumer of the API uses the same type definitions.
  • Productivity — developers get IDE autocompletion and type checking for API payloads out of the box.
  • Change detection — regenerating types after an API update immediately surfaces TypeScript compilation errors at call sites that are affected by the change.

1. openapi-typescript #

openapi-typescript is the most popular dedicated TypeScript type generator for OpenAPI. It generates pure TypeScript types (no runtime code) from OpenAPI 2.0, 3.0, and 3.1 documents. Its key advantage is that it produces lean, readable type definitions that don’t require any runtime dependency.

Installation and Usage #

npm install -D openapi-typescript typescript
npx openapi-typescript openapi.yaml -o src/types/api.d.ts

It also supports remote URLs:

npx openapi-typescript https://api.example.com/openapi.yaml -o src/types/api.d.ts

Generated Output #

For a schema like:

components:
  schemas:
    User:
      type: object
      required: [id, email]
      properties:
        id:
          type: string
          format: uuid
        email:
          type: string
          format: email
        name:
          type: string

openapi-typescript generates:

export interface components {
  schemas: {
    User: {
      id: string;
      email: string;
      name?: string;
    };
  };
}

openapi-fetch: Type-Safe Fetch Client #

openapi-typescript pairs with openapi-fetch, a tiny fetch wrapper that uses the generated types to enforce type safety on every API call:

import createClient from "openapi-fetch";
import type { paths } from "./types/api.d.ts";

const client = createClient<paths>({ baseUrl: "https://api.example.com" });

const { data, error } = await client.GET("/users/{id}", {
  params: { path: { id: "123" } },
});
// data is typed as the 200 response body
// error is typed as the error response body

This approach is particularly appealing to teams that prefer a thin, zero-dependency fetch wrapper over a full SDK generator.

2. openapi-generator (TypeScript Clients) #

openapi-generator is the most comprehensive code generator in the OpenAPI ecosystem, supporting over 50 client generators including multiple TypeScript targets:

  • typescript-fetch — generates a fetch-based client.
  • typescript-axios — generates an Axios-based client.
  • typescript-angular — generates an Angular service using HttpClient.
  • typescript-node — generates a Node.js client.

Usage #

npx @openapitools/openapi-generator-cli generate \
  -i openapi.yaml \
  -g typescript-fetch \
  -o src/api-client

The generated code includes model interfaces, API class methods, and request/response serialization. It supports advanced configuration via --additional-properties flags to control naming conventions, enum style, and more.

openapi-generator is the right choice when teams need a complete, batteries-included API client rather than just type definitions.

3. Hey API (formerly openapi-ts) #

Hey API (the @hey-api/openapi-ts package) is a modern OpenAPI client generator with a focus on TypeScript ergonomics and configurability. It supports OpenAPI 2.0, 3.0, and 3.1 and can generate:

  • TypeScript types for schemas, parameters, and responses.
  • HTTP client code for fetch, Axios, or custom transports.
  • TanStack Query (React Query) integration hooks.
  • Zod schema validation code.
npm install -D @hey-api/openapi-ts
npx openapi-ts --input openapi.yaml --output src/client --client fetch

Hey API’s plugin architecture allows teams to compose exactly the output they need, making it highly flexible for modern React and Next.js applications.

4. Orval #

Orval is a TypeScript client generator built specifically for React and Vue ecosystems. It generates typed API clients along with integration hooks for popular data-fetching libraries:

npm install -D orval
npx orval --input openapi.yaml --output src/api

Orval is ideal for teams building React or Vue frontends who want not just types but ready-to-use data-fetching hooks that match the API’s operations. Configuration is done via an orval.config.ts file with fine-grained control over output structure, naming, and mock generation.

5. Zodios #

Zodios takes a unique approach: instead of generating TypeScript interfaces, it generates Zod schemas — runtime validators that also serve as the source for TypeScript types. This provides both compile-time type safety and runtime validation of API responses in a single step.

The openapi-zod-client companion package generates Zodios-compatible clients from OpenAPI documents:

npx openapi-zod-client openapi.yaml -o src/api-client.ts

The generated client validates responses at runtime, catching API contract violations that TypeScript alone cannot detect.

6. Kiota (Microsoft) #

Kiota is Microsoft’s open-source API client generator designed for the Microsoft Graph SDK but generalized for any OpenAPI 3.x API. It supports TypeScript alongside C#, Java, Go, Python, PHP, and Ruby.

Kiota generates a fluent, resource-oriented client with a distinctive API style:

const client = createApiClient(requestAdapter);
const user = await client.users.byUserId("123").get();

It emphasizes minimal generated code by using a shared core library (@microsoft/kiota-abstractions) rather than generating boilerplate for every SDK. Kiota is particularly well-suited for enterprise environments already using Microsoft tooling.

Choosing the Right Tool #

ToolBest ForRuntime CodeValidation
openapi-typescript + openapi-fetchLightweight types + fetchMinimalNo
openapi-generatorFull clients, many languagesYesNo
Hey APIModern TS + React Query/ZodConfigurableOptional
OrvalReact/Vue + Query hooksYesNo
Zodios / openapi-zod-clientRuntime validation + typesYesYes (Zod)
KiotaEnterprise, fluent clientsYes (shared lib)No

Integrating into a Build Pipeline #

Type generation should be part of the automated build process so that types are always in sync with the latest API specification:

// package.json
{
  "scripts": {
    "generate:api": "openapi-typescript openapi.yaml -o src/types/api.d.ts",
    "prebuild": "npm run generate:api"
  }
}

In CI, the generated types can be committed and any diff between the committed types and freshly generated types can be used to detect API changes that were not reflected in the type definitions.

Conclusion #

Generating TypeScript types from OpenAPI specifications is one of the highest-leverage practices for frontend and full-stack teams consuming REST APIs. Tools like openapi-typescript, Hey API, and Orval make it straightforward to maintain accurate, up-to-date types with minimal effort. By integrating type generation into the build pipeline, teams eliminate an entire category of API integration bugs and dramatically improve the developer experience for anyone consuming the API.


Last updated on April 29, 2026.

This website is not affiliated with the OpenAPI Initiative.