Skip to content

Commit 9116614

Browse files
committed
Update configuration.mdx based on issue #266
1 parent f56806d commit 9116614

File tree

1 file changed

+109
-203
lines changed

1 file changed

+109
-203
lines changed

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

Lines changed: 109 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ groups:
1111
local:
1212
generators:
1313
- name: fernapi/fern-typescript-sdk
14-
version: <Markdown src="/snippets/version-number-ts.mdx"/>
14+
version: <Markdown src="/snippets/version-number-ts.mdx" />
1515
config:
1616
namespaceExport: Acme
1717
```
@@ -96,7 +96,6 @@ config:
9696
extraDependencies:
9797
lodash: "3.0.2"
9898
```
99-
10099
</ParamField>
101100

102101
<ParamField path="extraDevDependencies" type="object" default="{}" toc={true}>
@@ -130,9 +129,40 @@ Specify extra peer dependencies meta fields in the generated `package.json`:
130129
```yaml
131130
# generators.yml
132131
config:
133-
extraPeerDependencies:
134-
react: ">=16.8.0 <19.0.0"
135-
"react-dom": ">=16.8.0 <19.0.0"
132+
extraPeerDependenciesMeta:
133+
react:
134+
optional: true
135+
"react-dom":
136+
optional: true
137+
```
138+
</ParamField>
139+
140+
<ParamField path="extensionHeaders" type="object" toc={true}>
141+
Define custom request headers to be included in all API requests:
142+
143+
```yaml
144+
# generators.yml
145+
config:
146+
extensionHeaders:
147+
x-project-id: project_id
148+
```
149+
150+
The header value is derived from the variable name specified, which can be defined using `x-fern-sdk-variables` in your OpenAPI spec:
151+
152+
```yaml
153+
# openapi.yml
154+
x-fern-sdk-variables:
155+
project_id:
156+
type: string
157+
description: The project ID to use for all requests
158+
```
159+
160+
This will generate a client that accepts the variable in its constructor:
161+
162+
```typescript
163+
const client = new ApiClient({
164+
projectId: "my-project-id"
165+
});
136166
```
137167
</ParamField>
138168

@@ -165,7 +195,6 @@ Choose whether you want to support Node.js 16 and above (`Node16`), or Node.js 1
165195
</ParamField>
166196

167197
<ParamField path="includeContentHeadersOnFileDownloadResponse" type="boolean" toc={true}>
168-
169198
Includes the content type and content length from binary responses. The user will receive an object of the following type:
170199

171200
```typescript
@@ -238,7 +267,6 @@ public async post(
238267
...
239268
}
240269
```
241-
242270
</ParamField>
243271

244272
<ParamField path="inlinePathParameters" type="boolean" default="true" toc={true}>
@@ -254,28 +282,26 @@ await service.getFoo("pathParamValue", { id: "SOME_ID" });
254282
```typescript
255283
await service.getFoo({ pathParamName: "pathParamValue", id: "SOME_ID" });
256284
```
257-
258285
</ParamField>
259286

260287
<ParamField path="namespaceExport" type="string" toc={true}>
261288
By default, names are based on the organization and API names in the Fern Definition:
262289

263-
```typescript
264-
import { AcmeApi, AcmeApiClient } from "@acme/node";
265-
```
266-
267-
`namespaceExport` customizes the exported namespace and client names:
290+
```typescript
291+
import { AcmeApi, AcmeApiClient } from "@acme/node";
292+
```
268293

269-
```yaml
270-
# generators.yml
271-
config:
272-
namespaceExport: Acme
273-
```
294+
`namespaceExport` customizes the exported namespace and client names:
274295

275-
```typescript
276-
import { Acme, AcmeClient } from "@acme/node";
277-
```
296+
```yaml
297+
# generators.yml
298+
config:
299+
namespaceExport: Acme
300+
```
278301

302+
```typescript
303+
import { Acme, AcmeClient } from "@acme/node";
304+
```
279305
</ParamField>
280306

281307
<ParamField path="neverThrowErrors" type="boolean" default="false" toc={true}>
@@ -294,47 +320,44 @@ By default, names are based on the organization and API names in the Fern Defini
294320
<ParamField path="noOptionalProperties" type="boolean" default="false" toc={true}>
295321
By default, Fern's `optional<>` properties will translate to optional TypeScript properties:
296322

297-
```yaml {4}
298-
Person:
299-
properties:
300-
name: string
301-
age: optional<integer>
302-
```
303-
304-
```typescript {3}
305-
interface Person {
306-
name: string;
307-
age?: number;
308-
}
309-
```
310-
311-
When `noOptionalProperties` is enabled, the generated properties are never optional. Instead, the type is generated with `| undefined`. As a result, users must explicitly set the property to a value or `undefined`.
312-
313-
```typescript {3}
314-
interface Person {
315-
name: string;
316-
age: number | undefined;
317-
}
318-
```
323+
```yaml {4}
324+
Person:
325+
properties:
326+
name: string
327+
age: optional<integer>
328+
```
329+
330+
```typescript {3}
331+
interface Person {
332+
name: string;
333+
age?: number;
334+
}
335+
```
336+
337+
When `noOptionalProperties` is enabled, the generated properties are never optional. Instead, the type is generated with `| undefined`. As a result, users must explicitly set the property to a value or `undefined`.
338+
339+
```typescript {3}
340+
interface Person {
341+
name: string;
342+
age: number | undefined;
343+
}
344+
```
319345
</ParamField>
320346

321347
<ParamField path="noScripts" type="boolean" toc={true}>
322348
Prevent the generator from running any scripts such as `yarn format` or `yarn install`. If any of the scripts cause errors, toggling this option will allow you to receive the generated code.
323349
</ParamField>
324350

325351
<ParamField path="noSerdeLayer" type="boolean" default="true" toc={true}>
326-
327352
No serialization/deserialization code is generated by default. The client uses `JSON.parse()` and `JSON.stringify()` instead of the default Serde layer.
328353

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).
354+
When `noSerdeLayer: false`, the generated client includes a layer for serializing requests and deserializing responses. This has three benefits:
332355

333-
1. The client can support complex types like `Date` and `Set`.
356+
1. The client validates requests and response at runtime (client-side).
334357

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`.
358+
2. The client can support complex types like `Date` and `Set`.
337359

360+
3. The generated types can stray from the wire/JSON representation to be more idiomatic. For example, when the Serde layer is enabled (`noSerdeLayer: false`), all properties are `camelCase`, even if the server is expecting `snake_case`.
338361
</ParamField>
339362

340363
<ParamField path="outputSourceFiles" type="boolean" default="true" toc={true}>
@@ -373,46 +396,45 @@ generate a `jsr.json` as well as a GitHub workflow to publish to JSR.
373396
<ParamField path="retainOriginalCasing" type="boolean" default="false" toc={true}>
374397
When enabled, property names in the generated code retain their original casing from the API definition instead of being converted to camelCase.
375398

376-
```yaml
377-
# generators.yml
378-
config:
379-
retainOriginalCasing: true
380-
```
381-
382-
**Example with OpenAPI input:**
383-
```yaml {7, 9}
384-
# OpenAPI schema
385-
components:
386-
schemas:
387-
User:
388-
type: object
389-
properties:
390-
user_id:
391-
type: string
392-
display_name:
393-
type: string
394-
```
395-
396-
Generated TypeScript with `retainOriginalCasing: true`:
397-
```typescript {2-3}
398-
export interface User {
399-
user_id: string;
400-
display_name: string;
401-
}
402-
```
403-
404-
Generated TypeScript with default settings (`retainOriginalCasing: false`):
405-
```typescript {2-3}
406-
export interface User {
407-
userId: string;
408-
displayName: string;
409-
}
410-
```
399+
```yaml
400+
# generators.yml
401+
config:
402+
retainOriginalCasing: true
403+
```
404+
405+
**Example with OpenAPI input:**
406+
```yaml {7, 9}
407+
# OpenAPI schema
408+
components:
409+
schemas:
410+
User:
411+
type: object
412+
properties:
413+
user_id:
414+
type: string
415+
display_name:
416+
type: string
417+
```
411418

419+
Generated TypeScript with `retainOriginalCasing: true`:
420+
```typescript {2-3}
421+
export interface User {
422+
user_id: string;
423+
display_name: string;
424+
}
425+
```
426+
427+
Generated TypeScript with default settings (`retainOriginalCasing: false`):
428+
```typescript {2-3}
429+
export interface User {
430+
userId: string;
431+
displayName: string;
432+
}
433+
```
412434
</ParamField>
413435

414436
<ParamField path="shouldGenerateWebsocketClients" type="boolean" toc={true}>
415-
Generate WebSocket clients from your AsyncAPI specs.
437+
Generate WebSocket clients from your AsyncAPI specs.
416438
</ParamField>
417439

418440
<ParamField path="skipResponseValidation" type="boolean" default="false" toc={true}>
@@ -423,122 +445,6 @@ Fern Definition).
423445
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).
424446

425447
<Warning>Response validation only occurs when the Serde layer is enabled (`noSerdeLayer: false`). The Serde layer is disabled by default (`noSerdeLayer: true`).</Warning>
426-
427-
</ParamField>
428-
429-
<ParamField path="streamType" type="'wrapper' | 'web'" toc={true}>
430-
Change the type of stream that is used in the generated SDK.
431-
432-
* `wrapper`: The streams use a wrapper with multiple underlying implementations to support versions of Node.js before Node.js 18.
433-
* `web`: The streams use the web standard `ReadableStream`.
434-
435-
The default is `web`.
436-
</ParamField>
437-
438-
<ParamField path="treatUnknownAsAny" type="boolean" default="false" toc={true}>
439-
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).
440-
</ParamField>
441-
442-
<ParamField path="useBigInt" type="boolean" default="false" toc={true}>
443-
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*:
451-
452-
```yaml
453-
types:
454-
ObjectWithOptionalField:
455-
properties:
456-
longProp: long
457-
bigIntProp: bigint
458-
```
459-
460-
*TypeScript output*:
461-
462-
```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-
}
490-
```
491448
</ParamField>
492449

493-
<ParamField path="useBrandedStringAliases" type="boolean" default="false" toc={true}>
494-
495-
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
537-
printMyString(otherString);
538-
539-
// compiles
540-
const myString = MyString("my-string");
541-
printMyString(myString);
542-
```
543-
544-
</ParamField>
450+
<ParamField path="streamType" type="'wrapper' | 'web'" toc={

0 commit comments

Comments
 (0)