Skip to content

Configuration

openapi-ts supports loading configuration from any file inside your project root directory supported by jiti loader. Below are the most common file formats.

js
import { defineConfig } from '@hey-api/openapi-ts'

export default defineConfig({
  input: 'path/to/openapi.json',
  output: 'src/client',
})
js
/** @type {import('@hey-api/openapi-ts').UserConfig} */
module.exports = {
  input: 'path/to/openapi.json',
  output: 'src/client',
}
js
/** @type {import('@hey-api/openapi-ts').UserConfig} */
export default {
  input: 'path/to/openapi.json',
  output: 'src/client',
}

Alternatively, you can use openapi-ts.config.js and configure the export statement depending on your project setup.

Clients

By default, openapi-ts will try to guess your client based on your project dependencies. If we don't get it right, you can specify the desired client

js
export default {
  client: 'fetch',
  input: 'path/to/openapi.json',
  output: 'src/client',
}
js
export default {
  client: 'axios',
  input: 'path/to/openapi.json',
  output: 'src/client',
}
js
export default {
  client: 'angular',
  input: 'path/to/openapi.json',
  output: 'src/client',
}
js
export default {
  client: 'node',
  input: 'path/to/openapi.json',
  output: 'src/client',
}
js
export default {
  client: 'xhr',
  input: 'path/to/openapi.json',
  output: 'src/client',
}

We support these clients:

We also support the legacy Node.js and XHR clients:

TIP

You might not need a node client. Fetch API is experimental in Node.js v18 and stable in Node.js v21. We recommend upgrading to the latest Node.js version.

Formatting

By default, openapi-ts will automatically format your client according to your project configuration. To disable automatic formatting, set format to false

js
export default {
  format: false,
  input: 'path/to/openapi.json',
  output: 'src/client',
}

You can also prevent your client from being processed by formatters by adding your output path to the tool's ignore file (e.g. .prettierignore).

Linting

For performance reasons, openapi-ts does not automatically lint your client. To enable this feature, set lint to true

js
export default {
  input: 'path/to/openapi.json',
  lint: true,
  output: 'src/client',
}

You can also prevent your client from being processed by linters by adding your output path to the tool's ignore file (e.g. .eslintignore).

Enums

If you need to iterate through possible field values without manually typing arrays, you can export enums with

js
export default {
  enums: 'javascript',
  input: 'path/to/openapi.json',
  output: 'src/client',
}

This will export enums as plain JavaScript objects. For example, Foo would become

js
export const FooEnum = {
  FOO: 'foo',
  BAR: 'bar',
} as const;

We discourage generating TypeScript enums because they are not standard JavaScript and pose typing challenges. If you really need TypeScript enums, you can export them with

js
export default {
  enums: 'typescript',
  input: 'path/to/openapi.json',
  output: 'src/client',
}

Config API

You can view the complete list of options in the UserConfig interface.