Skip to content

Commit fed9699

Browse files
committed
fix: set next field to never and recommend next.js client
1 parent 53c88a6 commit fed9699

File tree

9 files changed

+280
-107
lines changed

9 files changed

+280
-107
lines changed

.changeset/gentle-bobcats-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/client-fetch': minor
3+
---
4+
5+
fix: set next field to never and recommend switching to the Next.js client

docs/openapi-ts/clients/next-js.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,6 @@ The Next.js client is built as a thin wrapper on top of [fetch](https://nextjs.o
6868

6969
When we installed the client above, it created a [`client.gen.ts`](/openapi-ts/output#client) file. You will most likely want to configure the exported `client` instance. There are two ways to do that.
7070

71-
### `setConfig()`
72-
73-
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to `setConfig()`, and even your own Fetch implementation.
74-
75-
```js
76-
import { client } from 'client/client.gen';
77-
78-
client.setConfig({
79-
baseUrl: 'https://example.com',
80-
});
81-
```
82-
83-
The disadvantage of this approach is that your code may call the `client` instance before it's configured for the first time. Depending on your use case, you might need to use the second approach.
84-
8571
### Runtime API
8672

8773
Since `client.gen.ts` is a generated file, we can't directly modify it. Instead, we can tell our configuration to use a custom file implementing the Runtime API. We do that by specifying the `runtimeConfigPath` option.
@@ -114,7 +100,21 @@ export const createClientConfig: CreateClientConfig = (config) => ({
114100

115101
:::
116102

117-
With this approach, `client.gen.ts` will call `createClientConfig()` before initializing the `client` instance. If needed, you can still use `setConfig()` to update the client configuration later.
103+
With this approach, `client.gen.ts` will call `createClientConfig()` before initializing the `client` instance. This is the recommended approach because it guarantees the client will be initialized in both server and client environment. If needed, you can still use `setConfig()` to update the client configuration later.
104+
105+
### `setConfig()`
106+
107+
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to `setConfig()`, and even your own Fetch implementation.
108+
109+
```js
110+
import { client } from 'client/client.gen';
111+
112+
client.setConfig({
113+
baseUrl: 'https://example.com',
114+
});
115+
```
116+
117+
The disadvantage of this approach is that your code may call the `client` instance before it's configured for the first time. Depending on your use case, this might be an acceptable trade-off. However, our Next.js users usually want to use the first approach.
118118

119119
### `createClient()`
120120

examples/openapi-ts-next/src/client/client.gen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@ export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =
2424
) => Config<Required<DefaultClientOptions> & T>;
2525

2626
export const client = createClient(
27-
createClientConfig(createConfig<ClientOptions>()),
27+
createClientConfig(
28+
createConfig<ClientOptions>({
29+
baseUrl: 'https://petstore3.swagger.io/api/v3',
30+
}),
31+
),
2832
);

examples/openapi-ts-next/src/client/sdk.gen.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import type {
3737
UpdatePetData,
3838
UpdatePetResponse,
3939
UpdatePetWithFormData,
40+
UpdatePetWithFormResponse,
4041
UpdateUserData,
4142
UploadFileData,
4243
UploadFileResponse,
@@ -60,8 +61,8 @@ export type Options<
6061
};
6162

6263
/**
63-
* Add a new pet to the store
64-
* Add a new pet to the store
64+
* Add a new pet to the store.
65+
* Add a new pet to the store.
6566
*/
6667
export const addPet = <ThrowOnError extends boolean = false>(
6768
options: Options<AddPetData, ThrowOnError>,
@@ -84,8 +85,8 @@ export const addPet = <ThrowOnError extends boolean = false>(
8485
);
8586

8687
/**
87-
* Update an existing pet
88-
* Update an existing pet by Id
88+
* Update an existing pet.
89+
* Update an existing pet by Id.
8990
*/
9091
export const updatePet = <ThrowOnError extends boolean = false>(
9192
options: Options<UpdatePetData, ThrowOnError>,
@@ -110,8 +111,8 @@ export const updatePet = <ThrowOnError extends boolean = false>(
110111
});
111112

112113
/**
113-
* Finds Pets by status
114-
* Multiple status values can be provided with comma separated strings
114+
* Finds Pets by status.
115+
* Multiple status values can be provided with comma separated strings.
115116
*/
116117
export const findPetsByStatus = <ThrowOnError extends boolean = false>(
117118
options?: Options<FindPetsByStatusData, ThrowOnError>,
@@ -132,7 +133,7 @@ export const findPetsByStatus = <ThrowOnError extends boolean = false>(
132133
});
133134

134135
/**
135-
* Finds Pets by tags
136+
* Finds Pets by tags.
136137
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
137138
*/
138139
export const findPetsByTags = <ThrowOnError extends boolean = false>(
@@ -154,7 +155,8 @@ export const findPetsByTags = <ThrowOnError extends boolean = false>(
154155
});
155156

156157
/**
157-
* Deletes a pet
158+
* Deletes a pet.
159+
* Delete a pet.
158160
*/
159161
export const deletePet = <ThrowOnError extends boolean = false>(
160162
options: Options<DeletePetData, ThrowOnError>,
@@ -171,8 +173,8 @@ export const deletePet = <ThrowOnError extends boolean = false>(
171173
});
172174

173175
/**
174-
* Find pet by ID
175-
* Returns a single pet
176+
* Find pet by ID.
177+
* Returns a single pet.
176178
*/
177179
export const getPetById = <ThrowOnError extends boolean = false>(
178180
options: Options<GetPetByIdData, ThrowOnError>,
@@ -197,12 +199,17 @@ export const getPetById = <ThrowOnError extends boolean = false>(
197199
});
198200

199201
/**
200-
* Updates a pet in the store with form data
202+
* Updates a pet in the store with form data.
203+
* Updates a pet resource based on the form data.
201204
*/
202205
export const updatePetWithForm = <ThrowOnError extends boolean = false>(
203206
options: Options<UpdatePetWithFormData, ThrowOnError>,
204207
) =>
205-
(options.client ?? _heyApiClient).post<unknown, unknown, ThrowOnError>({
208+
(options.client ?? _heyApiClient).post<
209+
UpdatePetWithFormResponse,
210+
unknown,
211+
ThrowOnError
212+
>({
206213
security: [
207214
{
208215
scheme: 'bearer',
@@ -214,7 +221,8 @@ export const updatePetWithForm = <ThrowOnError extends boolean = false>(
214221
});
215222

216223
/**
217-
* uploads an image
224+
* Uploads an image.
225+
* Upload image of the pet.
218226
*/
219227
export const uploadFile = <ThrowOnError extends boolean = false>(
220228
options: Options<UploadFileData, ThrowOnError>,
@@ -239,8 +247,8 @@ export const uploadFile = <ThrowOnError extends boolean = false>(
239247
});
240248

241249
/**
242-
* Returns pet inventories by status
243-
* Returns a map of status codes to quantities
250+
* Returns pet inventories by status.
251+
* Returns a map of status codes to quantities.
244252
*/
245253
export const getInventory = <ThrowOnError extends boolean = false>(
246254
options?: Options<GetInventoryData, ThrowOnError>,
@@ -261,8 +269,8 @@ export const getInventory = <ThrowOnError extends boolean = false>(
261269
});
262270

263271
/**
264-
* Place an order for a pet
265-
* Place a new order in the store
272+
* Place an order for a pet.
273+
* Place a new order in the store.
266274
*/
267275
export const placeOrder = <ThrowOnError extends boolean = false>(
268276
options?: Options<PlaceOrderData, ThrowOnError>,
@@ -281,8 +289,8 @@ export const placeOrder = <ThrowOnError extends boolean = false>(
281289
});
282290

283291
/**
284-
* Delete purchase order by ID
285-
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
292+
* Delete purchase order by identifier.
293+
* For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors.
286294
*/
287295
export const deleteOrder = <ThrowOnError extends boolean = false>(
288296
options: Options<DeleteOrderData, ThrowOnError>,
@@ -293,7 +301,7 @@ export const deleteOrder = <ThrowOnError extends boolean = false>(
293301
});
294302

295303
/**
296-
* Find purchase order by ID
304+
* Find purchase order by ID.
297305
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
298306
*/
299307
export const getOrderById = <ThrowOnError extends boolean = false>(
@@ -309,7 +317,7 @@ export const getOrderById = <ThrowOnError extends boolean = false>(
309317
});
310318

311319
/**
312-
* Create user
320+
* Create user.
313321
* This can only be done by the logged in user.
314322
*/
315323
export const createUser = <ThrowOnError extends boolean = false>(
@@ -329,8 +337,8 @@ export const createUser = <ThrowOnError extends boolean = false>(
329337
});
330338

331339
/**
332-
* Creates list of users with given input array
333-
* Creates list of users with given input array
340+
* Creates list of users with given input array.
341+
* Creates list of users with given input array.
334342
*/
335343
export const createUsersWithListInput = <ThrowOnError extends boolean = false>(
336344
options?: Options<CreateUsersWithListInputData, ThrowOnError>,
@@ -349,7 +357,8 @@ export const createUsersWithListInput = <ThrowOnError extends boolean = false>(
349357
});
350358

351359
/**
352-
* Logs user into the system
360+
* Logs user into the system.
361+
* Log into the system.
353362
*/
354363
export const loginUser = <ThrowOnError extends boolean = false>(
355364
options?: Options<LoginUserData, ThrowOnError>,
@@ -364,7 +373,8 @@ export const loginUser = <ThrowOnError extends boolean = false>(
364373
});
365374

366375
/**
367-
* Logs out current logged in user session
376+
* Logs out current logged in user session.
377+
* Log user out of the system.
368378
*/
369379
export const logoutUser = <ThrowOnError extends boolean = false>(
370380
options?: Options<LogoutUserData, ThrowOnError>,
@@ -375,7 +385,7 @@ export const logoutUser = <ThrowOnError extends boolean = false>(
375385
});
376386

377387
/**
378-
* Delete user
388+
* Delete user resource.
379389
* This can only be done by the logged in user.
380390
*/
381391
export const deleteUser = <ThrowOnError extends boolean = false>(
@@ -387,7 +397,8 @@ export const deleteUser = <ThrowOnError extends boolean = false>(
387397
});
388398

389399
/**
390-
* Get user by user name
400+
* Get user by user name.
401+
* Get user detail based on username.
391402
*/
392403
export const getUserByName = <ThrowOnError extends boolean = false>(
393404
options: Options<GetUserByNameData, ThrowOnError>,
@@ -402,7 +413,7 @@ export const getUserByName = <ThrowOnError extends boolean = false>(
402413
});
403414

404415
/**
405-
* Update user
416+
* Update user resource.
406417
* This can only be done by the logged in user.
407418
*/
408419
export const updateUser = <ThrowOnError extends boolean = false>(

0 commit comments

Comments
 (0)