Adding custom code
This page covers how to add custom logic, methods, and dependencies to your TypeScript SDK.
.fernignore
file.Adding custom logic
To get started adding custom code:
Adding custom SDK methods
Fern also allows you to add custom methods to the SDK itself (e.g.
client.my_method()
) by inheriting the Fern generated client and then
extending it.
Update generators.yml
configuration
Name your Fern-generated client something like BaseClient
to reflect that this client will be extended.
Adding custom client configuration
The Java SDK generator supports builder extensibility through an opt-in self-type pattern. When enabled via the enable-extensible-builders
flag, generated builders can be extended while maintaining type safety during method chaining.
Common use cases include:
- Dynamic URL construction: Replace placeholders with runtime values (e.g.,
https://api.${TENANT}.example.com
) - Custom authentication: Implement complex auth flows beyond basic token authentication
- Request transformation: Add custom headers or modify requests globally
- Multi-tenant support: Add tenant-specific configuration and headers
Default implementation
If you don’t need to extend the builder, use the provided Impl
class:
Method reference
Each method serves a specific purpose and is only generated when needed:
Common patterns
Multi-tenant URLs
Dynamic authentication
Environment variable expansion
Request tracking
Requirements
- Fern Java SDK version: 2.39.6 or later
- Configuration:
enable-extensible-builders: true
ingenerators.yml
Adding custom dependencies
To add packages that your custom code requires, update your generators.yml
.