跳转到内容
Host your specs. Generate from anywhere.

Output

此内容尚不支持你的语言。

You must set the output so we know where to generate your files.

Output can be a path to the destination folder or an object containing the destination folder path and optional settings.

export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
};

You can learn more about complex use cases in the Advanced section.

Control how files are named and annotated in the generated output.

You can customize the naming and casing pattern for files using the fileName option.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
fileName: '{{name}}',
path: 'src/client',
},
};

By default, we append every file name with a .gen suffix to highlight it’s automatically generated. You can customize or disable this suffix using the fileName.suffix option.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
fileName: {
suffix: '.gen',
},
path: 'src/client',
},
};

The generated output includes a notice in every file warning that any modifications will be lost when the files are regenerated. You can customize or disable this notice using the header option.

index.gen.ts
/* eslint-disable */
// This file is auto-generated by @hey-api/openapi-ts
/** ... */

Control how module specifiers are generated in the output.

Set module.extension to define the file extension used in import specifiers. This is useful when targeting environments that require fully specified imports (e.g., Node ESM or certain bundlers).

index.gen.ts
import foo from './foo.js';
import bar from './bar.js';

Use module.resolve for full control over how module specifiers are generated. This lets you override specific modules or redirect them to custom locations (e.g., CDNs or internal aliases).

index.gen.ts
import * as z from 'https://esm.sh/zod';

Source is a copy of the input specification used to generate your output. It can be used to power documentation tools or to persist a stable snapshot alongside your generated files.

Enabling the source option with true creates a source.json file in your output folder.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
path: 'src/client',
source: true,
},
};

You can customize the file name and location using fileName and path. For example, this configuration will create an openapi.json file inside src/client/source directory.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
path: 'src/client',
source: {
fileName: 'openapi',
path: './source',
},
},
};

To use the source without writing it to disk, you can provide a callback function. This is useful for logging or integrating with external systems.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
path: 'src/client',
source: {
callback: (source) => console.log(source),
path: null,
},
},
};

Post-processing allows you to run commands on the generated output folder after files are written. This is typically used to run formatters, linters, or other cleanup tools.

Commands are executed in order, and each command receives the output path via the path placeholder.

You can use built-in presets for common tools:

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
path: 'src/client',
postProcess: ['biome:check'],
},
};

You can also provide custom post processors:

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
path: 'src/client',
postProcess: [
{
command: 'dprint',
args: ['fmt', '{{path}}'],
},
],
},
};

You can skip processing by adding the output path to the tool’s ignore file (for example .eslintignore or .prettierignore).

As your project grows, the chances of name conflicts increase. We use a simple conflict resolver that appends numeric suffixes to duplicate identifiers. If you prefer a different strategy, you can provide your own nameConflictResolver function.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
nameConflictResolver({ attempt, baseName }) {
return attempt === 0 ? baseName : `${baseName}_N${attempt + 1}`;
},
path: 'src/client',
},
};

We use the TSConfig file to generate output matching your project’s settings. By default, we attempt to find a TSConfig file starting from the location of the @hey-api/openapi-ts configuration file and traversing up.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
path: 'src/client',
tsConfigPath: undefined,
},
};

By default, you can’t keep custom files in the path folder because it’s emptied on every run. If you’re sure you need to disable this behavior, set clean to false.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
clean: false,
path: 'src/client',
},
};

Examples

You can view live examples on StackBlitz or on GitHub.