Skip to content

Commit 697fef3

Browse files
committed
refactor: handling logic for SWR query key options
1 parent 1160cee commit 697fef3

File tree

49 files changed

+3556
-5882
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3556
-5882
lines changed

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

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ import type {
4444
UploadFileData,
4545
} from './types.gen';
4646

47+
/* eslint-disable @typescript-eslint/no-unused-vars */
4748
/**
4849
* Add a new pet to the store.
4950
*
5051
* Add a new pet to the store.
5152
*/
5253
export const addPetMutation = (options?: Options<AddPetData>) => ({
5354
fetcher: async (
54-
_key: string,
55+
_key: readonly [string],
5556
{
5657
arg,
5758
}: {
@@ -65,7 +66,7 @@ export const addPetMutation = (options?: Options<AddPetData>) => ({
6566
});
6667
return data;
6768
},
68-
key: '/pet',
69+
key: ['/pet'],
6970
});
7071

7172
/**
@@ -75,7 +76,7 @@ export const addPetMutation = (options?: Options<AddPetData>) => ({
7576
*/
7677
export const updatePetMutation = (options?: Options<UpdatePetData>) => ({
7778
fetcher: async (
78-
_key: string,
79+
_key: readonly [string],
7980
{
8081
arg,
8182
}: {
@@ -89,12 +90,12 @@ export const updatePetMutation = (options?: Options<UpdatePetData>) => ({
8990
});
9091
return data;
9192
},
92-
key: '/pet',
93+
key: ['/pet'],
9394
});
9495

9596
export const findPetsByStatusKey = (options: Options<FindPetsByStatusData>) => [
9697
'/pet/findByStatus',
97-
options.query,
98+
options,
9899
];
99100

100101
/**
@@ -114,7 +115,7 @@ export const findPetsByStatusOptions = (
114115

115116
export const findPetsByTagsKey = (options: Options<FindPetsByTagsData>) => [
116117
'/pet/findByTags',
117-
options.query,
118+
options,
118119
];
119120

120121
/**
@@ -139,7 +140,7 @@ export const findPetsByTagsOptions = (
139140
*/
140141
export const deletePetMutation = (options?: Options<DeletePetData>) => ({
141142
fetcher: async (
142-
_key: string | readonly [string, ...Array<string | number>],
143+
_key: readonly [string] | readonly [string, Options<DeletePetData>],
143144
{
144145
arg,
145146
}: {
@@ -153,12 +154,12 @@ export const deletePetMutation = (options?: Options<DeletePetData>) => ({
153154
});
154155
return data;
155156
},
156-
key: options?.path ? ['/pet/{petId}', options.path.petId] : '/pet/{petId}',
157+
key: options?.path ? ['/pet/{petId}', options] : ['/pet/{petId}'],
157158
});
158159

159160
export const getPetByIdKey = (options: Options<GetPetByIdData>) => [
160161
'/pet/{petId}',
161-
options.path.petId,
162+
options,
162163
];
163164

164165
/**
@@ -183,7 +184,7 @@ export const updatePetWithFormMutation = (
183184
options?: Options<UpdatePetWithFormData>,
184185
) => ({
185186
fetcher: async (
186-
_key: string | readonly [string, ...Array<string | number>],
187+
_key: readonly [string] | readonly [string, Options<UpdatePetWithFormData>],
187188
{
188189
arg,
189190
}: {
@@ -197,7 +198,7 @@ export const updatePetWithFormMutation = (
197198
});
198199
return data;
199200
},
200-
key: options?.path ? ['/pet/{petId}', options.path.petId] : '/pet/{petId}',
201+
key: options?.path ? ['/pet/{petId}', options] : ['/pet/{petId}'],
201202
});
202203

203204
/**
@@ -207,7 +208,7 @@ export const updatePetWithFormMutation = (
207208
*/
208209
export const uploadFileMutation = (options?: Options<UploadFileData>) => ({
209210
fetcher: async (
210-
_key: string | readonly [string, ...Array<string | number>],
211+
_key: readonly [string] | readonly [string, Options<UploadFileData>],
211212
{
212213
arg,
213214
}: {
@@ -222,13 +223,12 @@ export const uploadFileMutation = (options?: Options<UploadFileData>) => ({
222223
return data;
223224
},
224225
key: options?.path
225-
? ['/pet/{petId}/uploadImage', options.path.petId]
226-
: '/pet/{petId}/uploadImage',
226+
? ['/pet/{petId}/uploadImage', options]
227+
: ['/pet/{petId}/uploadImage'],
227228
});
228229

229230
export const getInventoryKey = (options?: Options<GetInventoryData>) => [
230231
'/store/inventory',
231-
options?.query,
232232
];
233233

234234
/**
@@ -251,7 +251,7 @@ export const getInventoryOptions = (options?: Options<GetInventoryData>) => ({
251251
*/
252252
export const placeOrderMutation = (options?: Options<PlaceOrderData>) => ({
253253
fetcher: async (
254-
_key: string,
254+
_key: readonly [string],
255255
{
256256
arg,
257257
}: {
@@ -265,7 +265,7 @@ export const placeOrderMutation = (options?: Options<PlaceOrderData>) => ({
265265
});
266266
return data;
267267
},
268-
key: '/store/order',
268+
key: ['/store/order'],
269269
});
270270

271271
/**
@@ -275,7 +275,7 @@ export const placeOrderMutation = (options?: Options<PlaceOrderData>) => ({
275275
*/
276276
export const deleteOrderMutation = (options?: Options<DeleteOrderData>) => ({
277277
fetcher: async (
278-
_key: string | readonly [string, ...Array<string | number>],
278+
_key: readonly [string] | readonly [string, Options<DeleteOrderData>],
279279
{
280280
arg,
281281
}: {
@@ -290,13 +290,13 @@ export const deleteOrderMutation = (options?: Options<DeleteOrderData>) => ({
290290
return data;
291291
},
292292
key: options?.path
293-
? ['/store/order/{orderId}', options.path.orderId]
294-
: '/store/order/{orderId}',
293+
? ['/store/order/{orderId}', options]
294+
: ['/store/order/{orderId}'],
295295
});
296296

297297
export const getOrderByIdKey = (options: Options<GetOrderByIdData>) => [
298298
'/store/order/{orderId}',
299-
options.path.orderId,
299+
options,
300300
];
301301

302302
/**
@@ -319,7 +319,7 @@ export const getOrderByIdOptions = (options: Options<GetOrderByIdData>) => ({
319319
*/
320320
export const createUserMutation = (options?: Options<CreateUserData>) => ({
321321
fetcher: async (
322-
_key: string,
322+
_key: readonly [string],
323323
{
324324
arg,
325325
}: {
@@ -333,7 +333,7 @@ export const createUserMutation = (options?: Options<CreateUserData>) => ({
333333
});
334334
return data;
335335
},
336-
key: '/user',
336+
key: ['/user'],
337337
});
338338

339339
/**
@@ -345,7 +345,7 @@ export const createUsersWithListInputMutation = (
345345
options?: Options<CreateUsersWithListInputData>,
346346
) => ({
347347
fetcher: async (
348-
_key: string,
348+
_key: readonly [string],
349349
{
350350
arg,
351351
}: {
@@ -359,12 +359,12 @@ export const createUsersWithListInputMutation = (
359359
});
360360
return data;
361361
},
362-
key: '/user/createWithList',
362+
key: ['/user/createWithList'],
363363
});
364364

365365
export const loginUserKey = (options?: Options<LoginUserData>) => [
366366
'/user/login',
367-
options?.query,
367+
options,
368368
];
369369

370370
/**
@@ -382,7 +382,6 @@ export const loginUserOptions = (options?: Options<LoginUserData>) => ({
382382

383383
export const logoutUserKey = (options?: Options<LogoutUserData>) => [
384384
'/user/logout',
385-
options?.query,
386385
];
387386

388387
/**
@@ -405,7 +404,7 @@ export const logoutUserOptions = (options?: Options<LogoutUserData>) => ({
405404
*/
406405
export const deleteUserMutation = (options?: Options<DeleteUserData>) => ({
407406
fetcher: async (
408-
_key: string | readonly [string, ...Array<string | number>],
407+
_key: readonly [string] | readonly [string, Options<DeleteUserData>],
409408
{
410409
arg,
411410
}: {
@@ -419,14 +418,12 @@ export const deleteUserMutation = (options?: Options<DeleteUserData>) => ({
419418
});
420419
return data;
421420
},
422-
key: options?.path
423-
? ['/user/{username}', options.path.username]
424-
: '/user/{username}',
421+
key: options?.path ? ['/user/{username}', options] : ['/user/{username}'],
425422
});
426423

427424
export const getUserByNameKey = (options: Options<GetUserByNameData>) => [
428425
'/user/{username}',
429-
options.path.username,
426+
options,
430427
];
431428

432429
/**
@@ -449,7 +446,7 @@ export const getUserByNameOptions = (options: Options<GetUserByNameData>) => ({
449446
*/
450447
export const updateUserMutation = (options?: Options<UpdateUserData>) => ({
451448
fetcher: async (
452-
_key: string | readonly [string, ...Array<string | number>],
449+
_key: readonly [string] | readonly [string, Options<UpdateUserData>],
453450
{
454451
arg,
455452
}: {
@@ -463,7 +460,5 @@ export const updateUserMutation = (options?: Options<UpdateUserData>) => ({
463460
});
464461
return data;
465462
},
466-
key: options?.path
467-
? ['/user/{username}', options.path.username]
468-
: '/user/{username}',
463+
key: options?.path ? ['/user/{username}', options] : ['/user/{username}'],
469464
});

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => {
7676
try {
7777
// assign Axios here for consistency with fetch
7878
const _axios = opts.axios!;
79+
7980
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8081
const { auth, ...optsWithoutAuth } = opts;
8182
const response = await _axios({

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => {
7676
try {
7777
// assign Axios here for consistency with fetch
7878
const _axios = opts.axios!;
79+
7980
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8081
const { auth, ...optsWithoutAuth } = opts;
8182
const response = await _axios({

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => {
7676
try {
7777
// assign Axios here for consistency with fetch
7878
const _axios = opts.axios!;
79+
7980
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8081
const { auth, ...optsWithoutAuth } = opts;
8182
const response = await _axios({

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => {
7676
try {
7777
// assign Axios here for consistency with fetch
7878
const _axios = opts.axios!;
79+
7980
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8081
const { auth, ...optsWithoutAuth } = opts;
8182
const response = await _axios({

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => {
7676
try {
7777
// assign Axios here for consistency with fetch
7878
const _axios = opts.axios!;
79+
7980
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8081
const { auth, ...optsWithoutAuth } = opts;
8182
const response = await _axios({

0 commit comments

Comments
 (0)