Skip to content

Commit c5c3acc

Browse files
committed
add new page on serde layer
1 parent bdd82a3 commit c5c3acc

File tree

3 files changed

+70
-19
lines changed

3 files changed

+70
-19
lines changed

fern/products/sdks/overview/typescript/configuration.mdx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ description: Configuration options for the Fern TypeScript SDK.
55

66
You can customize the behavior of the TypeScript SDK generator in `generators.yml`:
77

8-
```yml {7-8} title="generators.yml"
8+
```yml {7-9} title="generators.yml"
99
default-group: local
1010
groups:
11-
local:
11+
ts-sdk:
1212
generators:
1313
- name: fernapi/fern-typescript-sdk
1414
version: <Markdown src="/snippets/version-number-ts.mdx"/>
1515
config:
1616
namespaceExport: Acme
17+
noSerdeLayer: false
1718
```
1819

1920
## SDK configuration options
2021

2122
<ParamField path="allowExtraFields" type="boolean" toc={true}>
2223
Allow fields that are not defined in object schemas. This only applies to serde.
24+
25+
See [TypeScript serde layer](/sdks/generators/typescript/serde-layer) for more information.
2326
</ParamField>
2427

2528
<ParamField path="bundle" type="boolean" toc={true}>
@@ -323,18 +326,11 @@ Prevent the generator from running any scripts such as `yarn format` or `yarn in
323326
</ParamField>
324327

325328
<ParamField path="noSerdeLayer" type="boolean" default="true" toc={true}>
329+
Controls whether the serde layer is enabled for serialization/deserialization.
326330

327-
No serialization/deserialization code is generated by default. The client uses `JSON.parse()` and `JSON.stringify()` instead of the default Serde layer.
328-
329-
When `noSerdeLayer: false`, the generated client includes a layer for serializing requests and deserializing responses. This has three benefits:
330-
331-
1. The client validates requests and response at runtime (client-side).
332-
333-
1. The client can support complex types like `Date` and `Set`.
334-
335-
1. The generated types can stray from the wire/JSON representation to be more
336-
idiomatic. For example, when the Serde layer is enabled (`noSerdeLayer: false`), all properties are `camelCase`, even if the server is expecting `snake_case`.
331+
When `noSerdeLayer: false`, the generated client includes custom serialization code that transforms property names to camelCase, validates requests/responses at runtime, and supports complex types.
337332

333+
See [TypeScript serde layer](/sdks/generators/typescript/serde-layer) for detailed guidance on when to enable this option.
338334
</ParamField>
339335

340336
<ParamField path="outputSourceFiles" type="boolean" default="true" toc={true}>
@@ -444,10 +440,10 @@ The default is `web`.
444440
<ParamField path="useBigInt" type="boolean" default="false" toc={true}>
445441
When `useBigInt` is set to `true`, a customized JSON serializer & deserializer is used that will preserve the precision of `bigint`'s, as opposed to the native `JSON.stringify` and `JSON.parse` function which converts `bigint`'s to number's losing precision.
446442

447-
When combining `useBigInt` with our serialization layer (`no-serde: false`), both the request and response properties that are marked as `long` and `bigint` in OpenAPI/Fern spec, will consistently be `bigint`'s.
448-
However, when disabling the serialization layer (`no-serde: true`), they will be typed as `number | bigint`.
443+
When combining `useBigInt` with our serialization layer (`noSerdeLayer: false`), both the request and response properties that are marked as `long` and `bigint` in OpenAPI/Fern spec, will consistently be `bigint`'s.
444+
However, when disabling the serialization layer (`noSerdeLayer: true`), they will be typed as `number | bigint`. See [TypeScript serde layer](/sdks/generators/typescript/serde-layer) for more information.
449445

450-
Here's an overview of what to expect from the generated types when combining `useBigInt` and `noSerde` with the following Fern definition:
446+
Here's an overview of what to expect from the generated types when combining `useBigInt` and `noSerdeLayer` with the following Fern definition:
451447

452448
*Fern definition*:
453449

@@ -463,28 +459,28 @@ types:
463459

464460
```typescript
465461
// useBigInt: true
466-
// noSerde: false
462+
// noSerdeLayer: false
467463
interface ObjectWithLongAndBigInt {
468464
longProp: bigint;
469465
bigIntProp: bigint;
470466
}
471467
472468
// useBigInt: true
473-
// noSerde: true
469+
// noSerdeLayer: true
474470
interface ObjectWithLongAndBigInt {
475471
longProp: bigint | number;
476472
bigIntProp: bigint | number;
477473
}
478474
479475
// useBigInt: false
480-
// noSerde: false
476+
// noSerdeLayer: false
481477
interface ObjectWithLongAndBigInt {
482478
longProp: number;
483479
bigIntProp: string;
484480
}
485481
486482
// useBigInt: false
487-
// noSerde: true
483+
// noSerdeLayer: true
488484
interface ObjectWithLongAndBigInt {
489485
longProp: number;
490486
bigIntProp: string;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: TypeScript serde layer
3+
description: Control how your API naming conventions are transformed in the generated TypeScript SDK
4+
---
5+
6+
Fern's TypeScript SDK generator includes an optional serde layer that determines whether the generated SDK matches your original API naming conventions (snake_case vs. camelCase, case-sensitive fields) or follows TypeScript conventions. This serde layer is controlled by the `noSerdeLayer` option.
7+
8+
By default, the serde layer is **disabled** (`noSerdeLayer: true`), meaning field names are preserved exactly as they appear in your API specification.
9+
10+
## When to enable the serde layer
11+
12+
```yaml title="generators.yml" {7}
13+
groups:
14+
ts-sdk:
15+
generators:
16+
- name: fernapi/fern-typescript-sdk
17+
version: <Markdown src="/snippets/version-number-ts.mdx"/>
18+
config:
19+
noSerdeLayer: false # Enable serde layer
20+
```
21+
22+
When you turn on the serde layer, (`noSerdeLayer: false`), the TypeScript SDK generator includes custom serialization code that:
23+
- Transforms all property names from your API to camelCase
24+
- Validates requests and responses at runtime
25+
- Supports complex types like `Date` and `Set`.
26+
27+
Enable the serde layer when you want idiomatic TypeScript conventions and don't have case-sensitive field conflicts. Keep it disabled when your API has fields that differ only by casing or when you need exact field name preservation.
28+
29+
## Additional configuration options
30+
31+
Several configuration options work alongside an enabled serde layer:
32+
- `skipResponseValidation` disables the serde layer's runtime validation while keeping its transformation features
33+
- `allowExtraFields` permits properties not defined in your schema.
34+
- `useBigInt` enables custom JSON handling to preserve large number precision.
35+
36+
These options only take effect when the serde layer is enabled (`noSerdeLayer: false`), as they require the custom serialization infrastructure.
37+
38+
```yaml title="generators.yml" {7-10}
39+
groups:
40+
ts-sdk:
41+
generators:
42+
- name: fernapi/fern-typescript-sdk
43+
version: <Markdown src="/snippets/version-number-ts.mdx"/>
44+
config:
45+
noSerdeLayer: false # Enable serde layer
46+
skipResponseValidation: true # Disable runtime validation errors
47+
allowExtraFields: true # Allow undefined fields in responses
48+
useBigInt: true # Preserve precision for large numbers
49+
```
50+
51+
For the complete list of all TypeScript configuration options, go to [TypeScript configuration](/sdks/generators/typescript/configuration).
52+

fern/products/sdks/sdks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ navigation:
3939
- page: Adding custom code
4040
path: ./overview/typescript/custom-code.mdx
4141
slug: custom-code
42+
- page: Enabling the serde layer
43+
path: ./overview/typescript/serde-layer.mdx
44+
slug: serde-layer
4245
- changelog: ./overview/typescript/changelog
4346
slug: changelog
4447
- link: Customer showcase

0 commit comments

Comments
 (0)