@kubb/plugin-client 0.0.0-canary-20241104172400
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/LICENSE +21 -0
- package/README.md +53 -0
- package/client.ts +65 -0
- package/dist/chunk-I2NEG5CE.js +222 -0
- package/dist/chunk-I2NEG5CE.js.map +1 -0
- package/dist/chunk-IIY26RTZ.cjs +232 -0
- package/dist/chunk-IIY26RTZ.cjs.map +1 -0
- package/dist/chunk-PHUXTZZT.js +159 -0
- package/dist/chunk-PHUXTZZT.js.map +1 -0
- package/dist/chunk-UBMTYBLG.cjs +162 -0
- package/dist/chunk-UBMTYBLG.cjs.map +1 -0
- package/dist/client.cjs +45 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +35 -0
- package/dist/client.d.ts +35 -0
- package/dist/client.js +33 -0
- package/dist/client.js.map +1 -0
- package/dist/components.cjs +16 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +40 -0
- package/dist/components.d.ts +40 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/generators.cjs +21 -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 +17 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types-DXab6SYO.d.cts +92 -0
- package/dist/types-DXab6SYO.d.ts +92 -0
- package/package.json +117 -0
- package/src/components/Client.tsx +199 -0
- package/src/components/Operations.tsx +28 -0
- package/src/components/index.ts +2 -0
- package/src/generators/__snapshots__/deletePet.ts +13 -0
- package/src/generators/__snapshots__/deletePetObject.ts +13 -0
- package/src/generators/__snapshots__/findByTags.ts +13 -0
- package/src/generators/__snapshots__/findByTagsFull.ts +13 -0
- package/src/generators/__snapshots__/findByTagsObject.ts +15 -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/groupedClientGenerator.tsx +70 -0
- package/src/generators/index.ts +3 -0
- package/src/generators/operationsGenerator.tsx +26 -0
- package/src/index.ts +2 -0
- package/src/plugin.ts +122 -0
- package/src/types.ts +93 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { URLPath } from '@kubb/core/utils'
|
|
2
|
+
|
|
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'
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
/**
|
|
12
|
+
* Name of the function
|
|
13
|
+
*/
|
|
14
|
+
name: string
|
|
15
|
+
isExportable?: boolean
|
|
16
|
+
isIndexable?: boolean
|
|
17
|
+
|
|
18
|
+
baseURL: string | undefined
|
|
19
|
+
dataReturnType: PluginClient['resolvedOptions']['dataReturnType']
|
|
20
|
+
paramsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
21
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
22
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
23
|
+
typeSchemas: OperationSchemas
|
|
24
|
+
zodSchemas: OperationSchemas | undefined
|
|
25
|
+
operation: Operation
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type GetParamsProps = {
|
|
29
|
+
paramsType: PluginClient['resolvedOptions']['paramsType']
|
|
30
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
31
|
+
typeSchemas: OperationSchemas
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
35
|
+
if (paramsType === 'object') {
|
|
36
|
+
return FunctionParams.factory({
|
|
37
|
+
data: {
|
|
38
|
+
mode: 'object',
|
|
39
|
+
children: {
|
|
40
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
41
|
+
data: typeSchemas.request?.name
|
|
42
|
+
? {
|
|
43
|
+
type: typeSchemas.request?.name,
|
|
44
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
45
|
+
}
|
|
46
|
+
: undefined,
|
|
47
|
+
params: typeSchemas.queryParams?.name
|
|
48
|
+
? {
|
|
49
|
+
type: typeSchemas.queryParams?.name,
|
|
50
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
51
|
+
}
|
|
52
|
+
: undefined,
|
|
53
|
+
headers: typeSchemas.headerParams?.name
|
|
54
|
+
? {
|
|
55
|
+
type: typeSchemas.headerParams?.name,
|
|
56
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
57
|
+
}
|
|
58
|
+
: undefined,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
config: {
|
|
62
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
63
|
+
default: '{}',
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return FunctionParams.factory({
|
|
69
|
+
pathParams: typeSchemas.pathParams?.name
|
|
70
|
+
? {
|
|
71
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
72
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
73
|
+
type: typeSchemas.pathParams?.name,
|
|
74
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
75
|
+
}
|
|
76
|
+
: undefined,
|
|
77
|
+
data: typeSchemas.request?.name
|
|
78
|
+
? {
|
|
79
|
+
type: typeSchemas.request?.name,
|
|
80
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
81
|
+
}
|
|
82
|
+
: undefined,
|
|
83
|
+
params: typeSchemas.queryParams?.name
|
|
84
|
+
? {
|
|
85
|
+
type: typeSchemas.queryParams?.name,
|
|
86
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
87
|
+
}
|
|
88
|
+
: undefined,
|
|
89
|
+
headers: typeSchemas.headerParams?.name
|
|
90
|
+
? {
|
|
91
|
+
type: typeSchemas.headerParams?.name,
|
|
92
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
93
|
+
}
|
|
94
|
+
: undefined,
|
|
95
|
+
config: {
|
|
96
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
97
|
+
default: '{}',
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function Client({
|
|
103
|
+
name,
|
|
104
|
+
isExportable = true,
|
|
105
|
+
isIndexable = true,
|
|
106
|
+
typeSchemas,
|
|
107
|
+
baseURL,
|
|
108
|
+
dataReturnType,
|
|
109
|
+
parser,
|
|
110
|
+
zodSchemas,
|
|
111
|
+
paramsType,
|
|
112
|
+
pathParamsType,
|
|
113
|
+
operation,
|
|
114
|
+
}: Props): KubbNode {
|
|
115
|
+
const path = new URLPath(operation.path)
|
|
116
|
+
const contentType = operation.getContentType()
|
|
117
|
+
const isFormData = contentType === 'multipart/form-data'
|
|
118
|
+
const headers = [
|
|
119
|
+
contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,
|
|
120
|
+
typeSchemas.headerParams?.name ? '...headers' : undefined,
|
|
121
|
+
].filter(Boolean)
|
|
122
|
+
|
|
123
|
+
const generics = [
|
|
124
|
+
typeSchemas.response.name,
|
|
125
|
+
typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error',
|
|
126
|
+
typeSchemas.request?.name || 'unknown',
|
|
127
|
+
].filter(Boolean)
|
|
128
|
+
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
129
|
+
const clientParams = FunctionParams.factory({
|
|
130
|
+
config: {
|
|
131
|
+
mode: 'object',
|
|
132
|
+
children: {
|
|
133
|
+
method: {
|
|
134
|
+
value: JSON.stringify(operation.method.toUpperCase()),
|
|
135
|
+
},
|
|
136
|
+
url: {
|
|
137
|
+
value: path.template,
|
|
138
|
+
},
|
|
139
|
+
baseURL: baseURL
|
|
140
|
+
? {
|
|
141
|
+
value: JSON.stringify(baseURL),
|
|
142
|
+
}
|
|
143
|
+
: undefined,
|
|
144
|
+
params: typeSchemas.queryParams?.name ? {} : undefined,
|
|
145
|
+
data: typeSchemas.request?.name
|
|
146
|
+
? {
|
|
147
|
+
value: isFormData ? 'formData' : undefined,
|
|
148
|
+
}
|
|
149
|
+
: undefined,
|
|
150
|
+
headers: headers.length
|
|
151
|
+
? {
|
|
152
|
+
value: headers.length ? `{ ${headers.join(', ')}, ...config.headers }` : undefined,
|
|
153
|
+
}
|
|
154
|
+
: undefined,
|
|
155
|
+
config: {
|
|
156
|
+
mode: 'inlineSpread',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
const formData = isFormData
|
|
163
|
+
? `
|
|
164
|
+
const formData = new FormData()
|
|
165
|
+
if(data) {
|
|
166
|
+
Object.keys(data).forEach((key) => {
|
|
167
|
+
const value = data[key as keyof typeof data];
|
|
168
|
+
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
169
|
+
formData.append(key, value);
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
`
|
|
174
|
+
: ''
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>
|
|
178
|
+
<Function
|
|
179
|
+
name={name}
|
|
180
|
+
async
|
|
181
|
+
export={isExportable}
|
|
182
|
+
params={params.toConstructor()}
|
|
183
|
+
JSDoc={{
|
|
184
|
+
comments: getComments(operation),
|
|
185
|
+
}}
|
|
186
|
+
>
|
|
187
|
+
{formData}
|
|
188
|
+
{`const res = await client<${generics.join(', ')}>(${clientParams.toCall()})`}
|
|
189
|
+
<br />
|
|
190
|
+
{dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}
|
|
191
|
+
{dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}
|
|
192
|
+
{dataReturnType === 'full' && parser === 'client' && 'return res'}
|
|
193
|
+
{dataReturnType === 'data' && parser === 'client' && 'return res.data'}
|
|
194
|
+
</Function>
|
|
195
|
+
</File.Source>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
Client.getParams = getParams
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { URLPath } from '@kubb/core/utils'
|
|
2
|
+
import { Const, File } from '@kubb/react'
|
|
3
|
+
|
|
4
|
+
import type { HttpMethod, Operation } from '@kubb/oas'
|
|
5
|
+
|
|
6
|
+
type OperationsProps = {
|
|
7
|
+
name: string
|
|
8
|
+
operations: Array<Operation>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function Operations({ name, operations }: OperationsProps) {
|
|
12
|
+
const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}
|
|
13
|
+
|
|
14
|
+
operations.forEach((operation) => {
|
|
15
|
+
operationsObject[operation.getOperationId()] = {
|
|
16
|
+
path: new URLPath(operation.path).URL,
|
|
17
|
+
method: operation.method,
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<File.Source name={name} isExportable isIndexable>
|
|
23
|
+
<Const name={name} export asConst>
|
|
24
|
+
{JSON.stringify(operationsObject, undefined, 2)}
|
|
25
|
+
</Const>
|
|
26
|
+
</File.Source>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -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,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, 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,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,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 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 }: {
|
|
11
|
+
params?: FindPetsByTagsQueryParams;
|
|
12
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
13
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, ...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 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
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
2
|
+
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
3
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
4
|
+
import { pluginZodName } from '@kubb/plugin-zod'
|
|
5
|
+
import { File, useApp } from '@kubb/react'
|
|
6
|
+
import { Client } from '../components/Client'
|
|
7
|
+
import type { PluginClient } from '../types'
|
|
8
|
+
|
|
9
|
+
export const clientGenerator = createReactGenerator<PluginClient>({
|
|
10
|
+
name: 'client',
|
|
11
|
+
Operation({ options, operation }) {
|
|
12
|
+
const {
|
|
13
|
+
plugin: {
|
|
14
|
+
options: { output },
|
|
15
|
+
},
|
|
16
|
+
} = useApp<PluginClient>()
|
|
17
|
+
const { getSchemas, getName, getFile } = useOperationManager()
|
|
18
|
+
|
|
19
|
+
const client = {
|
|
20
|
+
name: getName(operation, { type: 'function' }),
|
|
21
|
+
file: getFile(operation),
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const type = {
|
|
25
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
26
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const zod = {
|
|
30
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
31
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<File baseName={client.file.baseName} path={client.file.path} meta={client.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
36
|
+
<File.Import name={'client'} path={options.importPath} />
|
|
37
|
+
<File.Import name={['RequestConfig']} path={options.importPath} isTypeOnly />
|
|
38
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={client.file.path} path={zod.file.path} />}
|
|
39
|
+
<File.Import
|
|
40
|
+
name={[
|
|
41
|
+
type.schemas.request?.name,
|
|
42
|
+
type.schemas.response.name,
|
|
43
|
+
type.schemas.pathParams?.name,
|
|
44
|
+
type.schemas.queryParams?.name,
|
|
45
|
+
type.schemas.headerParams?.name,
|
|
46
|
+
...(type.schemas.statusCodes?.map((item) => item.name) || []),
|
|
47
|
+
].filter(Boolean)}
|
|
48
|
+
root={client.file.path}
|
|
49
|
+
path={type.file.path}
|
|
50
|
+
isTypeOnly
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<Client
|
|
54
|
+
name={client.name}
|
|
55
|
+
baseURL={options.baseURL}
|
|
56
|
+
dataReturnType={options.dataReturnType}
|
|
57
|
+
pathParamsType={options.pathParamsType}
|
|
58
|
+
paramsType={options.paramsType}
|
|
59
|
+
typeSchemas={type.schemas}
|
|
60
|
+
operation={operation}
|
|
61
|
+
parser={options.parser}
|
|
62
|
+
zodSchemas={zod.schemas}
|
|
63
|
+
/>
|
|
64
|
+
</File>
|
|
65
|
+
)
|
|
66
|
+
},
|
|
67
|
+
})
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { camelCase } from '@kubb/core/transformers'
|
|
2
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
3
|
+
import { pluginClientName } from '@kubb/plugin-client'
|
|
4
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
5
|
+
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
6
|
+
import { File, Function, useApp } from '@kubb/react'
|
|
7
|
+
import type { PluginClient } from '../types'
|
|
8
|
+
|
|
9
|
+
export const groupedClientGenerator = createReactGenerator<PluginClient>({
|
|
10
|
+
name: 'groupedClient',
|
|
11
|
+
Operations({ operations }) {
|
|
12
|
+
const {
|
|
13
|
+
pluginManager,
|
|
14
|
+
plugin: { options },
|
|
15
|
+
} = useApp<PluginClient>()
|
|
16
|
+
const { getName, getFile } = useOperationManager()
|
|
17
|
+
|
|
18
|
+
const controllers = operations.reduce(
|
|
19
|
+
(acc, operation) => {
|
|
20
|
+
if (options.group?.type === 'tag') {
|
|
21
|
+
const tag = operation.getTags().at(0)?.name
|
|
22
|
+
const name = tag ? options.group?.name?.({ group: camelCase(tag) }) : undefined
|
|
23
|
+
|
|
24
|
+
if (!tag || !name) {
|
|
25
|
+
return acc
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const file = pluginManager.getFile({
|
|
29
|
+
name,
|
|
30
|
+
extname: '.ts',
|
|
31
|
+
pluginKey: [pluginClientName],
|
|
32
|
+
options: { tag },
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const client = {
|
|
36
|
+
name: getName(operation, { type: 'function' }),
|
|
37
|
+
file: getFile(operation),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const previousFile = acc.find((item) => item.file.path === file.path)
|
|
41
|
+
|
|
42
|
+
if (previousFile) {
|
|
43
|
+
previousFile.clients.push(client)
|
|
44
|
+
} else {
|
|
45
|
+
acc.push({ name, file, clients: [client] })
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return acc
|
|
50
|
+
},
|
|
51
|
+
[] as Array<{ name: string; file: KubbFile.File; clients: Array<{ name: string; file: KubbFile.File }> }>,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
return controllers.map(({ name, file, clients }) => {
|
|
55
|
+
return (
|
|
56
|
+
<File key={file.path} baseName={file.baseName} path={file.path} meta={file.meta} banner={options.output?.banner} footer={options.output?.footer}>
|
|
57
|
+
{clients.map((client) => (
|
|
58
|
+
<File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />
|
|
59
|
+
))}
|
|
60
|
+
|
|
61
|
+
<File.Source name={name} isExportable isIndexable>
|
|
62
|
+
<Function export name={name}>
|
|
63
|
+
{`return { ${clients.map((client) => client.name).join(', ')} }`}
|
|
64
|
+
</Function>
|
|
65
|
+
</File.Source>
|
|
66
|
+
</File>
|
|
67
|
+
)
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { pluginClientName } from '@kubb/plugin-client'
|
|
2
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
3
|
+
import { File, useApp } from '@kubb/react'
|
|
4
|
+
import { Operations } from '../components/Operations'
|
|
5
|
+
import type { PluginClient } from '../types'
|
|
6
|
+
|
|
7
|
+
export const operationsGenerator = createReactGenerator<PluginClient>({
|
|
8
|
+
name: 'client',
|
|
9
|
+
Operations({ operations }) {
|
|
10
|
+
const {
|
|
11
|
+
pluginManager,
|
|
12
|
+
plugin: {
|
|
13
|
+
options: { output },
|
|
14
|
+
},
|
|
15
|
+
} = useApp<PluginClient>()
|
|
16
|
+
|
|
17
|
+
const name = 'operations'
|
|
18
|
+
const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: [pluginClientName] })
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>
|
|
22
|
+
<Operations name={name} operations={operations} />
|
|
23
|
+
</File>
|
|
24
|
+
)
|
|
25
|
+
},
|
|
26
|
+
})
|
package/src/index.ts
ADDED