@kubb/plugin-client 3.0.0-alpha.2 → 3.0.0-alpha.20
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 +13 -4
- package/client.ts +2 -2
- package/dist/chunk-54CFYFPX.js +176 -0
- package/dist/chunk-54CFYFPX.js.map +1 -0
- package/dist/chunk-HGQQGWKN.js +130 -0
- package/dist/chunk-HGQQGWKN.js.map +1 -0
- package/dist/chunk-HUIJQCWL.cjs +185 -0
- package/dist/chunk-HUIJQCWL.cjs.map +1 -0
- package/dist/chunk-NEK3OJBX.cjs +133 -0
- package/dist/chunk-NEK3OJBX.cjs.map +1 -0
- package/dist/client.cjs +16 -7
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +5 -6
- package/dist/client.js.map +1 -1
- package/dist/components.cjs +11 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +37 -7
- package/dist/components.d.ts +37 -7
- package/dist/components.js +2 -8
- 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 +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +11 -156
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -6
- package/dist/index.d.ts +1 -6
- package/dist/index.js +3 -161
- package/dist/index.js.map +1 -1
- package/dist/types-xPfBu1CW.d.cts +96 -0
- package/dist/types-xPfBu1CW.d.ts +96 -0
- package/package.json +21 -16
- package/src/components/Client.tsx +110 -211
- package/src/components/Operations.tsx +9 -75
- package/src/generators/__snapshots__/deletePet.ts +13 -0
- package/src/generators/__snapshots__/deletePetObject.ts +15 -0
- package/src/generators/__snapshots__/findByTags.ts +13 -0
- package/src/generators/__snapshots__/findByTagsFull.ts +13 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +13 -0
- package/src/generators/__snapshots__/findByTagsWithZodFull.ts +13 -0
- package/src/generators/__snapshots__/importPath.ts +13 -0
- package/src/generators/__snapshots__/operations.ts +82 -0
- package/src/generators/__snapshots__/updatePetById.ts +12 -0
- package/src/generators/clientGenerator.tsx +67 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/operationsGenerator.tsx +26 -0
- package/src/plugin.ts +23 -40
- package/src/types.ts +24 -50
- package/dist/chunk-W57BRY5O.js +0 -201
- package/dist/chunk-W57BRY5O.js.map +0 -1
- package/dist/chunk-W7F5CMU6.cjs +0 -201
- package/dist/chunk-W7F5CMU6.cjs.map +0 -1
- package/dist/types-xK4X9e5d.d.cts +0 -228
- package/dist/types-xK4X9e5d.d.ts +0 -228
- package/src/OperationGenerator.tsx +0 -65
- package/src/components/__snapshots__/Client/showPetById.ts +0 -11
- package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
- package/src/components/__snapshots__/Query/showPetById.ts +0 -15
|
@@ -1,101 +1,123 @@
|
|
|
1
1
|
import { URLPath } from '@kubb/core/utils'
|
|
2
|
-
import { Parser, File, Function, useApp } from '@kubb/react'
|
|
3
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
4
|
-
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
5
|
-
import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
|
|
6
2
|
|
|
7
|
-
import { isOptional } from '@kubb/oas'
|
|
8
|
-
import type {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import type {
|
|
3
|
+
import { type Operation, isOptional } from '@kubb/oas'
|
|
4
|
+
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
5
|
+
import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
|
|
6
|
+
import { File, Function, FunctionParams } from '@kubb/react'
|
|
7
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
8
|
+
import type { PluginClient } from '../types.ts'
|
|
12
9
|
|
|
13
|
-
type
|
|
10
|
+
type Props = {
|
|
14
11
|
/**
|
|
15
12
|
* Name of the function
|
|
16
13
|
*/
|
|
17
14
|
name: string
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
15
|
+
isExportable?: boolean
|
|
16
|
+
isIndexable?: boolean
|
|
17
|
+
|
|
18
|
+
baseURL: string | undefined
|
|
19
|
+
dataReturnType: PluginClient['resolvedOptions']['dataReturnType']
|
|
20
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
21
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
22
|
+
typeSchemas: OperationSchemas
|
|
23
|
+
zodSchemas: OperationSchemas | undefined
|
|
24
|
+
operation: Operation
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type GetParamsProps = {
|
|
28
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
29
|
+
typeSchemas: OperationSchemas
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
33
|
+
return FunctionParams.factory({
|
|
34
|
+
pathParams: {
|
|
35
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
36
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
37
|
+
},
|
|
38
|
+
data: typeSchemas.request?.name
|
|
39
|
+
? {
|
|
40
|
+
type: typeSchemas.request?.name,
|
|
41
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
42
|
+
}
|
|
43
|
+
: undefined,
|
|
44
|
+
params: typeSchemas.queryParams?.name
|
|
45
|
+
? {
|
|
46
|
+
type: typeSchemas.queryParams?.name,
|
|
47
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
48
|
+
}
|
|
49
|
+
: undefined,
|
|
50
|
+
headers: typeSchemas.headerParams?.name
|
|
51
|
+
? {
|
|
52
|
+
type: typeSchemas.headerParams?.name,
|
|
53
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
54
|
+
}
|
|
55
|
+
: undefined,
|
|
56
|
+
config: {
|
|
57
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
58
|
+
default: '{}',
|
|
59
|
+
},
|
|
60
|
+
})
|
|
47
61
|
}
|
|
48
62
|
|
|
49
|
-
function
|
|
50
|
-
|
|
63
|
+
export function Client({
|
|
64
|
+
name,
|
|
65
|
+
isExportable = true,
|
|
66
|
+
isIndexable = true,
|
|
67
|
+
typeSchemas,
|
|
68
|
+
baseURL,
|
|
69
|
+
dataReturnType,
|
|
70
|
+
parser,
|
|
71
|
+
zodSchemas,
|
|
72
|
+
pathParamsType,
|
|
73
|
+
operation,
|
|
74
|
+
}: Props): KubbNode {
|
|
75
|
+
const path = new URLPath(operation.path)
|
|
76
|
+
const contentType = operation.getContentType()
|
|
77
|
+
const isFormData = contentType === 'multipart/form-data'
|
|
51
78
|
const headers = [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
79
|
+
contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,
|
|
80
|
+
typeSchemas.headerParams?.name ? '...headers' : undefined,
|
|
81
|
+
].filter(Boolean)
|
|
82
|
+
|
|
83
|
+
const generics = [
|
|
84
|
+
typeSchemas.response.name,
|
|
85
|
+
typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown',
|
|
86
|
+
typeSchemas.request?.name || 'unknown',
|
|
87
|
+
].filter(Boolean)
|
|
88
|
+
const params = getParams({ pathParamsType, typeSchemas })
|
|
89
|
+
const clientParams = FunctionParams.factory({
|
|
90
|
+
config: {
|
|
59
91
|
mode: 'object',
|
|
60
92
|
children: {
|
|
61
93
|
method: {
|
|
62
|
-
|
|
63
|
-
value: JSON.stringify(client.method),
|
|
94
|
+
value: JSON.stringify(operation.method),
|
|
64
95
|
},
|
|
65
96
|
url: {
|
|
66
|
-
|
|
67
|
-
value: client.path.template,
|
|
97
|
+
value: path.template,
|
|
68
98
|
},
|
|
69
|
-
baseURL:
|
|
99
|
+
baseURL: baseURL
|
|
70
100
|
? {
|
|
71
|
-
|
|
72
|
-
value: JSON.stringify(client.baseURL),
|
|
101
|
+
value: JSON.stringify(baseURL),
|
|
73
102
|
}
|
|
74
103
|
: undefined,
|
|
75
|
-
params:
|
|
104
|
+
params: typeSchemas.queryParams?.name ? {} : undefined,
|
|
105
|
+
data: typeSchemas.request?.name
|
|
76
106
|
? {
|
|
77
|
-
type: 'any',
|
|
78
|
-
}
|
|
79
|
-
: undefined,
|
|
80
|
-
data: client.withData
|
|
81
|
-
? {
|
|
82
|
-
type: 'any',
|
|
83
107
|
value: isFormData ? 'formData' : undefined,
|
|
84
108
|
}
|
|
85
109
|
: undefined,
|
|
86
110
|
headers: headers.length
|
|
87
111
|
? {
|
|
88
|
-
|
|
89
|
-
value: headers.length ? `{ ${headers}, ...options.headers }` : undefined,
|
|
112
|
+
value: headers.length ? `{ ${headers.join(', ')}, ...config.headers }` : undefined,
|
|
90
113
|
}
|
|
91
114
|
: undefined,
|
|
92
|
-
|
|
93
|
-
type: 'any',
|
|
115
|
+
config: {
|
|
94
116
|
mode: 'inlineSpread',
|
|
95
117
|
},
|
|
96
118
|
},
|
|
97
119
|
},
|
|
98
|
-
}
|
|
120
|
+
})
|
|
99
121
|
|
|
100
122
|
const formData = isFormData
|
|
101
123
|
? `
|
|
@@ -109,152 +131,29 @@ function Template({ name, generics, returnType, params, JSDoc, client }: Templat
|
|
|
109
131
|
})
|
|
110
132
|
}
|
|
111
133
|
`
|
|
112
|
-
:
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<Function name={name} async export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
|
|
116
|
-
{formData || ''}
|
|
117
|
-
<Function.Call name="res" to={<Function name="client" async generics={client.generics} params={clientParams} />} />
|
|
118
|
-
<Function.Return>{client.dataReturnType === 'data' ? 'res.data' : 'res'}</Function.Return>
|
|
119
|
-
</Function>
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
type RootTemplateProps = {
|
|
124
|
-
children?: React.ReactNode
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function RootTemplate({ children }: RootTemplateProps) {
|
|
128
|
-
const {
|
|
129
|
-
plugin: {
|
|
130
|
-
options: {
|
|
131
|
-
client: { importPath },
|
|
132
|
-
extName,
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
} = useApp<PluginClient>()
|
|
136
|
-
|
|
137
|
-
const { getSchemas, getFile } = useOperationManager()
|
|
138
|
-
const operation = useOperation()
|
|
139
|
-
|
|
140
|
-
const file = getFile(operation)
|
|
141
|
-
const fileType = getFile(operation, { pluginKey: [pluginTsName] })
|
|
142
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
143
|
-
|
|
144
|
-
return (
|
|
145
|
-
<Parser language="typescript">
|
|
146
|
-
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
147
|
-
<File.Import name={'client'} path={importPath} />
|
|
148
|
-
<File.Import name={['ResponseConfig']} path={importPath} isTypeOnly />
|
|
149
|
-
<File.Import
|
|
150
|
-
extName={extName}
|
|
151
|
-
name={[schemas.request?.name, schemas.response.name, schemas.pathParams?.name, schemas.queryParams?.name, schemas.headerParams?.name].filter(Boolean)}
|
|
152
|
-
root={file.path}
|
|
153
|
-
path={fileType.path}
|
|
154
|
-
isTypeOnly
|
|
155
|
-
/>
|
|
156
|
-
<File.Source>{children}</File.Source>
|
|
157
|
-
</File>
|
|
158
|
-
</Parser>
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const defaultTemplates = { default: Template, root: RootTemplate } as const
|
|
163
|
-
|
|
164
|
-
type Templates = Partial<typeof defaultTemplates>
|
|
165
|
-
|
|
166
|
-
type ClientProps = {
|
|
167
|
-
baseURL: string | undefined
|
|
168
|
-
/**
|
|
169
|
-
* This will make it possible to override the default behaviour.
|
|
170
|
-
*/
|
|
171
|
-
Template?: ComponentType<ComponentProps<typeof Template>>
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function Client({ baseURL, Template = defaultTemplates.default }: ClientProps): KubbNode {
|
|
175
|
-
const {
|
|
176
|
-
plugin: {
|
|
177
|
-
options: { client, dataReturnType, pathParamsType },
|
|
178
|
-
},
|
|
179
|
-
} = useApp<PluginClient>()
|
|
180
|
-
|
|
181
|
-
const { getSchemas, getName } = useOperationManager()
|
|
182
|
-
const operation = useOperation()
|
|
183
|
-
|
|
184
|
-
const contentType = operation.getContentType()
|
|
185
|
-
const name = getName(operation, { type: 'function' })
|
|
186
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
187
|
-
|
|
188
|
-
return (
|
|
189
|
-
<Template
|
|
190
|
-
name={name}
|
|
191
|
-
params={{
|
|
192
|
-
pathParams: {
|
|
193
|
-
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
194
|
-
children: getPathParams(schemas.pathParams, { typed: true }),
|
|
195
|
-
},
|
|
196
|
-
data: schemas.request?.name
|
|
197
|
-
? {
|
|
198
|
-
type: schemas.request?.name,
|
|
199
|
-
optional: isOptional(schemas.request?.schema),
|
|
200
|
-
}
|
|
201
|
-
: undefined,
|
|
202
|
-
params: schemas.queryParams?.name
|
|
203
|
-
? {
|
|
204
|
-
type: schemas.queryParams?.name,
|
|
205
|
-
optional: isOptional(schemas.queryParams?.schema),
|
|
206
|
-
}
|
|
207
|
-
: undefined,
|
|
208
|
-
headers: schemas.headerParams?.name
|
|
209
|
-
? {
|
|
210
|
-
type: schemas.headerParams?.name,
|
|
211
|
-
optional: isOptional(schemas.headerParams?.schema),
|
|
212
|
-
}
|
|
213
|
-
: undefined,
|
|
214
|
-
options: {
|
|
215
|
-
type: 'Partial<Parameters<typeof client>[0]>',
|
|
216
|
-
default: '{}',
|
|
217
|
-
},
|
|
218
|
-
}}
|
|
219
|
-
returnType={dataReturnType === 'data' ? `ResponseConfig<${schemas.response.name}>["data"]` : `ResponseConfig<${schemas.response.name}>`}
|
|
220
|
-
JSDoc={{
|
|
221
|
-
comments: getComments(operation),
|
|
222
|
-
}}
|
|
223
|
-
client={{
|
|
224
|
-
// only set baseURL from serverIndex(swagger) when no custom client(default) is used
|
|
225
|
-
baseURL: client.importPath === '@kubb/plugin-client/client' ? baseURL : undefined,
|
|
226
|
-
generics: [schemas.response.name, schemas.request?.name].filter(Boolean),
|
|
227
|
-
dataReturnType,
|
|
228
|
-
withQueryParams: !!schemas.queryParams?.name,
|
|
229
|
-
withData: !!schemas.request?.name,
|
|
230
|
-
withHeaders: !!schemas.headerParams?.name,
|
|
231
|
-
method: operation.method,
|
|
232
|
-
path: new URLPath(operation.path),
|
|
233
|
-
contentType,
|
|
234
|
-
}}
|
|
235
|
-
/>
|
|
236
|
-
)
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
type FileProps = {
|
|
240
|
-
baseURL: string | undefined
|
|
241
|
-
/**
|
|
242
|
-
* This will make it possible to override the default behaviour.
|
|
243
|
-
*/
|
|
244
|
-
templates?: Templates
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
Client.File = function ({ baseURL, ...props }: FileProps): KubbNode {
|
|
248
|
-
const templates = { ...defaultTemplates, ...props.templates }
|
|
249
|
-
|
|
250
|
-
const Template = templates.default
|
|
251
|
-
const RootTemplate = templates.root
|
|
134
|
+
: ''
|
|
252
135
|
|
|
253
136
|
return (
|
|
254
|
-
<
|
|
255
|
-
<
|
|
256
|
-
|
|
137
|
+
<File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>
|
|
138
|
+
<Function
|
|
139
|
+
name={name}
|
|
140
|
+
async
|
|
141
|
+
export={isExportable}
|
|
142
|
+
params={params.toConstructor()}
|
|
143
|
+
JSDoc={{
|
|
144
|
+
comments: getComments(operation),
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
{formData}
|
|
148
|
+
{`const res = await client<${generics.join(', ')}>(${clientParams.toCall()})`}
|
|
149
|
+
<br />
|
|
150
|
+
{dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}
|
|
151
|
+
{dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}
|
|
152
|
+
{dataReturnType === 'full' && parser === 'client' && 'return res'}
|
|
153
|
+
{dataReturnType === 'data' && parser === 'client' && 'return res.data'}
|
|
154
|
+
</Function>
|
|
155
|
+
</File.Source>
|
|
257
156
|
)
|
|
258
157
|
}
|
|
259
158
|
|
|
260
|
-
Client.
|
|
159
|
+
Client.getParams = getParams
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
import { URLPath } from '@kubb/core/utils'
|
|
2
|
-
import {
|
|
3
|
-
import { Const, File, Parser, useApp } from '@kubb/react'
|
|
2
|
+
import { Const, File } from '@kubb/react'
|
|
4
3
|
|
|
5
4
|
import type { HttpMethod, Operation } from '@kubb/oas'
|
|
6
|
-
import type { KubbNode } from '@kubb/react'
|
|
7
|
-
import type { ComponentProps, ComponentType } from 'react'
|
|
8
|
-
import type { FileMeta, PluginClient } from '../types.ts'
|
|
9
5
|
|
|
10
|
-
type
|
|
11
|
-
/**
|
|
12
|
-
* Name of the function
|
|
13
|
-
*/
|
|
6
|
+
type OperationsProps = {
|
|
14
7
|
name: string
|
|
15
|
-
operations: Operation
|
|
16
|
-
baseURL: string | undefined
|
|
8
|
+
operations: Array<Operation>
|
|
17
9
|
}
|
|
18
10
|
|
|
19
|
-
function
|
|
11
|
+
export function Operations({ name, operations }: OperationsProps) {
|
|
20
12
|
const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}
|
|
21
13
|
|
|
22
14
|
operations.forEach((operation) => {
|
|
@@ -25,70 +17,12 @@ function Template({ name, operations }: TemplateProps): KubbNode {
|
|
|
25
17
|
method: operation.method,
|
|
26
18
|
}
|
|
27
19
|
})
|
|
28
|
-
return (
|
|
29
|
-
<Const name={name} export asConst>
|
|
30
|
-
{JSON.stringify(operationsObject, undefined, 2)}
|
|
31
|
-
</Const>
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type RootTemplateProps = {
|
|
36
|
-
children?: React.ReactNode
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function RootTemplate({ children }: RootTemplateProps) {
|
|
40
|
-
const {
|
|
41
|
-
pluginManager,
|
|
42
|
-
plugin: { key: pluginKey },
|
|
43
|
-
} = useApp<PluginClient>()
|
|
44
|
-
const file = pluginManager.getFile({ name: 'operations', extName: '.ts', pluginKey })
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<Parser language="typescript">
|
|
48
|
-
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta} exportable={false}>
|
|
49
|
-
<File.Source>{children}</File.Source>
|
|
50
|
-
</File>
|
|
51
|
-
</Parser>
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const defaultTemplates = { default: Template, root: RootTemplate } as const
|
|
56
|
-
|
|
57
|
-
type Templates = Partial<typeof defaultTemplates>
|
|
58
|
-
|
|
59
|
-
type Props = {
|
|
60
|
-
baseURL: string | undefined
|
|
61
|
-
/**
|
|
62
|
-
* This will make it possible to override the default behaviour.
|
|
63
|
-
*/
|
|
64
|
-
Template?: ComponentType<ComponentProps<typeof Template>>
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function Operations({ baseURL, Template = defaultTemplates.default }: Props): KubbNode {
|
|
68
|
-
const operations = useOperations()
|
|
69
|
-
|
|
70
|
-
return <Template baseURL={baseURL} name="operations" operations={operations} />
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type FileProps = {
|
|
74
|
-
baseURL: string | undefined
|
|
75
|
-
/**
|
|
76
|
-
* This will make it possible to override the default behaviour.
|
|
77
|
-
*/
|
|
78
|
-
templates?: Templates
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
Operations.File = function ({ baseURL, ...props }: FileProps): KubbNode {
|
|
82
|
-
const templates = { ...defaultTemplates, ...props.templates }
|
|
83
|
-
|
|
84
|
-
const Template = templates.default
|
|
85
|
-
const RootTemplate = templates.root
|
|
86
20
|
|
|
87
21
|
return (
|
|
88
|
-
<
|
|
89
|
-
<
|
|
90
|
-
|
|
22
|
+
<File.Source name={name} isExportable isIndexable>
|
|
23
|
+
<Const name={name} export asConst>
|
|
24
|
+
{JSON.stringify(operationsObject, undefined, 2)}
|
|
25
|
+
</Const>
|
|
26
|
+
</File.Source>
|
|
91
27
|
)
|
|
92
28
|
}
|
|
93
|
-
|
|
94
|
-
Operations.templates = defaultTemplates
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import client from "@kubb/plugin-client/client";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description delete a pet
|
|
7
|
+
* @summary Deletes a pet
|
|
8
|
+
* @link /pet/:petId
|
|
9
|
+
*/
|
|
10
|
+
export async function deletePet(petId: DeletePetPathParams["petId"], headers?: DeletePetHeaderParams, config: Partial<RequestConfig> = {}) {
|
|
11
|
+
const res = await client<DeletePetMutationResponse, DeletePet400, unknown>({ method: "delete", url: `/pet/${petId}`, headers: { ...headers, ...config.headers }, ...config });
|
|
12
|
+
return res.data;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import client from "@kubb/plugin-client/client";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description delete a pet
|
|
7
|
+
* @summary Deletes a pet
|
|
8
|
+
* @link /pet/:petId
|
|
9
|
+
*/
|
|
10
|
+
export async function deletePet({ petId }: {
|
|
11
|
+
petId: DeletePetPathParams["petId"];
|
|
12
|
+
}, headers?: DeletePetHeaderParams, config: Partial<RequestConfig> = {}) {
|
|
13
|
+
const res = await client<DeletePetMutationResponse, DeletePet400, unknown>({ method: "delete", url: `/pet/${petId}`, headers: { ...headers, ...config.headers }, ...config });
|
|
14
|
+
return res.data;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import client from "@kubb/plugin-client/client";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
7
|
+
* @summary Finds Pets by tags
|
|
8
|
+
* @link /pet/findByTags
|
|
9
|
+
*/
|
|
10
|
+
export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
11
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
|
|
12
|
+
return res.data;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import client from "@kubb/plugin-client/client";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
7
|
+
* @summary Finds Pets by tags
|
|
8
|
+
* @link /pet/findByTags
|
|
9
|
+
*/
|
|
10
|
+
export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
11
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
|
|
12
|
+
return res;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import client from "@kubb/plugin-client/client";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
7
|
+
* @summary Finds Pets by tags
|
|
8
|
+
* @link /pet/findByTags
|
|
9
|
+
*/
|
|
10
|
+
export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
11
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
|
|
12
|
+
return findPetsByTagsQueryResponse.parse(res.data);
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import client from "@kubb/plugin-client/client";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
7
|
+
* @summary Finds Pets by tags
|
|
8
|
+
* @link /pet/findByTags
|
|
9
|
+
*/
|
|
10
|
+
export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
11
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
|
|
12
|
+
return { ...res, data: findPetsByTagsQueryResponse.parse(res.data) };
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import client from "axios";
|
|
3
|
+
import type { RequestConfig } from "axios";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
7
|
+
* @summary Finds Pets by tags
|
|
8
|
+
* @link /pet/findByTags
|
|
9
|
+
*/
|
|
10
|
+
export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
|
|
11
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
|
|
12
|
+
return res.data;
|
|
13
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export const operations = {
|
|
2
|
+
"updatePet": {
|
|
3
|
+
"path": "/pet",
|
|
4
|
+
"method": "put"
|
|
5
|
+
},
|
|
6
|
+
"addPet": {
|
|
7
|
+
"path": "/pet",
|
|
8
|
+
"method": "post"
|
|
9
|
+
},
|
|
10
|
+
"findPetsByStatus": {
|
|
11
|
+
"path": "/pet/findByStatus",
|
|
12
|
+
"method": "get"
|
|
13
|
+
},
|
|
14
|
+
"findPetsByTags": {
|
|
15
|
+
"path": "/pet/findByTags",
|
|
16
|
+
"method": "get"
|
|
17
|
+
},
|
|
18
|
+
"getPetById": {
|
|
19
|
+
"path": "/pet/:petId",
|
|
20
|
+
"method": "get"
|
|
21
|
+
},
|
|
22
|
+
"updatePetWithForm": {
|
|
23
|
+
"path": "/pet/:petId",
|
|
24
|
+
"method": "post"
|
|
25
|
+
},
|
|
26
|
+
"deletePet": {
|
|
27
|
+
"path": "/pet/:petId",
|
|
28
|
+
"method": "delete"
|
|
29
|
+
},
|
|
30
|
+
"uploadFile": {
|
|
31
|
+
"path": "/pet/:petId/uploadImage",
|
|
32
|
+
"method": "post"
|
|
33
|
+
},
|
|
34
|
+
"getInventory": {
|
|
35
|
+
"path": "/store/inventory",
|
|
36
|
+
"method": "get"
|
|
37
|
+
},
|
|
38
|
+
"placeOrder": {
|
|
39
|
+
"path": "/store/order",
|
|
40
|
+
"method": "post"
|
|
41
|
+
},
|
|
42
|
+
"placeOrderPatch": {
|
|
43
|
+
"path": "/store/order",
|
|
44
|
+
"method": "patch"
|
|
45
|
+
},
|
|
46
|
+
"getOrderById": {
|
|
47
|
+
"path": "/store/order/:orderId",
|
|
48
|
+
"method": "get"
|
|
49
|
+
},
|
|
50
|
+
"deleteOrder": {
|
|
51
|
+
"path": "/store/order/:orderId",
|
|
52
|
+
"method": "delete"
|
|
53
|
+
},
|
|
54
|
+
"createUser": {
|
|
55
|
+
"path": "/user",
|
|
56
|
+
"method": "post"
|
|
57
|
+
},
|
|
58
|
+
"createUsersWithListInput": {
|
|
59
|
+
"path": "/user/createWithList",
|
|
60
|
+
"method": "post"
|
|
61
|
+
},
|
|
62
|
+
"loginUser": {
|
|
63
|
+
"path": "/user/login",
|
|
64
|
+
"method": "get"
|
|
65
|
+
},
|
|
66
|
+
"logoutUser": {
|
|
67
|
+
"path": "/user/logout",
|
|
68
|
+
"method": "get"
|
|
69
|
+
},
|
|
70
|
+
"getUserByName": {
|
|
71
|
+
"path": "/user/:username",
|
|
72
|
+
"method": "get"
|
|
73
|
+
},
|
|
74
|
+
"updateUser": {
|
|
75
|
+
"path": "/user/:username",
|
|
76
|
+
"method": "put"
|
|
77
|
+
},
|
|
78
|
+
"deleteUser": {
|
|
79
|
+
"path": "/user/:username",
|
|
80
|
+
"method": "delete"
|
|
81
|
+
}
|
|
82
|
+
} as const;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import client from "@kubb/plugin-client/client";
|
|
3
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @summary Updates a pet in the store with form data
|
|
7
|
+
* @link /pet/:petId
|
|
8
|
+
*/
|
|
9
|
+
export async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
|
|
10
|
+
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "post", url: `/pet/${petId}`, params, ...config });
|
|
11
|
+
return res.data;
|
|
12
|
+
}
|