@kubb/plugin-client 4.8.0 → 4.9.0
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/dist/{Operations-BCvft948.js → Operations-B6I1tCOx.js} +118 -5
- package/dist/Operations-B6I1tCOx.js.map +1 -0
- package/dist/{Operations-CP_QErFp.cjs → Operations-BVIrtQ0H.cjs} +122 -3
- package/dist/Operations-BVIrtQ0H.cjs.map +1 -0
- package/dist/components.cjs +2 -1
- package/dist/components.d.cts +53 -2
- package/dist/components.d.ts +53 -2
- package/dist/components.js +2 -2
- package/dist/generators-CsFgdAtO.js +424 -0
- package/dist/generators-CsFgdAtO.js.map +1 -0
- package/dist/{generators-9lVWKcq3.cjs → generators-dDr1GP7q.cjs} +198 -2
- package/dist/generators-dDr1GP7q.cjs.map +1 -0
- package/dist/generators.cjs +3 -2
- package/dist/generators.d.cts +5 -2
- package/dist/generators.d.ts +5 -2
- package/dist/generators.js +3 -3
- package/dist/index.cjs +11 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/{types-CRHoY-hv.d.ts → types-DDd1VM_Z.d.ts} +9 -1
- package/dist/{types-DxXfO6iR.d.cts → types-MSth0FPg.d.cts} +9 -1
- package/package.json +6 -6
- package/src/components/ClassClient.tsx +235 -0
- package/src/components/Client.tsx +3 -2
- package/src/components/index.ts +1 -0
- package/src/generators/__snapshots__/Pet.ts +186 -0
- package/src/generators/__snapshots__/Store.ts +109 -0
- package/src/generators/__snapshots__/User.ts +147 -0
- package/src/generators/classClientGenerator.tsx +231 -0
- package/src/generators/index.ts +1 -0
- package/src/plugin.ts +10 -2
- package/src/types.ts +8 -0
- package/dist/Operations-BCvft948.js.map +0 -1
- package/dist/Operations-CP_QErFp.cjs.map +0 -1
- package/dist/generators-9lVWKcq3.cjs.map +0 -1
- package/dist/generators-BQlm15sh.js +0 -234
- package/dist/generators-BQlm15sh.js.map +0 -1
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { buildJSDoc, URLPath } from '@kubb/core/utils'
|
|
2
|
+
import type { Operation } from '@kubb/oas'
|
|
3
|
+
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
4
|
+
import { getComments } from '@kubb/plugin-oas/utils'
|
|
5
|
+
import { File, FunctionParams } from '@kubb/react-fabric'
|
|
6
|
+
import type { KubbNode } from '@kubb/react-fabric/types'
|
|
7
|
+
import type { PluginClient } from '../types.ts'
|
|
8
|
+
|
|
9
|
+
import { Client } from './Client.tsx'
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
/**
|
|
13
|
+
* Name of the class
|
|
14
|
+
*/
|
|
15
|
+
name: string
|
|
16
|
+
isExportable?: boolean
|
|
17
|
+
isIndexable?: boolean
|
|
18
|
+
operations: Array<{
|
|
19
|
+
operation: Operation
|
|
20
|
+
name: string
|
|
21
|
+
typeSchemas: OperationSchemas
|
|
22
|
+
zodSchemas: OperationSchemas | undefined
|
|
23
|
+
}>
|
|
24
|
+
baseURL: string | undefined
|
|
25
|
+
dataReturnType: PluginClient['resolvedOptions']['dataReturnType']
|
|
26
|
+
paramsCasing: PluginClient['resolvedOptions']['paramsCasing']
|
|
27
|
+
paramsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
28
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
29
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
30
|
+
children?: KubbNode
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type GenerateMethodProps = {
|
|
34
|
+
operation: Operation
|
|
35
|
+
name: string
|
|
36
|
+
typeSchemas: OperationSchemas
|
|
37
|
+
zodSchemas: OperationSchemas | undefined
|
|
38
|
+
baseURL: string | undefined
|
|
39
|
+
dataReturnType: PluginClient['resolvedOptions']['dataReturnType']
|
|
40
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
41
|
+
paramsType: PluginClient['resolvedOptions']['paramsType']
|
|
42
|
+
paramsCasing: PluginClient['resolvedOptions']['paramsCasing']
|
|
43
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function buildHeaders(contentType: string, hasHeaderParams: boolean): Array<string> {
|
|
47
|
+
return [
|
|
48
|
+
contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,
|
|
49
|
+
hasHeaderParams ? '...headers' : undefined,
|
|
50
|
+
].filter(Boolean) as Array<string>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function buildGenerics(typeSchemas: OperationSchemas): Array<string> {
|
|
54
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
55
|
+
return [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function buildClientParams({
|
|
59
|
+
operation,
|
|
60
|
+
path,
|
|
61
|
+
baseURL,
|
|
62
|
+
typeSchemas,
|
|
63
|
+
isFormData,
|
|
64
|
+
headers,
|
|
65
|
+
}: {
|
|
66
|
+
operation: Operation
|
|
67
|
+
path: URLPath
|
|
68
|
+
baseURL: string | undefined
|
|
69
|
+
typeSchemas: OperationSchemas
|
|
70
|
+
isFormData: boolean
|
|
71
|
+
headers: Array<string>
|
|
72
|
+
}) {
|
|
73
|
+
return FunctionParams.factory({
|
|
74
|
+
config: {
|
|
75
|
+
mode: 'object',
|
|
76
|
+
children: {
|
|
77
|
+
method: {
|
|
78
|
+
value: JSON.stringify(operation.method.toUpperCase()),
|
|
79
|
+
},
|
|
80
|
+
url: {
|
|
81
|
+
value: path.template,
|
|
82
|
+
},
|
|
83
|
+
baseURL: baseURL
|
|
84
|
+
? {
|
|
85
|
+
value: JSON.stringify(baseURL),
|
|
86
|
+
}
|
|
87
|
+
: undefined,
|
|
88
|
+
params: typeSchemas.queryParams?.name ? {} : undefined,
|
|
89
|
+
data: typeSchemas.request?.name
|
|
90
|
+
? {
|
|
91
|
+
value: isFormData ? 'formData as FormData' : 'requestData',
|
|
92
|
+
}
|
|
93
|
+
: undefined,
|
|
94
|
+
requestConfig: {
|
|
95
|
+
mode: 'inlineSpread',
|
|
96
|
+
},
|
|
97
|
+
headers: headers.length
|
|
98
|
+
? {
|
|
99
|
+
value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,
|
|
100
|
+
}
|
|
101
|
+
: undefined,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function buildRequestDataLine({
|
|
108
|
+
parser,
|
|
109
|
+
zodSchemas,
|
|
110
|
+
typeSchemas,
|
|
111
|
+
}: {
|
|
112
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
113
|
+
zodSchemas: OperationSchemas | undefined
|
|
114
|
+
typeSchemas: OperationSchemas
|
|
115
|
+
}): string {
|
|
116
|
+
if (parser === 'zod' && zodSchemas?.request?.name) {
|
|
117
|
+
return `const requestData = ${zodSchemas.request.name}.parse(data)`
|
|
118
|
+
}
|
|
119
|
+
if (typeSchemas?.request?.name) {
|
|
120
|
+
return 'const requestData = data'
|
|
121
|
+
}
|
|
122
|
+
return ''
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function buildFormDataLine(isFormData: boolean, hasRequest: boolean): string {
|
|
126
|
+
return isFormData && hasRequest ? 'const formData = buildFormData(requestData)' : ''
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function buildReturnStatement({
|
|
130
|
+
dataReturnType,
|
|
131
|
+
parser,
|
|
132
|
+
zodSchemas,
|
|
133
|
+
}: {
|
|
134
|
+
dataReturnType: PluginClient['resolvedOptions']['dataReturnType']
|
|
135
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
136
|
+
zodSchemas: OperationSchemas | undefined
|
|
137
|
+
}): string {
|
|
138
|
+
if (dataReturnType === 'full' && parser === 'zod' && zodSchemas) {
|
|
139
|
+
return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`
|
|
140
|
+
}
|
|
141
|
+
if (dataReturnType === 'data' && parser === 'zod' && zodSchemas) {
|
|
142
|
+
return `return ${zodSchemas.response.name}.parse(res.data)`
|
|
143
|
+
}
|
|
144
|
+
if (dataReturnType === 'full' && parser === 'client') {
|
|
145
|
+
return 'return res'
|
|
146
|
+
}
|
|
147
|
+
return 'return res.data'
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function generateMethod({
|
|
151
|
+
operation,
|
|
152
|
+
name,
|
|
153
|
+
typeSchemas,
|
|
154
|
+
zodSchemas,
|
|
155
|
+
baseURL,
|
|
156
|
+
dataReturnType,
|
|
157
|
+
parser,
|
|
158
|
+
paramsType,
|
|
159
|
+
paramsCasing,
|
|
160
|
+
pathParamsType,
|
|
161
|
+
}: GenerateMethodProps): string {
|
|
162
|
+
const path = new URLPath(operation.path, { casing: paramsCasing })
|
|
163
|
+
const contentType = operation.getContentType()
|
|
164
|
+
const isFormData = contentType === 'multipart/form-data'
|
|
165
|
+
const headers = buildHeaders(contentType, !!typeSchemas.headerParams?.name)
|
|
166
|
+
const generics = buildGenerics(typeSchemas)
|
|
167
|
+
const params = ClassClient.getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable: true })
|
|
168
|
+
const clientParams = buildClientParams({ operation, path, baseURL, typeSchemas, isFormData, headers })
|
|
169
|
+
const jsdoc = buildJSDoc(getComments(operation))
|
|
170
|
+
|
|
171
|
+
const requestDataLine = buildRequestDataLine({ parser, zodSchemas, typeSchemas })
|
|
172
|
+
const formDataLine = buildFormDataLine(isFormData, !!typeSchemas?.request?.name)
|
|
173
|
+
const returnStatement = buildReturnStatement({ dataReturnType, parser, zodSchemas })
|
|
174
|
+
|
|
175
|
+
const methodBody = [
|
|
176
|
+
'const { client: request = this.#client, ...requestConfig } = config',
|
|
177
|
+
'',
|
|
178
|
+
requestDataLine,
|
|
179
|
+
formDataLine,
|
|
180
|
+
`const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`,
|
|
181
|
+
returnStatement,
|
|
182
|
+
]
|
|
183
|
+
.filter(Boolean)
|
|
184
|
+
.map((line) => ` ${line}`)
|
|
185
|
+
.join('\n')
|
|
186
|
+
|
|
187
|
+
return `${jsdoc}async ${name}(${params.toConstructor()}) {\n${methodBody}\n }`
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function ClassClient({
|
|
191
|
+
name,
|
|
192
|
+
isExportable = true,
|
|
193
|
+
isIndexable = true,
|
|
194
|
+
operations,
|
|
195
|
+
baseURL,
|
|
196
|
+
dataReturnType,
|
|
197
|
+
parser,
|
|
198
|
+
paramsType,
|
|
199
|
+
paramsCasing,
|
|
200
|
+
pathParamsType,
|
|
201
|
+
children,
|
|
202
|
+
}: Props): KubbNode {
|
|
203
|
+
const methods = operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) =>
|
|
204
|
+
generateMethod({
|
|
205
|
+
operation,
|
|
206
|
+
name: methodName,
|
|
207
|
+
typeSchemas,
|
|
208
|
+
zodSchemas,
|
|
209
|
+
baseURL,
|
|
210
|
+
dataReturnType,
|
|
211
|
+
parser,
|
|
212
|
+
paramsType,
|
|
213
|
+
paramsCasing,
|
|
214
|
+
pathParamsType,
|
|
215
|
+
}),
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
const classCode = `export class ${name} {
|
|
219
|
+
#client: typeof fetch
|
|
220
|
+
|
|
221
|
+
constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
222
|
+
this.#client = config.client || fetch
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
${methods.join('\n\n')}
|
|
226
|
+
}`
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>
|
|
230
|
+
{classCode}
|
|
231
|
+
{children}
|
|
232
|
+
</File.Source>
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
ClassClient.getParams = Client.getParams
|
|
@@ -212,8 +212,9 @@ export function Client({
|
|
|
212
212
|
{isConfigurable ? 'const { client: request = fetch, ...requestConfig } = config' : ''}
|
|
213
213
|
<br />
|
|
214
214
|
<br />
|
|
215
|
-
{parser === 'zod' && zodSchemas?.request?.name
|
|
216
|
-
|
|
215
|
+
{parser === 'zod' && zodSchemas?.request?.name
|
|
216
|
+
? `const requestData = ${zodSchemas.request.name}.parse(data)`
|
|
217
|
+
: typeSchemas?.request?.name && 'const requestData = data'}
|
|
217
218
|
<br />
|
|
218
219
|
{isFormData && typeSchemas?.request?.name && 'const formData = buildFormData(requestData)'}
|
|
219
220
|
<br />
|
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
6
|
+
import type {
|
|
7
|
+
UpdatePetMutationRequest,
|
|
8
|
+
UpdatePetMutationResponse,
|
|
9
|
+
UpdatePet400,
|
|
10
|
+
UpdatePet404,
|
|
11
|
+
UpdatePet405,
|
|
12
|
+
AddPetMutationRequest,
|
|
13
|
+
AddPetMutationResponse,
|
|
14
|
+
AddPet405,
|
|
15
|
+
FindPetsByStatusQueryResponse,
|
|
16
|
+
FindPetsByStatusQueryParams,
|
|
17
|
+
FindPetsByStatus400,
|
|
18
|
+
FindPetsByTagsQueryResponse,
|
|
19
|
+
FindPetsByTagsQueryParams,
|
|
20
|
+
FindPetsByTags400,
|
|
21
|
+
GetPetByIdQueryResponse,
|
|
22
|
+
GetPetByIdPathParams,
|
|
23
|
+
GetPetById400,
|
|
24
|
+
GetPetById404,
|
|
25
|
+
UpdatePetWithFormMutationResponse,
|
|
26
|
+
UpdatePetWithFormPathParams,
|
|
27
|
+
UpdatePetWithFormQueryParams,
|
|
28
|
+
UpdatePetWithForm405,
|
|
29
|
+
DeletePetMutationResponse,
|
|
30
|
+
DeletePetPathParams,
|
|
31
|
+
DeletePetHeaderParams,
|
|
32
|
+
DeletePet400,
|
|
33
|
+
UploadFileMutationRequest,
|
|
34
|
+
UploadFileMutationResponse,
|
|
35
|
+
UploadFilePathParams,
|
|
36
|
+
UploadFileQueryParams,
|
|
37
|
+
} from './findByTags'
|
|
38
|
+
import { buildFormData } from './test/.kubb/config'
|
|
39
|
+
import { fetch } from './test/.kubb/fetch'
|
|
40
|
+
|
|
41
|
+
export class Pet {
|
|
42
|
+
#client: typeof fetch
|
|
43
|
+
|
|
44
|
+
constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
45
|
+
this.#client = config.client || fetch
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @description Update an existing pet by Id
|
|
50
|
+
* @summary Update an existing pet
|
|
51
|
+
* {@link /pet}
|
|
52
|
+
*/
|
|
53
|
+
async updatePet(data: UpdatePetMutationRequest, config: Partial<RequestConfig<UpdatePetMutationRequest>> & { client?: typeof fetch } = {}) {
|
|
54
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
55
|
+
const requestData = data
|
|
56
|
+
const res = await request<UpdatePetMutationResponse, ResponseErrorConfig<UpdatePet400 | UpdatePet404 | UpdatePet405>, UpdatePetMutationRequest>({
|
|
57
|
+
method: 'PUT',
|
|
58
|
+
url: `/pet`,
|
|
59
|
+
data: requestData,
|
|
60
|
+
...requestConfig,
|
|
61
|
+
})
|
|
62
|
+
return res.data
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @description Add a new pet to the store
|
|
67
|
+
* @summary Add a new pet to the store
|
|
68
|
+
* {@link /pet}
|
|
69
|
+
*/
|
|
70
|
+
async addPet(data: AddPetMutationRequest, config: Partial<RequestConfig<AddPetMutationRequest>> & { client?: typeof fetch } = {}) {
|
|
71
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
72
|
+
const requestData = data
|
|
73
|
+
const res = await request<AddPetMutationResponse, ResponseErrorConfig<AddPet405>, AddPetMutationRequest>({
|
|
74
|
+
method: 'POST',
|
|
75
|
+
url: `/pet`,
|
|
76
|
+
data: requestData,
|
|
77
|
+
...requestConfig,
|
|
78
|
+
})
|
|
79
|
+
return res.data
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @description Multiple status values can be provided with comma separated strings
|
|
84
|
+
* @summary Finds Pets by status
|
|
85
|
+
* {@link /pet/findByStatus}
|
|
86
|
+
*/
|
|
87
|
+
async findPetsByStatus(params?: FindPetsByStatusQueryParams, config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
88
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
89
|
+
const res = await request<FindPetsByStatusQueryResponse, ResponseErrorConfig<FindPetsByStatus400>, unknown>({
|
|
90
|
+
method: 'GET',
|
|
91
|
+
url: `/pet/findByStatus`,
|
|
92
|
+
params,
|
|
93
|
+
...requestConfig,
|
|
94
|
+
})
|
|
95
|
+
return res.data
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
100
|
+
* @summary Finds Pets by tags
|
|
101
|
+
* {@link /pet/findByTags}
|
|
102
|
+
*/
|
|
103
|
+
async findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
104
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
105
|
+
const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
|
|
106
|
+
method: 'GET',
|
|
107
|
+
url: `/pet/findByTags`,
|
|
108
|
+
params,
|
|
109
|
+
...requestConfig,
|
|
110
|
+
})
|
|
111
|
+
return res.data
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @description Returns a single pet
|
|
116
|
+
* @summary Find pet by ID
|
|
117
|
+
* {@link /pet/:petId}
|
|
118
|
+
*/
|
|
119
|
+
async getPetById(petId: GetPetByIdPathParams['petId'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
120
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
121
|
+
const res = await request<GetPetByIdQueryResponse, ResponseErrorConfig<GetPetById400 | GetPetById404>, unknown>({
|
|
122
|
+
method: 'GET',
|
|
123
|
+
url: `/pet/${petId}`,
|
|
124
|
+
...requestConfig,
|
|
125
|
+
})
|
|
126
|
+
return res.data
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @summary Updates a pet in the store with form data
|
|
131
|
+
* {@link /pet/:petId}
|
|
132
|
+
*/
|
|
133
|
+
async updatePetWithForm(
|
|
134
|
+
petId: UpdatePetWithFormPathParams['petId'],
|
|
135
|
+
params?: UpdatePetWithFormQueryParams,
|
|
136
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
137
|
+
) {
|
|
138
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
139
|
+
const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, unknown>({
|
|
140
|
+
method: 'POST',
|
|
141
|
+
url: `/pet/${petId}`,
|
|
142
|
+
params,
|
|
143
|
+
...requestConfig,
|
|
144
|
+
})
|
|
145
|
+
return res.data
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @description delete a pet
|
|
150
|
+
* @summary Deletes a pet
|
|
151
|
+
* {@link /pet/:petId}
|
|
152
|
+
*/
|
|
153
|
+
async deletePet(petId: DeletePetPathParams['petId'], headers?: DeletePetHeaderParams, config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
154
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
155
|
+
const res = await request<DeletePetMutationResponse, ResponseErrorConfig<DeletePet400>, unknown>({
|
|
156
|
+
method: 'DELETE',
|
|
157
|
+
url: `/pet/${petId}`,
|
|
158
|
+
...requestConfig,
|
|
159
|
+
headers: { ...headers, ...requestConfig.headers },
|
|
160
|
+
})
|
|
161
|
+
return res.data
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @summary uploads an image
|
|
166
|
+
* {@link /pet/:petId/uploadImage}
|
|
167
|
+
*/
|
|
168
|
+
async uploadFile(
|
|
169
|
+
petId: UploadFilePathParams['petId'],
|
|
170
|
+
data: UploadFileMutationRequest,
|
|
171
|
+
params?: UploadFileQueryParams,
|
|
172
|
+
config: Partial<RequestConfig<UploadFileMutationRequest>> & { client?: typeof fetch } = {},
|
|
173
|
+
) {
|
|
174
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
175
|
+
const requestData = data
|
|
176
|
+
const formData = buildFormData(requestData)
|
|
177
|
+
const res = await request<UploadFileMutationResponse, ResponseErrorConfig<Error>, UploadFileMutationRequest>({
|
|
178
|
+
method: 'POST',
|
|
179
|
+
url: `/pet/${petId}/uploadImage`,
|
|
180
|
+
params,
|
|
181
|
+
data: formData as FormData,
|
|
182
|
+
...requestConfig,
|
|
183
|
+
})
|
|
184
|
+
return res.data
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
6
|
+
import type {
|
|
7
|
+
GetInventoryQueryResponse,
|
|
8
|
+
PlaceOrderMutationRequest,
|
|
9
|
+
PlaceOrderMutationResponse,
|
|
10
|
+
PlaceOrder405,
|
|
11
|
+
PlaceOrderPatchMutationRequest,
|
|
12
|
+
PlaceOrderPatchMutationResponse,
|
|
13
|
+
PlaceOrderPatch405,
|
|
14
|
+
GetOrderByIdQueryResponse,
|
|
15
|
+
GetOrderByIdPathParams,
|
|
16
|
+
GetOrderById400,
|
|
17
|
+
GetOrderById404,
|
|
18
|
+
DeleteOrderMutationResponse,
|
|
19
|
+
DeleteOrderPathParams,
|
|
20
|
+
DeleteOrder400,
|
|
21
|
+
DeleteOrder404,
|
|
22
|
+
} from './findByTags'
|
|
23
|
+
import { fetch } from './test/.kubb/fetch'
|
|
24
|
+
|
|
25
|
+
export class Store {
|
|
26
|
+
#client: typeof fetch
|
|
27
|
+
|
|
28
|
+
constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
29
|
+
this.#client = config.client || fetch
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @description Returns a map of status codes to quantities
|
|
34
|
+
* @summary Returns pet inventories by status
|
|
35
|
+
* {@link /store/inventory}
|
|
36
|
+
*/
|
|
37
|
+
async getInventory(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
38
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
39
|
+
const res = await request<GetInventoryQueryResponse, ResponseErrorConfig<Error>, unknown>({ method: 'GET', url: `/store/inventory`, ...requestConfig })
|
|
40
|
+
return res.data
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @description Place a new order in the store
|
|
45
|
+
* @summary Place an order for a pet
|
|
46
|
+
* {@link /store/order}
|
|
47
|
+
*/
|
|
48
|
+
async placeOrder(data?: PlaceOrderMutationRequest, config: Partial<RequestConfig<PlaceOrderMutationRequest>> & { client?: typeof fetch } = {}) {
|
|
49
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
50
|
+
const requestData = data
|
|
51
|
+
const res = await request<PlaceOrderMutationResponse, ResponseErrorConfig<PlaceOrder405>, PlaceOrderMutationRequest>({
|
|
52
|
+
method: 'POST',
|
|
53
|
+
url: `/store/order`,
|
|
54
|
+
data: requestData,
|
|
55
|
+
...requestConfig,
|
|
56
|
+
})
|
|
57
|
+
return res.data
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @description Place a new order in the store with patch
|
|
62
|
+
* @summary Place an order for a pet with patch
|
|
63
|
+
* {@link /store/order}
|
|
64
|
+
*/
|
|
65
|
+
async placeOrderPatch(
|
|
66
|
+
data?: PlaceOrderPatchMutationRequest,
|
|
67
|
+
config: Partial<RequestConfig<PlaceOrderPatchMutationRequest>> & { client?: typeof fetch } = {},
|
|
68
|
+
) {
|
|
69
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
70
|
+
const requestData = data
|
|
71
|
+
const res = await request<PlaceOrderPatchMutationResponse, ResponseErrorConfig<PlaceOrderPatch405>, PlaceOrderPatchMutationRequest>({
|
|
72
|
+
method: 'PATCH',
|
|
73
|
+
url: `/store/order`,
|
|
74
|
+
data: requestData,
|
|
75
|
+
...requestConfig,
|
|
76
|
+
})
|
|
77
|
+
return res.data
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
|
|
82
|
+
* @summary Find purchase order by ID
|
|
83
|
+
* {@link /store/order/:orderId}
|
|
84
|
+
*/
|
|
85
|
+
async getOrderById(orderId: GetOrderByIdPathParams['orderId'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
86
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
87
|
+
const res = await request<GetOrderByIdQueryResponse, ResponseErrorConfig<GetOrderById400 | GetOrderById404>, unknown>({
|
|
88
|
+
method: 'GET',
|
|
89
|
+
url: `/store/order/${orderId}`,
|
|
90
|
+
...requestConfig,
|
|
91
|
+
})
|
|
92
|
+
return res.data
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
|
97
|
+
* @summary Delete purchase order by ID
|
|
98
|
+
* {@link /store/order/:orderId}
|
|
99
|
+
*/
|
|
100
|
+
async deleteOrder(orderId: DeleteOrderPathParams['orderId'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
101
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
102
|
+
const res = await request<DeleteOrderMutationResponse, ResponseErrorConfig<DeleteOrder400 | DeleteOrder404>, unknown>({
|
|
103
|
+
method: 'DELETE',
|
|
104
|
+
url: `/store/order/${orderId}`,
|
|
105
|
+
...requestConfig,
|
|
106
|
+
})
|
|
107
|
+
return res.data
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
6
|
+
import type {
|
|
7
|
+
CreateUserMutationRequest,
|
|
8
|
+
CreateUserMutationResponse,
|
|
9
|
+
CreateUsersWithListInputMutationRequest,
|
|
10
|
+
CreateUsersWithListInputMutationResponse,
|
|
11
|
+
LoginUserQueryResponse,
|
|
12
|
+
LoginUserQueryParams,
|
|
13
|
+
LoginUser400,
|
|
14
|
+
LogoutUserQueryResponse,
|
|
15
|
+
GetUserByNameQueryResponse,
|
|
16
|
+
GetUserByNamePathParams,
|
|
17
|
+
GetUserByName400,
|
|
18
|
+
GetUserByName404,
|
|
19
|
+
UpdateUserMutationRequest,
|
|
20
|
+
UpdateUserMutationResponse,
|
|
21
|
+
UpdateUserPathParams,
|
|
22
|
+
DeleteUserMutationResponse,
|
|
23
|
+
DeleteUserPathParams,
|
|
24
|
+
DeleteUser400,
|
|
25
|
+
DeleteUser404,
|
|
26
|
+
} from './findByTags'
|
|
27
|
+
import { fetch } from './test/.kubb/fetch'
|
|
28
|
+
|
|
29
|
+
export class User {
|
|
30
|
+
#client: typeof fetch
|
|
31
|
+
|
|
32
|
+
constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
33
|
+
this.#client = config.client || fetch
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @description This can only be done by the logged in user.
|
|
38
|
+
* @summary Create user
|
|
39
|
+
* {@link /user}
|
|
40
|
+
*/
|
|
41
|
+
async createUser(data?: CreateUserMutationRequest, config: Partial<RequestConfig<CreateUserMutationRequest>> & { client?: typeof fetch } = {}) {
|
|
42
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
43
|
+
const requestData = data
|
|
44
|
+
const res = await request<CreateUserMutationResponse, ResponseErrorConfig<Error>, CreateUserMutationRequest>({
|
|
45
|
+
method: 'POST',
|
|
46
|
+
url: `/user`,
|
|
47
|
+
data: requestData,
|
|
48
|
+
...requestConfig,
|
|
49
|
+
})
|
|
50
|
+
return res.data
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @description Creates list of users with given input array
|
|
55
|
+
* @summary Creates list of users with given input array
|
|
56
|
+
* {@link /user/createWithList}
|
|
57
|
+
*/
|
|
58
|
+
async createUsersWithListInput(
|
|
59
|
+
data?: CreateUsersWithListInputMutationRequest,
|
|
60
|
+
config: Partial<RequestConfig<CreateUsersWithListInputMutationRequest>> & { client?: typeof fetch } = {},
|
|
61
|
+
) {
|
|
62
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
63
|
+
const requestData = data
|
|
64
|
+
const res = await request<CreateUsersWithListInputMutationResponse, ResponseErrorConfig<Error>, CreateUsersWithListInputMutationRequest>({
|
|
65
|
+
method: 'POST',
|
|
66
|
+
url: `/user/createWithList`,
|
|
67
|
+
data: requestData,
|
|
68
|
+
...requestConfig,
|
|
69
|
+
})
|
|
70
|
+
return res.data
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @summary Logs user into the system
|
|
75
|
+
* {@link /user/login}
|
|
76
|
+
*/
|
|
77
|
+
async loginUser(params?: LoginUserQueryParams, config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
78
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
79
|
+
const res = await request<LoginUserQueryResponse, ResponseErrorConfig<LoginUser400>, unknown>({
|
|
80
|
+
method: 'GET',
|
|
81
|
+
url: `/user/login`,
|
|
82
|
+
params,
|
|
83
|
+
...requestConfig,
|
|
84
|
+
})
|
|
85
|
+
return res.data
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @summary Logs out current logged in user session
|
|
90
|
+
* {@link /user/logout}
|
|
91
|
+
*/
|
|
92
|
+
async logoutUser(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
93
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
94
|
+
const res = await request<LogoutUserQueryResponse, ResponseErrorConfig<Error>, unknown>({ method: 'GET', url: `/user/logout`, ...requestConfig })
|
|
95
|
+
return res.data
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @summary Get user by user name
|
|
100
|
+
* {@link /user/:username}
|
|
101
|
+
*/
|
|
102
|
+
async getUserByName(username: GetUserByNamePathParams['username'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
103
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
104
|
+
const res = await request<GetUserByNameQueryResponse, ResponseErrorConfig<GetUserByName400 | GetUserByName404>, unknown>({
|
|
105
|
+
method: 'GET',
|
|
106
|
+
url: `/user/${username}`,
|
|
107
|
+
...requestConfig,
|
|
108
|
+
})
|
|
109
|
+
return res.data
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @description This can only be done by the logged in user.
|
|
114
|
+
* @summary Update user
|
|
115
|
+
* {@link /user/:username}
|
|
116
|
+
*/
|
|
117
|
+
async updateUser(
|
|
118
|
+
username: UpdateUserPathParams['username'],
|
|
119
|
+
data?: UpdateUserMutationRequest,
|
|
120
|
+
config: Partial<RequestConfig<UpdateUserMutationRequest>> & { client?: typeof fetch } = {},
|
|
121
|
+
) {
|
|
122
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
123
|
+
const requestData = data
|
|
124
|
+
const res = await request<UpdateUserMutationResponse, ResponseErrorConfig<Error>, UpdateUserMutationRequest>({
|
|
125
|
+
method: 'PUT',
|
|
126
|
+
url: `/user/${username}`,
|
|
127
|
+
data: requestData,
|
|
128
|
+
...requestConfig,
|
|
129
|
+
})
|
|
130
|
+
return res.data
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @description This can only be done by the logged in user.
|
|
135
|
+
* @summary Delete user
|
|
136
|
+
* {@link /user/:username}
|
|
137
|
+
*/
|
|
138
|
+
async deleteUser(username: DeleteUserPathParams['username'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
139
|
+
const { client: request = this.#client, ...requestConfig } = config
|
|
140
|
+
const res = await request<DeleteUserMutationResponse, ResponseErrorConfig<DeleteUser400 | DeleteUser404>, unknown>({
|
|
141
|
+
method: 'DELETE',
|
|
142
|
+
url: `/user/${username}`,
|
|
143
|
+
...requestConfig,
|
|
144
|
+
})
|
|
145
|
+
return res.data
|
|
146
|
+
}
|
|
147
|
+
}
|