@kubb/plugin-client 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/client.ts +2 -2
- package/dist/chunk-6W3SC7JK.cjs +228 -0
- package/dist/chunk-6W3SC7JK.cjs.map +1 -0
- package/dist/chunk-LI44LDXH.js +218 -0
- package/dist/chunk-LI44LDXH.js.map +1 -0
- package/dist/chunk-X73EA6RA.cjs +133 -0
- package/dist/chunk-X73EA6RA.cjs.map +1 -0
- package/dist/chunk-YYBNZBCI.js +130 -0
- package/dist/chunk-YYBNZBCI.js.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 -5
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +37 -5
- package/dist/components.d.ts +37 -5
- package/dist/components.js +2 -9
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -4
- package/dist/generators.cjs.map +1 -1
- package/dist/generators.d.cts +7 -6
- package/dist/generators.d.ts +7 -6
- package/dist/generators.js +3 -7
- package/dist/generators.js.map +1 -1
- package/dist/index.cjs +11 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +3 -114
- package/dist/index.js.map +1 -1
- package/dist/types-Bk_NZurp.d.cts +86 -0
- package/dist/types-Bk_NZurp.d.ts +86 -0
- package/package.json +14 -17
- package/src/components/Client.tsx +78 -58
- 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 +66 -0
- package/src/generators/groupedClientGenerator.tsx +70 -0
- package/src/generators/index.ts +3 -1
- package/src/generators/operationsGenerator.tsx +26 -0
- package/src/plugin.ts +34 -45
- package/src/types.ts +33 -75
- package/dist/chunk-AZDWYBLW.cjs +0 -1
- package/dist/chunk-AZDWYBLW.cjs.map +0 -1
- package/dist/chunk-GHHJWXKQ.cjs +0 -61
- package/dist/chunk-GHHJWXKQ.cjs.map +0 -1
- package/dist/chunk-OODSLPAP.js +0 -61
- package/dist/chunk-OODSLPAP.js.map +0 -1
- package/dist/chunk-W256NILH.js +0 -128
- package/dist/chunk-W256NILH.js.map +0 -1
- package/dist/chunk-YGRM4AA5.cjs +0 -128
- package/dist/chunk-YGRM4AA5.cjs.map +0 -1
- package/dist/chunk-YJOVLRSC.js +0 -1
- package/dist/chunk-YJOVLRSC.js.map +0 -1
- package/dist/types-DETYKDFZ.d.cts +0 -139
- package/dist/types-DETYKDFZ.d.ts +0 -139
- package/src/components/__snapshots__/Client/showPetById.ts +0 -8
- package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
- package/src/components/__snapshots__/Query/showPetById.ts +0 -15
- package/src/generators/axiosGenerator.tsx +0 -63
|
@@ -3,8 +3,8 @@ import { URLPath } from '@kubb/core/utils'
|
|
|
3
3
|
import { type Operation, isOptional } from '@kubb/oas'
|
|
4
4
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
5
5
|
import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
|
|
6
|
-
import { File, Function,
|
|
7
|
-
import type { KubbNode
|
|
6
|
+
import { File, Function, FunctionParams } from '@kubb/react'
|
|
7
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
8
8
|
import type { PluginClient } from '../types.ts'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
@@ -12,87 +12,107 @@ type Props = {
|
|
|
12
12
|
* Name of the function
|
|
13
13
|
*/
|
|
14
14
|
name: string
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
17
24
|
operation: Operation
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const isFormData = contentType === 'multipart/form-data'
|
|
25
|
-
const headers = [
|
|
26
|
-
contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,
|
|
27
|
-
typedSchemas.headerParams?.name ? '...headers' : undefined,
|
|
28
|
-
].filter(Boolean)
|
|
27
|
+
type GetParamsProps = {
|
|
28
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
29
|
+
typeSchemas: OperationSchemas
|
|
30
|
+
}
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
33
|
+
return FunctionParams.factory({
|
|
31
34
|
pathParams: {
|
|
32
|
-
mode:
|
|
33
|
-
children: getPathParams(
|
|
35
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
36
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
34
37
|
},
|
|
35
|
-
data:
|
|
38
|
+
data: typeSchemas.request?.name
|
|
36
39
|
? {
|
|
37
|
-
type:
|
|
38
|
-
optional: isOptional(
|
|
40
|
+
type: typeSchemas.request?.name,
|
|
41
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
39
42
|
}
|
|
40
43
|
: undefined,
|
|
41
|
-
params:
|
|
44
|
+
params: typeSchemas.queryParams?.name
|
|
42
45
|
? {
|
|
43
|
-
type:
|
|
44
|
-
optional: isOptional(
|
|
46
|
+
type: typeSchemas.queryParams?.name,
|
|
47
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
45
48
|
}
|
|
46
49
|
: undefined,
|
|
47
|
-
headers:
|
|
50
|
+
headers: typeSchemas.headerParams?.name
|
|
48
51
|
? {
|
|
49
|
-
type:
|
|
50
|
-
optional: isOptional(
|
|
52
|
+
type: typeSchemas.headerParams?.name,
|
|
53
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
51
54
|
}
|
|
52
55
|
: undefined,
|
|
53
|
-
|
|
54
|
-
type: 'Partial<
|
|
56
|
+
config: {
|
|
57
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
55
58
|
default: '{}',
|
|
56
59
|
},
|
|
57
60
|
})
|
|
61
|
+
}
|
|
62
|
+
|
|
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'
|
|
78
|
+
const headers = [
|
|
79
|
+
contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,
|
|
80
|
+
typeSchemas.headerParams?.name ? '...headers' : undefined,
|
|
81
|
+
].filter(Boolean)
|
|
58
82
|
|
|
59
|
-
const
|
|
60
|
-
|
|
83
|
+
const generics = [
|
|
84
|
+
typeSchemas.response.name,
|
|
85
|
+
typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error',
|
|
86
|
+
typeSchemas.request?.name || 'unknown',
|
|
87
|
+
].filter(Boolean)
|
|
88
|
+
const params = getParams({ pathParamsType, typeSchemas })
|
|
89
|
+
const clientParams = FunctionParams.factory({
|
|
90
|
+
config: {
|
|
61
91
|
mode: 'object',
|
|
62
92
|
children: {
|
|
63
93
|
method: {
|
|
64
|
-
|
|
65
|
-
value: JSON.stringify(operation.method),
|
|
94
|
+
value: JSON.stringify(operation.method.toUpperCase()),
|
|
66
95
|
},
|
|
67
96
|
url: {
|
|
68
|
-
type: 'string',
|
|
69
97
|
value: path.template,
|
|
70
98
|
},
|
|
71
99
|
baseURL: baseURL
|
|
72
100
|
? {
|
|
73
|
-
type: 'string',
|
|
74
101
|
value: JSON.stringify(baseURL),
|
|
75
102
|
}
|
|
76
103
|
: undefined,
|
|
77
|
-
params:
|
|
104
|
+
params: typeSchemas.queryParams?.name ? {} : undefined,
|
|
105
|
+
data: typeSchemas.request?.name
|
|
78
106
|
? {
|
|
79
|
-
type: 'any',
|
|
80
|
-
}
|
|
81
|
-
: undefined,
|
|
82
|
-
data: typedSchemas.request?.name
|
|
83
|
-
? {
|
|
84
|
-
type: 'any',
|
|
85
107
|
value: isFormData ? 'formData' : undefined,
|
|
86
108
|
}
|
|
87
109
|
: undefined,
|
|
88
110
|
headers: headers.length
|
|
89
111
|
? {
|
|
90
|
-
|
|
91
|
-
value: headers.length ? `{ ${headers.join(', ')}, ...options.headers }` : undefined,
|
|
112
|
+
value: headers.length ? `{ ${headers.join(', ')}, ...config.headers }` : undefined,
|
|
92
113
|
}
|
|
93
114
|
: undefined,
|
|
94
|
-
|
|
95
|
-
type: 'any',
|
|
115
|
+
config: {
|
|
96
116
|
mode: 'inlineSpread',
|
|
97
117
|
},
|
|
98
118
|
},
|
|
@@ -104,36 +124,36 @@ export function Client({ name, options, typedSchemas, operation }: Props): KubbN
|
|
|
104
124
|
const formData = new FormData()
|
|
105
125
|
if(data) {
|
|
106
126
|
Object.keys(data).forEach((key) => {
|
|
107
|
-
const value = data[key];
|
|
127
|
+
const value = data[key as keyof typeof data];
|
|
108
128
|
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
109
129
|
formData.append(key, value);
|
|
110
130
|
}
|
|
111
131
|
})
|
|
112
132
|
}
|
|
113
133
|
`
|
|
114
|
-
:
|
|
134
|
+
: ''
|
|
115
135
|
|
|
116
136
|
return (
|
|
117
|
-
<File.Source name={name} isExportable isIndexable>
|
|
137
|
+
<File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>
|
|
118
138
|
<Function
|
|
119
139
|
name={name}
|
|
120
140
|
async
|
|
121
|
-
export
|
|
122
|
-
|
|
123
|
-
options.dataReturnType === 'data' ? `ResponseConfig<${typedSchemas.response.name}>["data"]` : `ResponseConfig<${typedSchemas.response.name}>`
|
|
124
|
-
}
|
|
125
|
-
params={params}
|
|
141
|
+
export={isExportable}
|
|
142
|
+
params={params.toConstructor()}
|
|
126
143
|
JSDoc={{
|
|
127
144
|
comments: getComments(operation),
|
|
128
145
|
}}
|
|
129
146
|
>
|
|
130
|
-
{formData
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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'}
|
|
136
154
|
</Function>
|
|
137
155
|
</File.Source>
|
|
138
156
|
)
|
|
139
157
|
}
|
|
158
|
+
|
|
159
|
+
Client.getParams = getParams
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
typeSchemas={type.schemas}
|
|
59
|
+
operation={operation}
|
|
60
|
+
parser={options.parser}
|
|
61
|
+
zodSchemas={zod.schemas}
|
|
62
|
+
/>
|
|
63
|
+
</File>
|
|
64
|
+
)
|
|
65
|
+
},
|
|
66
|
+
})
|
|
@@ -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
|
+
})
|
package/src/generators/index.ts
CHANGED
|
@@ -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
|
+
})
|