@kubb/plugin-swr 3.0.0-alpha.9 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/dist/chunk-4EGGCGSE.js +217 -0
- package/dist/chunk-4EGGCGSE.js.map +1 -0
- package/dist/chunk-H23WKEYP.js +243 -0
- package/dist/chunk-H23WKEYP.js.map +1 -0
- package/dist/chunk-JWGWABV5.cjs +249 -0
- package/dist/chunk-JWGWABV5.cjs.map +1 -0
- package/dist/chunk-PTOQHHST.cjs +220 -0
- package/dist/chunk-PTOQHHST.cjs.map +1 -0
- package/dist/components.cjs +23 -6
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +88 -6
- package/dist/components.d.ts +88 -6
- package/dist/components.js +2 -10
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +11 -0
- package/dist/generators.d.ts +11 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +93 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +77 -114
- package/dist/index.js.map +1 -1
- package/dist/types-DaH2Sc1M.d.cts +103 -0
- package/dist/types-DaH2Sc1M.d.ts +103 -0
- package/package.json +23 -17
- package/src/components/Mutation.tsx +93 -227
- package/src/components/MutationKey.tsx +48 -0
- package/src/components/Query.tsx +93 -259
- package/src/components/QueryKey.tsx +73 -0
- package/src/components/QueryOptions.tsx +54 -177
- package/src/components/index.ts +2 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +43 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +43 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
- package/src/generators/__snapshots__/findByTags.ts +43 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +43 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +43 -0
- package/src/generators/__snapshots__/getAsMutation.ts +34 -0
- package/src/generators/__snapshots__/postAsQuery.ts +41 -0
- package/src/generators/__snapshots__/updatePetById.ts +32 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +36 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mutationGenerator.tsx +109 -0
- package/src/generators/queryGenerator.tsx +114 -0
- package/src/plugin.ts +71 -52
- package/src/types.ts +62 -78
- package/dist/chunk-TGLXUPN4.cjs +0 -536
- package/dist/chunk-TGLXUPN4.cjs.map +0 -1
- package/dist/chunk-XWXMQJD6.js +0 -536
- package/dist/chunk-XWXMQJD6.js.map +0 -1
- package/dist/index-B3C-JOIU.d.cts +0 -299
- package/dist/index-B3C-JOIU.d.ts +0 -299
- package/src/OperationGenerator.tsx +0 -75
- package/src/components/SchemaType.tsx +0 -63
- package/src/components/__snapshots__/Mutation/Pets.ts +0 -46
- package/src/components/__snapshots__/Query/showPetById.ts +0 -59
|
@@ -1,199 +1,76 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
|
-
import { getASTParams } from '@kubb/plugin-oas/utils'
|
|
5
|
-
import { Function, File, useApp } from '@kubb/react'
|
|
6
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
1
|
+
import { getPathParams } from '@kubb/plugin-oas/utils'
|
|
2
|
+
import { File, Function, FunctionParams } from '@kubb/react'
|
|
7
3
|
|
|
8
|
-
import type { HttpMethod } from '@kubb/oas'
|
|
9
4
|
import type { ReactNode } from 'react'
|
|
10
5
|
import type { PluginSwr } from '../types.ts'
|
|
11
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
import { isOptional } from '@kubb/oas'
|
|
8
|
+
import { Client } from '@kubb/plugin-client/components'
|
|
9
|
+
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
17
12
|
name: string
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
params: string
|
|
22
|
-
/**
|
|
23
|
-
* Generics that needs to be added for TypeScript
|
|
24
|
-
*/
|
|
25
|
-
generics?: string
|
|
26
|
-
/**
|
|
27
|
-
* ReturnType(see async for adding Promise type)
|
|
28
|
-
*/
|
|
29
|
-
returnType?: string
|
|
30
|
-
/**
|
|
31
|
-
* Options for JSdocs
|
|
32
|
-
*/
|
|
33
|
-
JSDoc?: {
|
|
34
|
-
comments: string[]
|
|
35
|
-
}
|
|
36
|
-
client: {
|
|
37
|
-
generics: string
|
|
38
|
-
method: HttpMethod
|
|
39
|
-
path: URLPath
|
|
40
|
-
withQueryParams: boolean
|
|
41
|
-
withPathParams: boolean
|
|
42
|
-
withData: boolean
|
|
43
|
-
withHeaders: boolean
|
|
44
|
-
contentType: string
|
|
45
|
-
}
|
|
46
|
-
dataReturnType: NonNullable<PluginSwr['options']['dataReturnType']>
|
|
47
|
-
parser: string | undefined
|
|
13
|
+
clientName: string
|
|
14
|
+
typeSchemas: OperationSchemas
|
|
15
|
+
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
48
16
|
}
|
|
49
17
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
client.withHeaders ? '...headers' : undefined,
|
|
55
|
-
]
|
|
56
|
-
.filter(Boolean)
|
|
57
|
-
.join(', ')
|
|
58
|
-
|
|
59
|
-
const clientOptions = [
|
|
60
|
-
`method: "${client.method}"`,
|
|
61
|
-
`url: ${client.path.template}`,
|
|
62
|
-
client.withQueryParams ? 'params' : undefined,
|
|
63
|
-
client.withData && !isFormData ? 'data' : undefined,
|
|
64
|
-
client.withData && isFormData ? 'data: formData' : undefined,
|
|
65
|
-
headers.length ? `headers: { ${headers}, ...options.headers }` : undefined,
|
|
66
|
-
'...options',
|
|
67
|
-
].filter(Boolean)
|
|
68
|
-
|
|
69
|
-
const resolvedClientOptions = `${transformers.createIndent(4)}${clientOptions.join(`,\n${transformers.createIndent(4)}`)}`
|
|
70
|
-
|
|
71
|
-
let returnRes = parser ? `return ${parser}(res.data)` : 'return res.data'
|
|
18
|
+
type GetParamsProps = {
|
|
19
|
+
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
20
|
+
typeSchemas: OperationSchemas
|
|
21
|
+
}
|
|
72
22
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
23
|
+
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
24
|
+
return FunctionParams.factory({
|
|
25
|
+
pathParams: {
|
|
26
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
27
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
28
|
+
},
|
|
29
|
+
data: typeSchemas.request?.name
|
|
30
|
+
? {
|
|
31
|
+
type: typeSchemas.request?.name,
|
|
32
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
33
|
+
}
|
|
34
|
+
: undefined,
|
|
35
|
+
params: typeSchemas.queryParams?.name
|
|
36
|
+
? {
|
|
37
|
+
type: typeSchemas.queryParams?.name,
|
|
38
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
39
|
+
}
|
|
40
|
+
: undefined,
|
|
41
|
+
headers: typeSchemas.headerParams?.name
|
|
42
|
+
? {
|
|
43
|
+
type: typeSchemas.headerParams?.name,
|
|
44
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
45
|
+
}
|
|
46
|
+
: undefined,
|
|
47
|
+
config: {
|
|
48
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
49
|
+
default: '{}',
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
}
|
|
76
53
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
84
|
-
formData.append(key, value);
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
`
|
|
89
|
-
: undefined
|
|
54
|
+
export function QueryOptions({ name, clientName, typeSchemas, pathParamsType }: Props): ReactNode {
|
|
55
|
+
const params = getParams({ pathParamsType, typeSchemas })
|
|
56
|
+
const clientParams = Client.getParams({
|
|
57
|
+
typeSchemas,
|
|
58
|
+
pathParamsType,
|
|
59
|
+
})
|
|
90
60
|
|
|
91
61
|
return (
|
|
92
62
|
<File.Source name={name} isExportable isIndexable>
|
|
93
|
-
<Function name={name} export
|
|
63
|
+
<Function name={name} export params={params.toConstructor()}>
|
|
94
64
|
{`
|
|
95
65
|
return {
|
|
96
66
|
fetcher: async () => {
|
|
97
|
-
${
|
|
98
|
-
const res = await client<${client.generics}>({
|
|
99
|
-
${resolvedClientOptions}
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
${returnRes}
|
|
67
|
+
return ${clientName}(${clientParams.toCall()})
|
|
103
68
|
},
|
|
104
69
|
}
|
|
105
|
-
|
|
106
|
-
`}
|
|
70
|
+
`}
|
|
107
71
|
</Function>
|
|
108
72
|
</File.Source>
|
|
109
73
|
)
|
|
110
74
|
}
|
|
111
75
|
|
|
112
|
-
|
|
113
|
-
default: Template,
|
|
114
|
-
} as const
|
|
115
|
-
|
|
116
|
-
type Props = {
|
|
117
|
-
factory: {
|
|
118
|
-
name: string
|
|
119
|
-
}
|
|
120
|
-
dataReturnType: NonNullable<PluginSwr['options']['dataReturnType']>
|
|
121
|
-
/**
|
|
122
|
-
* This will make it possible to override the default behaviour.
|
|
123
|
-
*/
|
|
124
|
-
Template?: React.ComponentType<TemplateProps>
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function QueryOptions({ factory, dataReturnType, Template = defaultTemplates.default }: Props): ReactNode {
|
|
128
|
-
const {
|
|
129
|
-
pluginManager,
|
|
130
|
-
plugin: {
|
|
131
|
-
key: pluginKey,
|
|
132
|
-
options: { parser },
|
|
133
|
-
},
|
|
134
|
-
} = useApp<PluginSwr>()
|
|
135
|
-
const { getSchemas } = useOperationManager()
|
|
136
|
-
const operation = useOperation()
|
|
137
|
-
|
|
138
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
139
|
-
const zodSchemas = getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' })
|
|
140
|
-
const name = pluginManager.resolveName({
|
|
141
|
-
name: `${factory.name}QueryOptions`,
|
|
142
|
-
pluginKey,
|
|
143
|
-
})
|
|
144
|
-
const contentType = operation.getContentType()
|
|
145
|
-
|
|
146
|
-
const generics = new FunctionParams()
|
|
147
|
-
const params = new FunctionParams()
|
|
148
|
-
|
|
149
|
-
const clientGenerics = ['TData', `${factory.name}['error']`]
|
|
150
|
-
const resultGenerics = ['TData', `${factory.name}['error']`]
|
|
151
|
-
|
|
152
|
-
generics.add([{ type: 'TData', default: `${factory.name}['response']` }])
|
|
153
|
-
|
|
154
|
-
params.add([
|
|
155
|
-
...getASTParams(schemas.pathParams, { typed: true }),
|
|
156
|
-
{
|
|
157
|
-
name: 'params',
|
|
158
|
-
type: `${factory.name}['queryParams']`,
|
|
159
|
-
enabled: !!schemas.queryParams?.name,
|
|
160
|
-
required: false,
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
name: 'headers',
|
|
164
|
-
type: `${factory.name}['headerParams']`,
|
|
165
|
-
enabled: !!schemas.headerParams?.name,
|
|
166
|
-
required: false,
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
name: 'options',
|
|
170
|
-
type: `${factory.name}['client']['parameters']`,
|
|
171
|
-
default: '{}',
|
|
172
|
-
},
|
|
173
|
-
])
|
|
174
|
-
|
|
175
|
-
const client = {
|
|
176
|
-
withQueryParams: !!schemas.queryParams?.name,
|
|
177
|
-
withData: !!schemas.request?.name,
|
|
178
|
-
withPathParams: !!schemas.pathParams?.name,
|
|
179
|
-
withHeaders: !!schemas.headerParams?.name,
|
|
180
|
-
method: operation.method,
|
|
181
|
-
path: new URLPath(operation.path),
|
|
182
|
-
generics: clientGenerics.join(', '),
|
|
183
|
-
contentType,
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return (
|
|
187
|
-
<Template
|
|
188
|
-
name={name}
|
|
189
|
-
params={params.toString()}
|
|
190
|
-
generics={generics.toString()}
|
|
191
|
-
returnType={`SWRConfiguration<${resultGenerics.join(', ')}>`}
|
|
192
|
-
client={client}
|
|
193
|
-
dataReturnType={dataReturnType}
|
|
194
|
-
parser={parser === 'zod' ? `${zodSchemas.response.name}.parse` : undefined}
|
|
195
|
-
/>
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
QueryOptions.templates = defaultTemplates
|
|
76
|
+
QueryOptions.getParams = getParams
|
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import type { RequestConfig, ResponseConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
6
|
+
|
|
7
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
11
|
+
* @summary Finds Pets by tags
|
|
12
|
+
* @link /pet/findByTags
|
|
13
|
+
*/
|
|
14
|
+
async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
15
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, ...config });
|
|
16
|
+
return res;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
20
|
+
return {
|
|
21
|
+
fetcher: async () => {
|
|
22
|
+
return findPetsByTags(params, config);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
29
|
+
* @summary Finds Pets by tags
|
|
30
|
+
* @link /pet/findByTags
|
|
31
|
+
*/
|
|
32
|
+
export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
|
|
33
|
+
query?: Parameters<typeof useSWR<ResponseConfig<FindPetsByTagsQueryResponse>, FindPetsByTags400, FindPetsByTagsQueryKey | null, any>>[2];
|
|
34
|
+
client?: Partial<RequestConfig>;
|
|
35
|
+
shouldFetch?: boolean;
|
|
36
|
+
} = {}) {
|
|
37
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
38
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
39
|
+
return useSWR<ResponseConfig<FindPetsByTagsQueryResponse>, FindPetsByTags400, FindPetsByTagsQueryKey | null>(shouldFetch ? queryKey : null, {
|
|
40
|
+
...findPetsByTagsQueryOptions(params, config),
|
|
41
|
+
...queryOptions
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import client from "axios";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import type { RequestConfig } from "axios";
|
|
4
|
+
|
|
5
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
6
|
+
|
|
7
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
11
|
+
* @summary Finds Pets by tags
|
|
12
|
+
* @link /pet/findByTags
|
|
13
|
+
*/
|
|
14
|
+
async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
15
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, ...config });
|
|
16
|
+
return res.data;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
20
|
+
return {
|
|
21
|
+
fetcher: async () => {
|
|
22
|
+
return findPetsByTags(params, config);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
29
|
+
* @summary Finds Pets by tags
|
|
30
|
+
* @link /pet/findByTags
|
|
31
|
+
*/
|
|
32
|
+
export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
|
|
33
|
+
query?: Parameters<typeof useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null, any>>[2];
|
|
34
|
+
client?: Partial<RequestConfig>;
|
|
35
|
+
shouldFetch?: boolean;
|
|
36
|
+
} = {}) {
|
|
37
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
38
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
39
|
+
return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null>(shouldFetch ? queryKey : null, {
|
|
40
|
+
...findPetsByTagsQueryOptions(params, config),
|
|
41
|
+
...queryOptions
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import client from "axios";
|
|
2
|
+
import useSWRMutation from "swr/mutation";
|
|
3
|
+
import type { RequestConfig } from "axios";
|
|
4
|
+
|
|
5
|
+
export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
|
|
6
|
+
|
|
7
|
+
export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @summary Updates a pet in the store with form data
|
|
11
|
+
* @link /pet/:petId
|
|
12
|
+
*/
|
|
13
|
+
async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
|
|
14
|
+
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "POST", url: `/pet/${petId}`, params, ...config });
|
|
15
|
+
return res.data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @summary Updates a pet in the store with form data
|
|
20
|
+
* @link /pet/:petId
|
|
21
|
+
*/
|
|
22
|
+
export function useUpdatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, options: {
|
|
23
|
+
mutation?: Parameters<typeof useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationKey>>[2];
|
|
24
|
+
client?: Partial<RequestConfig>;
|
|
25
|
+
shouldFetch?: boolean;
|
|
26
|
+
} = {}) {
|
|
27
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
28
|
+
const mutationKey = updatePetWithFormMutationKey();
|
|
29
|
+
return useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationKey | null>(shouldFetch ? mutationKey : null, async (_url) => {
|
|
30
|
+
return updatePetWithForm(petId, params, config);
|
|
31
|
+
}, mutationOptions);
|
|
32
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
6
|
+
|
|
7
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
11
|
+
* @summary Finds Pets by tags
|
|
12
|
+
* @link /pet/findByTags
|
|
13
|
+
*/
|
|
14
|
+
async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
15
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, ...config });
|
|
16
|
+
return res.data;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
20
|
+
return {
|
|
21
|
+
fetcher: async () => {
|
|
22
|
+
return findPetsByTags(params, config);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
29
|
+
* @summary Finds Pets by tags
|
|
30
|
+
* @link /pet/findByTags
|
|
31
|
+
*/
|
|
32
|
+
export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
|
|
33
|
+
query?: Parameters<typeof useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null, any>>[2];
|
|
34
|
+
client?: Partial<RequestConfig>;
|
|
35
|
+
shouldFetch?: boolean;
|
|
36
|
+
} = {}) {
|
|
37
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
38
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
39
|
+
return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null>(shouldFetch ? queryKey : null, {
|
|
40
|
+
...findPetsByTagsQueryOptions(params, config),
|
|
41
|
+
...queryOptions
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
6
|
+
|
|
7
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
11
|
+
* @summary Finds Pets by tags
|
|
12
|
+
* @link /pet/findByTags
|
|
13
|
+
*/
|
|
14
|
+
async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
15
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, ...config });
|
|
16
|
+
return res.data;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
20
|
+
return {
|
|
21
|
+
fetcher: async () => {
|
|
22
|
+
return findPetsByTags(params, config);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
29
|
+
* @summary Finds Pets by tags
|
|
30
|
+
* @link /pet/findByTags
|
|
31
|
+
*/
|
|
32
|
+
export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
|
|
33
|
+
query?: Parameters<typeof useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null, any>>[2];
|
|
34
|
+
client?: Partial<RequestConfig>;
|
|
35
|
+
shouldFetch?: boolean;
|
|
36
|
+
} = {}) {
|
|
37
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
38
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
39
|
+
return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null>(shouldFetch ? queryKey : null, {
|
|
40
|
+
...findPetsByTagsQueryOptions(params, config),
|
|
41
|
+
...queryOptions
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
6
|
+
|
|
7
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
11
|
+
* @summary Finds Pets by tags
|
|
12
|
+
* @link /pet/findByTags
|
|
13
|
+
*/
|
|
14
|
+
async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
15
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, ...config });
|
|
16
|
+
return findPetsByTagsQueryResponse.parse(res.data);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
20
|
+
return {
|
|
21
|
+
fetcher: async () => {
|
|
22
|
+
return findPetsByTags(params, config);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
29
|
+
* @summary Finds Pets by tags
|
|
30
|
+
* @link /pet/findByTags
|
|
31
|
+
*/
|
|
32
|
+
export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
|
|
33
|
+
query?: Parameters<typeof useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null, any>>[2];
|
|
34
|
+
client?: Partial<RequestConfig>;
|
|
35
|
+
shouldFetch?: boolean;
|
|
36
|
+
} = {}) {
|
|
37
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
38
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
39
|
+
return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null>(shouldFetch ? queryKey : null, {
|
|
40
|
+
...findPetsByTagsQueryOptions(params, config),
|
|
41
|
+
...queryOptions
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import useSWRMutation from "custom-swr/mutation";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
export const findPetsByTagsMutationKey = () => [{ "url": "/pet/findByTags" }] as const;
|
|
6
|
+
|
|
7
|
+
export type FindPetsByTagsMutationKey = ReturnType<typeof findPetsByTagsMutationKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
11
|
+
* @summary Finds Pets by tags
|
|
12
|
+
* @link /pet/findByTags
|
|
13
|
+
*/
|
|
14
|
+
async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
15
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, ...config });
|
|
16
|
+
return res.data;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
21
|
+
* @summary Finds Pets by tags
|
|
22
|
+
* @link /pet/findByTags
|
|
23
|
+
*/
|
|
24
|
+
export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
|
|
25
|
+
mutation?: Parameters<typeof useSWRMutation<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsMutationKey>>[2];
|
|
26
|
+
client?: Partial<RequestConfig>;
|
|
27
|
+
shouldFetch?: boolean;
|
|
28
|
+
} = {}) {
|
|
29
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
30
|
+
const mutationKey = findPetsByTagsMutationKey();
|
|
31
|
+
return useSWRMutation<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsMutationKey | null>(shouldFetch ? mutationKey : null, async (_url) => {
|
|
32
|
+
return findPetsByTags(params, config);
|
|
33
|
+
}, mutationOptions);
|
|
34
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import useSWR from "custom-swr";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
export const updatePetWithFormQueryKey = (petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : [])] as const;
|
|
6
|
+
|
|
7
|
+
export type UpdatePetWithFormQueryKey = ReturnType<typeof updatePetWithFormQueryKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @summary Updates a pet in the store with form data
|
|
11
|
+
* @link /pet/:petId
|
|
12
|
+
*/
|
|
13
|
+
async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
|
|
14
|
+
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "POST", url: `/pet/${petId}`, params, ...config });
|
|
15
|
+
return res.data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function updatePetWithFormQueryOptions(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
|
|
19
|
+
return {
|
|
20
|
+
fetcher: async () => {
|
|
21
|
+
return updatePetWithForm(petId, params, config);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @summary Updates a pet in the store with form data
|
|
28
|
+
* @link /pet/:petId
|
|
29
|
+
*/
|
|
30
|
+
export function useUpdatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, options: {
|
|
31
|
+
query?: Parameters<typeof useSWR<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormQueryKey | null, any>>[2];
|
|
32
|
+
client?: Partial<RequestConfig>;
|
|
33
|
+
shouldFetch?: boolean;
|
|
34
|
+
} = {}) {
|
|
35
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
36
|
+
const queryKey = updatePetWithFormQueryKey(petId, params);
|
|
37
|
+
return useSWR<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormQueryKey | null>(shouldFetch ? queryKey : null, {
|
|
38
|
+
...updatePetWithFormQueryOptions(petId, params, config),
|
|
39
|
+
...queryOptions
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import useSWRMutation from "swr/mutation";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
|
|
6
|
+
|
|
7
|
+
export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @summary Updates a pet in the store with form data
|
|
11
|
+
* @link /pet/:petId
|
|
12
|
+
*/
|
|
13
|
+
async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
|
|
14
|
+
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "POST", url: `/pet/${petId}`, params, ...config });
|
|
15
|
+
return res.data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @summary Updates a pet in the store with form data
|
|
20
|
+
* @link /pet/:petId
|
|
21
|
+
*/
|
|
22
|
+
export function useUpdatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, options: {
|
|
23
|
+
mutation?: Parameters<typeof useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationKey>>[2];
|
|
24
|
+
client?: Partial<RequestConfig>;
|
|
25
|
+
shouldFetch?: boolean;
|
|
26
|
+
} = {}) {
|
|
27
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
28
|
+
const mutationKey = updatePetWithFormMutationKey();
|
|
29
|
+
return useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationKey | null>(shouldFetch ? mutationKey : null, async (_url) => {
|
|
30
|
+
return updatePetWithForm(petId, params, config);
|
|
31
|
+
}, mutationOptions);
|
|
32
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import useSWRMutation from "swr/mutation";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
|
|
6
|
+
|
|
7
|
+
export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @summary Updates a pet in the store with form data
|
|
11
|
+
* @link /pet/:petId
|
|
12
|
+
*/
|
|
13
|
+
async function updatePetWithForm({ petId }: {
|
|
14
|
+
petId: UpdatePetWithFormPathParams["petId"];
|
|
15
|
+
}, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
|
|
16
|
+
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "POST", url: `/pet/${petId}`, params, ...config });
|
|
17
|
+
return res.data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @summary Updates a pet in the store with form data
|
|
22
|
+
* @link /pet/:petId
|
|
23
|
+
*/
|
|
24
|
+
export function useUpdatePetWithForm({ petId }: {
|
|
25
|
+
petId: UpdatePetWithFormPathParams["petId"];
|
|
26
|
+
}, params?: UpdatePetWithFormQueryParams, options: {
|
|
27
|
+
mutation?: Parameters<typeof useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationKey>>[2];
|
|
28
|
+
client?: Partial<RequestConfig>;
|
|
29
|
+
shouldFetch?: boolean;
|
|
30
|
+
} = {}) {
|
|
31
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
|
|
32
|
+
const mutationKey = updatePetWithFormMutationKey();
|
|
33
|
+
return useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationKey | null>(shouldFetch ? mutationKey : null, async (_url) => {
|
|
34
|
+
return updatePetWithForm({ petId }, params, config);
|
|
35
|
+
}, mutationOptions);
|
|
36
|
+
}
|