-
Notifications
You must be signed in to change notification settings - Fork 3
Add TypeScript configuration options #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6715e27
cde8cfe
95ed9a0
ef5f814
1148090
5448d5e
c53665a
743fcb2
f6d310d
3b89c97
e136086
ec3e8de
467cd1d
cf7b063
d879fba
21619d7
ff44678
6c1e677
9381dda
c443c1d
06b4dc1
17993e9
02ad8a8
1d518ab
0b6644c
0b59d2c
97b4817
0de0892
c26aa5e
76584a7
11cacfd
bd08ff3
e328f5b
9b25af2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,360 @@ title: Typescript Configuration | |
| description: Configuration options for the Fern Typescript SDK. | ||
| --- | ||
|
|
||
| # Typescript Configuration | ||
| You can customize the behavior of the TypeScript SDK generator in `generators.yml`: | ||
|
|
||
| ```yml {7-8} | ||
| default-group: local | ||
| groups: | ||
| local: | ||
| generators: | ||
| - name: fernapi/fern-typescript-node-sdk | ||
| version: 0.7.1 | ||
| config: | ||
| useBrandedStringAliases: true | ||
| ``` | ||
|
|
||
| ## SDK configuration options | ||
|
|
||
| <ParamField path="neverThrowErrors" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="outputEsm" type="boolean" default="false"> | ||
| By default, the generated TypeScript targets CommonJS. Setting to `true` targets `esnext` instead. | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="outputSourceFiles" type="boolean" default="false"> | ||
| When enabled, the generator outputs raw TypeScript files. When disabled (the default), outputs `.js` and `d.ts` files. | ||
|
|
||
| <Note>This only applies when dumping code locally. This configuration is ignored when publishing to Github or npm._ </Note> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="includeCredentialsOnCrossOriginRequests" type="boolean" default="false"> | ||
| When enabled, [`withCredentials`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials) is set to `true` when making network requests. | ||
| </ParamField> | ||
|
|
||
| <ParamField path="bundle" type="boolean"> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="allowCustomFetcher" type="boolean" default="false"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| When enabled, the generated client allows the end user to specify a custom fetcher implementation. | ||
|
|
||
| ```typescript | ||
| const acme = new AcmeClient({ | ||
| fetcher: (args) => { | ||
| ... | ||
| }, | ||
| }); | ||
| ``` | ||
| </ParamField> | ||
|
|
||
| <ParamField path="shouldGenerateWebsocketClients" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="defaultTimeoutInSeconds" type="number | 'infinity'"> | ||
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="skipResponseValidation" type="boolean" default="false"> | ||
| By default, the client will throw an error if the response from the server | ||
| doesn't match the expected type (based on how the response is modeled in the | ||
| Fern Definition). | ||
|
|
||
| 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). | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="extraDependencies" type="object" default="{}"> | ||
| Specify extra dependencies in the generated `package.json`. This is useful | ||
| when you utilize [`.fernignore`](https://buildwithfern.com/learn/sdks/capabilities/custom-code) to | ||
| supplement the generated client with custom code. | ||
|
|
||
| ```yaml | ||
| # generators.yml | ||
| config: | ||
| extraDependencies: | ||
| lodash: "3.0.2" | ||
| ``` | ||
|
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="extraDevDependencies" type="object" default="{}"> | ||
| Specify extra dev dependencies in the generated `package.json`. | ||
|
|
||
| ```yaml | ||
| # generators.yml | ||
| config: | ||
| extraDevDependencies: | ||
| jest: "29.0.7" | ||
| ``` | ||
|
|
||
| <Note>Only applies when publishing to Github.</Note> | ||
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="extraPeerDependencies" type="object"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="extraPeerDependenciesMeta" type="object"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="treatUnknownAsAny" type="boolean" default="false"> | ||
| In Fern, there's an `unknown` type that represents data that isn't knowable at runtime. When `treatUnknownAsAny` is enabled, unknown types from Fern are generated into TypeScript using `any` instead of the `unknown` type. | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="noOptionalProperties" type="boolean" default="false"> | ||
| By default, Fern's `optional<>` properties will translate to optional TypeScript properties: | ||
|
|
||
| ```yaml {4} | ||
| Person: | ||
| properties: | ||
| name: string | ||
| age: optional<integer> | ||
| ``` | ||
|
|
||
| ```typescript {3} | ||
| interface Person { | ||
| name: string; | ||
| age?: number; | ||
| } | ||
| ``` | ||
|
|
||
| When `noOptionalProperties` is enabled, the generated properties are never optional. Instead, the type is generated with `| undefined`: | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```typescript {3} | ||
| interface Person { | ||
| name: string; | ||
| age: number | undefined; | ||
| } | ||
| ``` | ||
| </ParamField> | ||
|
|
||
| <ParamField path="tolerateRepublish" type="boolean"> | ||
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="packageJson" type="object"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="publishToJsr" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="omitUndefined" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="useLegacyExports" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="streamType" type="'wrapper' | 'web'"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="fileResponseType" type="'stream' | 'binary-response'"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="formDataSupport" type="'Node16' | 'Node18'"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="fetchSupport" type="'node-fetch' | 'native'"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="packagePath" type="string"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| ### Options relevant to dynamic snippets | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <ParamField path="allowExtraFields" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="enableInlineTypes" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="inlineFileProperties" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="inlinePathParameters" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="namespaceExport" type="string"> | ||
| By default, names are based on the organization and API names in the Fern Definition: | ||
|
|
||
| ```typescript | ||
| import { AcmeApi, AcmeApiClient } from "@acme/node"; | ||
| ``` | ||
|
|
||
| `namespaceExport` customizes the exported namespace and client names: | ||
|
|
||
| ```yaml | ||
| # generators.yml | ||
| config: | ||
| namespaceExport: Acme | ||
| ``` | ||
|
|
||
| ```typescript | ||
| import { Acme, AcmeClient } from "@acme/node"; | ||
| ``` | ||
|
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="noSerdeLayer" type="boolean" default="false"> | ||
| By default, the generated client includes a layer for serializing requests and deserializing responses. This has three benefits: | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1. The client validates requests and response at runtime (client-side). | ||
|
|
||
| 1. The client can support complex types like `Date` and `Set`. | ||
|
|
||
| 1. The generated types can stray from the wire/JSON representation to be more | ||
| idiomatic. For example, when `noSerdeLayer` is disabled, all properties are `camelCase`, | ||
| even if the server is expecting `snake_case`. | ||
|
|
||
| When `noSerdeLayer` is enabled, no serialization/deserialization code is generated. The client uses `JSON.parse()` and `JSON.stringify()` instead of the default Serde layer. | ||
|
|
||
|
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="private" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="requireDefaultEnvironment" type="boolean" default="false"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| When enabled, the generated client doesn't allow the user to specify a server URL. When disabled (the default), the generated client includes an option to override the server URL: | ||
|
|
||
| ```typescript | ||
| const acme = new AcmeClient({ | ||
| environment: "localhost:8080" | ||
| }); | ||
| ``` | ||
| </ParamField> | ||
|
|
||
| <ParamField path="retainOriginalCasing" type="boolean" default="false"> | ||
| When enabled, property names in the generated code retain their original casing from the API definition instead of being converted to camelCase. | ||
|
|
||
| ```yaml | ||
| # generators.yml | ||
| config: | ||
| retainOriginalCasing: true | ||
| ``` | ||
|
|
||
| **Example with OpenAPI input:** | ||
| ```yaml {7, 9} | ||
| # OpenAPI schema | ||
| components: | ||
| schemas: | ||
| User: | ||
| type: object | ||
| properties: | ||
| user_id: | ||
| type: string | ||
| display_name: | ||
| type: string | ||
| ``` | ||
|
|
||
| Generated TypeScript with `retainOriginalCasing: true`: | ||
| ```typescript {2-3} | ||
| export interface User { | ||
| user_id: string; | ||
| display_name: string; | ||
| } | ||
| ``` | ||
|
|
||
| Generated TypeScript with default settings (`retainOriginalCasing: false`): | ||
| ```typescript {2-3} | ||
| export interface User { | ||
| userId: string; | ||
| displayName: string; | ||
| } | ||
| ``` | ||
|
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="useBigInt" type="boolean"> | ||
| </ParamField> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <ParamField path="useBrandedStringAliases" type="boolean" default="false"> | ||
|
|
||
| When `useBrandedStringAliases` is disabled (the default), string aliases are generated as | ||
| normal TypeScript aliases: | ||
|
|
||
| ```typescript | ||
| // generated code | ||
|
|
||
| export type MyString = string; | ||
|
|
||
| export type OtherString = string; | ||
| ``` | ||
| 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. | ||
|
|
||
| ```yaml | ||
| # fern definition | ||
|
|
||
| types: | ||
| MyString: string | ||
| OtherString: string | ||
| ``` | ||
|
|
||
| ```typescript | ||
| // generated code | ||
|
|
||
| export type MyString = string & { __MyString: void }; | ||
| export const MyString = (value: string): MyString => value as MyString; | ||
|
|
||
| export type OtherString = string & { __OtherString: void }; | ||
| export const OtherString = (value: string): OtherString => value as OtherString; | ||
| ``` | ||
|
|
||
| ```typescript | ||
| // consuming the generated type | ||
|
|
||
| function printMyString(s: MyString): void { | ||
| console.log("MyString: " + s); | ||
| } | ||
|
|
||
| // doesn't compile, "foo" is not assignable to MyString | ||
| printMyString("foo"); | ||
|
|
||
| const otherString = OtherString("other-string"); | ||
| // doesn't compile, otherString is not assignable to MyString | ||
| printMyString(otherString); | ||
|
|
||
| // compiles | ||
| const myString = MyString("my-string"); | ||
| printMyString(myString); | ||
| ``` | ||
|
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="neverThrowErrors" type="boolean" default="false"> | ||
| When enabled, the client doesn't throw errors when a non-200 response is received from the server. Instead, the response is wrapped in an [`ApiResponse`](packages/core-utilities/fetcher/src/APIResponse.ts). | ||
|
|
||
| ```typescript | ||
| const response = await client.callEndpoint(...); | ||
| if (response.ok) { | ||
| console.log(response.body) | ||
| } else { | ||
| console.error(respons.error) | ||
| } | ||
| ``` | ||
| </ParamField> | ||
|
|
||
| ### Beta options | ||
|
|
||
| <ParamField path="includeContentHeadersOnFileDownloadResponse" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="includeUtilsOnUnionMembers" type="boolean"> | ||
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="includeOtherInUnionTypes" type="boolean"> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="generateWireTests" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| <ParamField path="noScripts" type="boolean"> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| ### Deprecated options | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <ParamField path="timeoutInSeconds" type="number | 'infinity'" deprecated={true}> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The default timeout for network requests. In the generated client, this can be overridden at the request level. | ||
| </ParamField> | ||
|
|
||
| <ParamField path="includeApiReference" type="boolean" deprecated={true}> | ||
devalog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ParamField> | ||
|
|
||
| Discover how to configure the Fern Typescript SDK for your project. | ||
Uh oh!
There was an error while loading. Please reload this page.