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
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).
81
+
82
+
```typescript
83
+
const response =awaitclient.callEndpoint(...);
84
+
if (response.ok) {
85
+
console.log(response.body)
86
+
} else {
87
+
console.error(respons.error)
88
+
}
89
+
```
90
+
</ParamField>
91
+
92
+
<ParamFieldpath="namespaceExport"type="string">
93
+
Customizes the exported namespace and client names. By default, names are based on the organization and API names in the Fern Definition.
When enabled, the generator outputs raw TypeScript files. When disabled (the default), outputs .js and d.ts files. Note: Only applies when dumping code locally.
By default, the client will throw an error if the response from the server doesn't match the expected type. If enabled, the client will log issues using console.warn and return the data casted to the expected response type.
Specify extra dependencies in the generated package.json. Useful when utilizing .fernignore to supplement the generated client with custom code. Note: Only applies when publishing to Github.
When enabled, no serialization/deserialization code is generated. The client uses JSON.parse() and JSON.stringify() instead of the default serde layer that provides validation and complex type support.
Copy file name to clipboardExpand all lines: fern/products/sdks/pages/typescript/quickstart.mdx
+89-31Lines changed: 89 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,35 +22,35 @@ Generate a TypeScript SDK by following the instructions on this page.
22
22
23
23
### Initialize the Fern Folder
24
24
25
-
You can use either the OpenAPI definition or Fern Definition to generate your SDK.
25
+
You can use either the OpenAPI definition, AsyncAPI definition, or Fern Definition to generate your SDK.
26
26
27
27
<AccordionGroup>
28
-
<Accordiontitle="Option 1: OpenAPI">
29
-
Initialize the Fern folder using your OpenAPI Specification. Run one of the following commands based on your spec's location:
28
+
<Accordiontitle="Option 1: OpenAPI">
29
+
Initialize the Fern folder using your OpenAPI Specification. Run one of the following commands based on your spec's location.
30
30
31
31
<Tip>
32
32
Fern can handle both JSON and YML formats for OpenAPI specifications, and the --openapi flag accepts either format, so you can use whichever format your API spec is available in.
33
33
</Tip>
34
34
35
+
<Info>
36
+
`--organization <YourOrganization>` configures your organization name in `fern.config.json`. This is required in order to successfully generate your SDK.
Enter your organization name when prompted. The organization name must be configured in `fern.config.json` in order to successfully generate your SDK.
53
-
</Info>
53
+
</CodeBlocks>
54
54
55
55
This creates a `fern` folder in your current directory with the OpenAPI Specification. The exact folder structure might look different depending on your initial input files.
56
56
@@ -63,33 +63,91 @@ Generate a TypeScript SDK by following the instructions on this page.
63
63
├─ openapi.yml # API-level configuration
64
64
```
65
65
</Accordion>
66
-
<Accordiontitle="Option 2: Fern Definition">
66
+
<Accordiontitle="Option 2: AsyncAPI">
67
+
Initialize the Fern folder using your AsyncAPI Specification. Run one of the following commands based on your spec's location.
67
68
68
-
Initialize the Fern folder using the Fern Definition by running the following command:
69
+
<Tip>
70
+
Fern can handle both JSON and YML formats for AsyncAPI specifications, and the --openapi flag accepts either format, so you can use whichever format your API spec is available in.
71
+
</Tip>
69
72
70
-
```bash
71
-
fern init
72
-
```
73
73
<Info>
74
-
Enter your organization name when prompted. The organization name must be configured in `fern.config.json`in order to sucessfully generate your SDK.
74
+
`--organization <YourOrganization>` configures your organization name in `fern.config.json`. This is required in order to successfully generate your SDK.
75
75
</Info>
76
76
77
-
This creates a `fern` folder in your current directory with the Fern Definition.
This creates a `fern` folder in your current directory with the AsyncAPI Specification. The exact folder structure might look different depending on your initial input files.
78
94
79
95
```bash
80
96
fern/
81
97
├─ fern.config.json # root-level configuration
82
-
├─ generators.yml#generators you're using
83
-
└─ definition/
84
-
├─ api.yml # API-level configuration
85
-
└─ imdb.yml # endpoints, types, and errors
98
+
└─ api/#your API
99
+
├─ generators.yml # generators you're using
100
+
└─ openapi/
101
+
├─ openapi.yml # API-level configuration
86
102
```
103
+
</Accordion>
104
+
<Accordiontitle="Option 3: Fern Definition">
105
+
106
+
1. Initialize the Fern folder using the Fern Definition by running the following command:
107
+
108
+
```bash
109
+
fern init --organization <YourOrganization>
110
+
```
111
+
112
+
<Info>
113
+
`--organization <YourOrganization>` configures your organization name in `fern.config.json`. This is required in order to successfully generate your SDK.
114
+
</Info>
115
+
116
+
This creates a `fern` folder in your current directory with the Fern Definition.
117
+
118
+
```bash
119
+
fern/
120
+
├─ fern.config.json # root-level configuration
121
+
├─ generators.yml # generators you're using
122
+
└─ definition/
123
+
├─ api.yml # API-level configuration
124
+
└─ imdb.yml # endpoints, types, and errors
125
+
```
126
+
127
+
<Note>
128
+
`imdb.yml` contains an example movies API. If you’re just generating an SDK for test purposes, you can leave this file as it is. To generate an SDK for your own API instead of the example movies API, replace `imdb.yml` with your own endpoints, types, and errors before proceeding with the rest of this page.
129
+
</Note>
130
+
131
+
{/* TODO: show want generators.yml looks like, link out to configuration.md */}
132
+
133
+
1. Add the config option `outputSourceFiles: true` to `generators.yml`. This ensures your SDK contains `.ts` files instead of compiled output.
`imdb.yml` contains an example movies API. If you’re just generating an SDK for test purposes, you can leave this file as it is. To generate an SDK for your own API instead of the example movies API, replace `imdb.yml` with your own endpoints, types, and errors before proceeding with the rest of this page.
90
-
</Note>
91
150
92
-
{/* TODO: show want generators.yml looks like, link out to configuration.md */}
93
151
94
152
95
153
</Accordion>
@@ -117,12 +175,12 @@ Generate a TypeScript SDK by following the instructions on this page.
0 commit comments