You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, the client will throw an error if the response from the server
420
-
doesn't match the expected type (based on how the response is modeled in the
421
-
Fern Definition).
422
-
423
-
If `skipResponseValidation` is set to `true`, the client will never throw if the response is misshapen. Instead, the client will log the issue using `console.warn` and return the data (casted to the expected response type).
424
-
425
-
<Warning>Response validation only occurs when the Serde layer is enabled (`noSerdeLayer: false`). The Serde layer is disabled by default (`noSerdeLayer: true`).</Warning>
When `treatUnknownAsAny` is enabled, [unknown types from Fern are generated into TypeScript using `any` instead of the `unknown` type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type).
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.
444
-
445
-
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.
446
-
However, when disabling the serialization layer (`no-serde: true`), they will be typed as `number | bigint`.
447
-
448
-
Here's an overview of what to expect from the generated types when combining `useBigInt` and `noSerde` with the following Fern definition:
449
-
450
-
*Fern definition*:
419
+
```yaml
420
+
# generators.yml
421
+
config:
422
+
sdkClientVariable: project_id
423
+
```
451
424
452
425
```yaml
453
-
types:
454
-
ObjectWithOptionalField:
455
-
properties:
456
-
longProp: long
457
-
bigIntProp: bigint
426
+
# OpenAPI spec
427
+
x-fern-sdk-variables:
428
+
project_id:
429
+
type: string
430
+
description: The project ID
431
+
pattern: "^proj_[a-zA-Z0-9]+$"
458
432
```
459
433
460
-
*TypeScript output*:
434
+
This allows injecting variables like project_id from the client constructor instead of requiring it on each request:
461
435
462
436
```typescript
463
-
// useBigInt: true
464
-
// noSerde: false
465
-
interface ObjectWithLongAndBigInt {
466
-
longProp: bigint;
467
-
bigIntProp: bigint;
468
-
}
469
-
470
-
// useBigInt: true
471
-
// noSerde: true
472
-
interface ObjectWithLongAndBigInt {
473
-
longProp: bigint | number;
474
-
bigIntProp: bigint | number;
475
-
}
476
-
477
-
// useBigInt: false
478
-
// noSerde: false
479
-
interface ObjectWithLongAndBigInt {
480
-
longProp: number;
481
-
bigIntProp: string;
482
-
}
483
-
484
-
// useBigInt: false
485
-
// noSerde: true
486
-
interface ObjectWithLongAndBigInt {
487
-
longProp: number;
488
-
bigIntProp: string;
489
-
}
437
+
const client = new ApiClient({ projectId: "proj_123" });
When `useBrandedStringAliases` is disabled (the default), string aliases are generated as
496
-
normal TypeScript aliases:
497
-
498
-
```typescript
499
-
// generated code
500
-
501
-
export type MyString = string;
502
-
503
-
export type OtherString = string;
504
-
```
505
-
When `useBrandedStringAliases` is enabled, string aliases are generated as branded strings. This makes each alias feel like its own type and improves compile-time safety.
506
-
507
-
```yaml
508
-
# fern definition
509
-
510
-
types:
511
-
MyString: string
512
-
OtherString: string
513
-
```
514
-
515
-
```typescript
516
-
// generated code
517
-
518
-
export type MyString = string & { __MyString: void };
519
-
export const MyString = (value: string): MyString => value as MyString;
520
-
521
-
export type OtherString = string & { __OtherString: void };
522
-
export const OtherString = (value: string): OtherString => value as OtherString;
523
-
```
524
-
525
-
```typescript
526
-
// consuming the generated type
527
-
528
-
function printMyString(s: MyString): void {
529
-
console.log("MyString: " + s);
530
-
}
531
-
532
-
// doesn't compile, "foo" is not assignable to MyString
533
-
printMyString("foo");
534
-
535
-
const otherString = OtherString("other-string");
536
-
// doesn't compile, otherString is not assignable to MyString
By default, the client will throw an error if the response from the server
449
+
doesn't match the expected type (based on how the response is modeled in the
450
+
Fern Definition).
543
451
544
-
</ParamField>
452
+
If `skipResponseValidation` is set to `true`, the client will never throw if the response is misshapen. Instead, the client will log the issue using `console.warn` and return the data (casted to the expected response type
0 commit comments