@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.
Installation
The Transformers plugin is included when you install@hey-api/openapi-ts:
Configuration
Add the plugin to youropenapi-ts.config.ts:
What It Generates
The Transformers plugin generates atransformers.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.bigInt
Convert long integers into BigInt values.
boolean
default:"true"
Transforms integers with format
int64 into BigInt values for precise large number handling.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 whendates: true (default).
OpenAPI Schema:
BigInt Transformation
Automatically enabled whenbigInt: true (default).
OpenAPI Schema:
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
- Only transform when necessary - Disable transformations you don’t need
- Avoid deep transformations - Transformations traverse the entire object tree
- Use with caching - Consider memoizing transformed results
- Test performance - Measure impact on your application
Type Safety
When using transformers, the generated TypeScript types reflect the transformed data: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.