Skip to content
Host your specs. Generate from anywhere.

Parser

We parse your input before making it available to plugins. Configuring the parser is optional, but it provides an ideal opportunity to modify or validate your input as needed.

Sometimes you need to modify raw input before it’s processed further. A common use case is fixing an invalid specification or adding a missing field. For this reason, custom patches are applied before any parsing takes place.

You can add custom patches with patch.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
patch: {
schemas: {
Foo: (schema) => {
// convert date-time format to timestamp
delete schema.properties.updatedAt.format;
schema.properties.updatedAt.type = 'number';
},
Bar: (schema) => {
// add missing property
schema.properties.meta = {
additionalProperties: true,
type: 'object',
};
schema.required = ['meta'];
},
Baz: (schema) => {
// remove property
delete schema.properties.internalField;
},
},
},
},
};

If you don’t control or trust your input, you might want to validate it. Any detected errors in your input will exit @hey-api/openapi-ts and no plugins will be executed.

To validate your input, set validate_EXPERIMENTAL to true.

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

Filters allow you to trim your input before it’s processed further, so your output contains only relevant resources.

Set include to match operations to be included or exclude to match operations to be excluded. Both exact keys and regular expressions are supported. When both rules match the same operation, exclude takes precedence over include.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
filters: {
operations: {
include: ['GET /api/v1/foo', '/^[A-Z]+ /api/v1//'],
},
},
},
};

Set include to match tags to be included or exclude to match tags to be excluded. When both rules match the same tag, exclude takes precedence over include.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
filters: {
tags: {
include: ['v2'],
},
},
},
};

You can filter out deprecated resources by setting deprecated to false.

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

Set include to match schemas to be included or exclude to match schemas to be excluded. Both exact keys and regular expressions are supported. When both rules match the same schema, exclude takes precedence over include.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
filters: {
schemas: {
include: ['Foo', '/^Bar/'],
},
},
},
};

Set include to match parameters to be included or exclude to match parameters to be excluded. Both exact keys and regular expressions are supported. When both rules match the same parameter, exclude takes precedence over include.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
filters: {
parameters: {
include: ['QueryParameter', '/^MyQueryParameter/'],
},
},
},
};

Set include to match request bodies to be included or exclude to match request bodies to be excluded. Both exact keys and regular expressions are supported. When both rules match the same request body, exclude takes precedence over include.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
filters: {
requestBodies: {
include: ['Payload', '/^SpecialPayload/'],
},
},
},
};

Set include to match responses to be included or exclude to match responses to be excluded. Both exact keys and regular expressions are supported. When both rules match the same response, exclude takes precedence over include.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
filters: {
responses: {
include: ['Foo', '/^Bar/'],
},
},
},
};

If you only want to exclude orphaned resources, set orphans to false. This is the default value when combined with any other filters. If this isn’t the desired behavior, you may want to set orphans to true to always preserve unused resources.

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

For performance reasons, we don’t preserve the original order when filtering out resources. If maintaining the original order is important to you, set preserveOrder to true.

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

You can think of transforms as deterministic patches. They provide an easy way to apply the most commonly used input transformations.

Your input might contain two types of enums:

  • enums defined as reusable components (root enums)
  • non-reusable enums nested within other schemas (inline enums)

You may want all enums to be reusable. This is because only root enums are typically exported by plugins. Inline enums will never be directly importable since they’re nested inside other schemas.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
transforms: {
enums: 'root',
},
},
};

You can customize the naming and casing pattern for enums schemas using the .name and .case options.

By default, any object schema with a missing required keyword is interpreted as “no properties are required.” This is the correct behavior according to the OpenAPI standard. However, some specifications interpret a missing required keyword as “all properties should be required.”

This option allows you to change the default behavior so that properties are required by default unless explicitly marked as optional.

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

Your schemas might contain read-only or write-only fields. Using such schemas directly could mean asking the user to provide a read-only field in requests, or expecting a write-only field in responses. We separate schemas for requests and responses if direct usage would result in such scenarios.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
transforms: {
readWrite: {
requests: '{{name}}Writable',
responses: '{{name}}',
},
},
},
};

You can customize the naming and casing pattern for requests and responses schemas using the .name and .case options.

Sometimes your schema names are auto-generated or follow a naming convention that produces verbose or awkward type names. You can rename schema component keys throughout the specification, automatically updating all $ref pointers. For example, stripping version markers from schema names, removing vendor prefixes, converting naming conventions, or shortening deeply qualified names.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
transforms: {
schemaName: (name) => {
// Strip version markers: ServiceRoot_v1_20_0_ServiceRoot → ServiceRoot
let clean = name.replace(
/([A-Za-z\d]+)_v\d+_\d+_\d+_([A-Za-z\d]*)/g,
(_, p1, p2) => (p2.startsWith(p1) ? p2 : p1 + p2),
);
// Deduplicate prefixes: Foo_Foo → Foo
const m = clean.match(/^([A-Za-z\d]+)_\1([A-Za-z\d]*)$/);
if (m) clean = m[1] + m[2];
return clean;
},
},
},
};

Paginated operations are detected by having a pagination keyword in its parameters or request body. By default, we consider the following to be pagination keywords: after, before, cursor, offset, page, and start.

You can provide custom pagination keywords using pagination.keywords.

openapi-ts.config.ts
import { defaultPaginationKeywords } from '@hey-api/openapi-ts';
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
pagination: {
keywords: [
...defaultPaginationKeywords,
'extra',
'pagination',
'keywords',
],
},
},
};

Hooks affect runtime behavior but aren’t tied to any single plugin. They can be configured globally via hooks or per plugin through the ~hooks property.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
hooks: {}, // configure global hooks
},
};

We always use the first hook that returns a value. If a hook returns no value, we fall back to less specific hooks until one does.

Operations

Each operation has a list of classifiers that can include query, mutation, both, or none. Plugins may use these values to decide whether to generate specific output. For example, you usually don’t want to generate TanStack Query options for PATCH operations.

Query operations

By default, GET operations are classified as query operations.

Mutation operations

By default, DELETE, PATCH, POST, and PUT operations are classified as mutation operations.

Imagine your API has a POST /search endpoint that accepts a large payload. By default, it’s classified as a mutation, but in practice it behaves like a query, and your state management plugin should generate query hooks.

You can achieve this by classifying the operation as query in a matcher.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
hooks: {
operations: {
isQuery: (op) => {
if (op.method === 'post' && op.path === '/search') {
return true;
}
},
},
},
},
};

Symbols

Each symbol can have a placement function deciding its output location.

While we work on a better example, let’s imagine a world where it’s desirable to place every symbol in a file named after its initial letter. For example, a function named Foo should end up in the file f.ts.

You can achieve this by using the symbol’s name.

openapi-ts.config.ts
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
parser: {
hooks: {
symbols: {
getFilePath: (symbol) => {
if (symbol.name) {
return symbol.name[0]?.toLowerCase();
}
},
},
},
},
};

Most plugins expose configuration options that allow you to rename many of the generated symbols. If you need even more control, use the getName() hook.

By default, generated enums use the same name for both the type and the runtime value.

index.gen.ts
export const Flags = {
ALPHA: 'alpha',
BETA: 'beta',
} as const;
export type Flags = (typeof Flags)[keyof typeof Flags];

While this code works perfectly fine due to TypeScript’s declaration merging, let’s say we want to use a different name for the type. We can accomplish this with the getName() hook.

index.gen.ts
export const Flags = {
ALPHA: 'alpha',
BETA: 'beta',
} as const;
export type FlagsType = (typeof Flags)[keyof typeof Flags];

Examples

You can view live examples on StackBlitz or on GitHub.