Configuration ​
@hey-api/openapi-ts
supports loading configuration from any file inside your project root folder supported by jiti loader. Below are the most common file formats.
import { defineConfig } from '@hey-api/openapi-ts';
export default defineConfig({
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: 'src/client',
});
/** @type {import('@hey-api/openapi-ts').UserConfig} */
module.exports = {
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: 'src/client',
};
/** @type {import('@hey-api/openapi-ts').UserConfig} */
export default {
client: '@hey-api/client-fetch',
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.
Input ​
Input is the first thing you must define. It can be a local path, remote URL, or a string content resolving to an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
INFO
We use @apidevtools/json-schema-ref-parser
to resolve file locations. Please note that accessing a HTTPS URL on localhost has a known workaround.
Output ​
Output is the next thing to define. It can be either a string pointing to the destination folder or a configuration object containing the destination folder path and optional settings (these are described below).
TIP
You should treat the output folder as a dependency. Do not directly modify its contents as your changes might be erased when you run @hey-api/openapi-ts
again.
Formatting ​
To format your output folder contents, set output.format
to a valid formatter.
export default {
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: {
format: false,
path: 'src/client',
},
};
export default {
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: {
format: 'prettier',
path: 'src/client',
},
};
export default {
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: {
format: 'biome',
path: 'src/client',
},
};
You can also prevent your output from being formatted by adding your output path to the formatter's ignore file.
Linting ​
To lint your output folder contents, set output.lint
to a valid linter.
export default {
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: {
lint: false,
path: 'src/client',
},
};
export default {
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: {
lint: 'eslint',
path: 'src/client',
},
};
export default {
client: '@hey-api/client-fetch',
input: 'path/to/openapi.json',
output: {
lint: 'biome',
path: 'src/client',
},
};
You can also prevent your output from being linted by adding your output path to the linter's ignore file.
Clients ​
Clients are responsible for sending the actual HTTP requests. The client
value is not required, but you must define it if you're generating the service layer (enabled by default).
You can learn more on the Clients page.
Plugins ​
Plugins are responsible for generating artifacts from your input. By default, Hey API will generate TypeScript interfaces, JSON Schemas, and services from your OpenAPI specification. You can add, remove, or customize any of the plugins. In fact, we highly encourage you to do so!
You can learn more on the Output page.
Config API ​
You can view the complete list of options in the UserConfig interface.
Examples ​
You can view live examples on StackBlitz.
Sponsoring ​
Love Hey API? Please consider becoming a sponsor.