Skip to main content
The @hey-api/transformers plugin generates runtime transformers that convert response data into desired formats. This is useful for transforming ISO date strings into Date objects, converting large integers into BigInt values, or applying custom transformations.
Transformation adds runtime overhead. Only use when necessary.

Installation

The Transformers plugin is included when you install @hey-api/openapi-ts:

Configuration

Add the plugin to your openapi-ts.config.ts:

What It Generates

The Transformers plugin generates a transformers.gen.ts file containing functions that transform response data:

Configuration Options

dates

Convert date strings into Date objects.
boolean
default:"true"
Automatically transforms ISO 8601 date strings (format: date, date-time) into JavaScript Date objects.
Before transformation:
After transformation:

bigInt

Convert long integers into BigInt values.
boolean
default:"true"
Transforms integers with format int64 into BigInt values for precise large number handling.
Before transformation:
After transformation:

transformers

Add custom transformation logic.
Array<ExpressionTransformer>
default:"[]"
Array of custom transformer functions to apply to the generated code.

typeTransformers

Modify the TypeScript types generated for transformed data.
Array<TypeTransformer>
default:"[]"
Array of custom type transformer functions that modify the TypeScript types.

Built-in Transformations

Date/DateTime Transformation

Automatically enabled when dates: true (default). OpenAPI Schema:
Generated Type:
Generated Transformer:

BigInt Transformation

Automatically enabled when bigInt: true (default). OpenAPI Schema:
Generated Type:
Generated Transformer:

Use Cases

Working with Dates

Handling Large Numbers

Selective Transformations

Disable specific transformations you don’t need:

Common Patterns

Basic Date Transformation

Disable All Transformations

Custom Currency Transformer

Performance Considerations

Transformers add runtime overhead. Consider these best practices:
  1. Only transform when necessary - Disable transformations you don’t need
  2. Avoid deep transformations - Transformations traverse the entire object tree
  3. Use with caching - Consider memoizing transformed results
  4. Test performance - Measure impact on your application

Type Safety

When using transformers, the generated TypeScript types reflect the transformed data:
This ensures your code is type-safe and you get proper IDE autocomplete:

Export Configuration

By default, transformers are not included in the entry file (index.ts). To include them:

Next Steps

SDK Plugin

Use transformers with generated SDK functions.

TypeScript Plugin

Customize the generated TypeScript types.

Validators

Validate transformed data at runtime.

HTTP Clients

Choose an HTTP client for making requests.