Skip to main content

Package Manager Installation

Install @hey-api/openapi-ts as a dev dependency using your preferred package manager:
The -E flag (or --save-exact) pins the exact version. This is recommended due to the package being in initial development (see Versioning).

Requirements

OpenAPI TypeScript has minimal requirements:
  • Node.js: >=20.19.0
  • TypeScript: >=5.5.3 (peer dependency)
You can verify your Node.js version:
If you need to upgrade Node.js, we recommend using nvm or fnm.

Versioning

This package is in initial development (v0.x.x). Breaking changes may occur between minor versions.
To safely upgrade:
  1. Pin exact versions using the -E flag when installing
  2. Review migration notes before upgrading
  3. Test thoroughly after upgrading

Migration Notes

We publish detailed migration notes for every breaking release. You might not be impacted by a breaking change if you don’t use the affected features. Check the migration guide when upgrading:

Adding to package.json Scripts

After installation, add a script to your package.json to make the CLI easily accessible:
package.json
Now you can run the generator with:
You can customize the script name to match your workflow, such as "generate:client" or "codegen".

Basic Setup

After installation, create a configuration file to define your code generation settings.

Configuration File

OpenAPI TypeScript supports multiple configuration file formats. The most common is openapi-ts.config.ts:

Running the Generator

With the configuration file in place, run the generator:
The generator will read your configuration and create the output files in the specified directory.

Programmatic Usage

You can also use OpenAPI TypeScript programmatically in Node.js:
script.ts
Run your script:
This is useful for:
  • Custom build pipelines
  • Dynamic configuration
  • Integration with other tools
  • CI/CD workflows

Verification

Verify the installation by checking the version:
You should see output like:

Project Structure

Here’s a typical project structure after installation:
Add the output directory (e.g., src/client/) to your .gitignore if you regenerate it as part of your build process. Otherwise, commit it if other developers need the generated code.

TypeScript Configuration

Ensure your tsconfig.json is configured for ESM modules:
tsconfig.json

Watch Mode

During development, you can enable watch mode to automatically regenerate code when your OpenAPI specification changes:
Or configure it in your config file:
openapi-ts.config.ts

Multiple Configurations

You can generate multiple clients from different OpenAPI specifications:
openapi-ts.config.ts

Next Steps

Configuration

Learn about all configuration options

Quick Start

Generate your first client

Plugins

Explore available plugins

HTTP Clients

Choose your HTTP client