@kubb/plugin-client 3.0.0-alpha.8 → 3.0.0-beta.1
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 -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 +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 +10 -128
- 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 -134
- 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 +22 -17
- package/src/components/Client.tsx +109 -208
- package/src/components/Operations.tsx +5 -71
- 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 -0
- package/src/generators/operationsGenerator.tsx +26 -0
- package/src/plugin.ts +34 -45
- package/src/types.ts +33 -75
- package/dist/chunk-E562RKCC.js +0 -199
- package/dist/chunk-E562RKCC.js.map +0 -1
- package/dist/chunk-PXA2JOEN.cjs +0 -199
- package/dist/chunk-PXA2JOEN.cjs.map +0 -1
- package/dist/types-C_-LImV-.d.cts +0 -233
- package/dist/types-C_-LImV-.d.ts +0 -233
- package/src/OperationGenerator.tsx +0 -29
- 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
|
@@ -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
|
+
})
|
|
@@ -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/plugin.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
|
|
3
|
-
import { FileManager, PluginManager, createPlugin } from '@kubb/core'
|
|
3
|
+
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase } from '@kubb/core/transformers'
|
|
5
|
-
import { renderTemplate } from '@kubb/core/utils'
|
|
6
5
|
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
7
6
|
|
|
8
|
-
import { clientParser } from './OperationGenerator.tsx'
|
|
9
|
-
import { Client, Operations } from './components/index.ts'
|
|
10
|
-
|
|
11
7
|
import type { Plugin } from '@kubb/core'
|
|
12
8
|
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
9
|
+
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
+
import { operationsGenerator } from './generators'
|
|
11
|
+
import { clientGenerator } from './generators/clientGenerator.tsx'
|
|
12
|
+
import { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'
|
|
13
13
|
import type { PluginClient } from './types.ts'
|
|
14
14
|
|
|
15
15
|
export const pluginClientName = 'plugin-client' satisfies PluginClient['name']
|
|
16
16
|
|
|
17
17
|
export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
18
18
|
const {
|
|
19
|
-
output = { path: 'clients' },
|
|
19
|
+
output = { path: 'clients', barrelType: 'named' },
|
|
20
20
|
group,
|
|
21
21
|
exclude = [],
|
|
22
22
|
include,
|
|
@@ -24,38 +24,34 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
24
24
|
transformers = {},
|
|
25
25
|
dataReturnType = 'data',
|
|
26
26
|
pathParamsType = 'inline',
|
|
27
|
-
|
|
27
|
+
operations = false,
|
|
28
|
+
generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),
|
|
29
|
+
importPath = '@kubb/plugin-client/client',
|
|
30
|
+
parser = 'client',
|
|
28
31
|
} = options
|
|
29
32
|
|
|
30
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
|
|
31
|
-
|
|
32
33
|
return {
|
|
33
34
|
name: pluginClientName,
|
|
34
|
-
output: {
|
|
35
|
-
exportType: 'barrelNamed',
|
|
36
|
-
...output,
|
|
37
|
-
},
|
|
38
35
|
options: {
|
|
39
|
-
|
|
36
|
+
output,
|
|
37
|
+
group,
|
|
38
|
+
parser,
|
|
40
39
|
dataReturnType,
|
|
41
|
-
|
|
42
|
-
importPath: '@kubb/plugin-client/client',
|
|
43
|
-
methods: ['get', 'post', 'delete', 'put'],
|
|
44
|
-
...options.client,
|
|
45
|
-
},
|
|
40
|
+
importPath,
|
|
46
41
|
pathParamsType,
|
|
47
|
-
templates: {
|
|
48
|
-
operations: Operations.templates,
|
|
49
|
-
client: Client.templates,
|
|
50
|
-
...templates,
|
|
51
|
-
},
|
|
52
42
|
baseURL: undefined,
|
|
53
43
|
},
|
|
54
|
-
pre: [pluginOasName],
|
|
44
|
+
pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
55
45
|
resolvePath(baseName, pathMode, options) {
|
|
56
46
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
57
47
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
58
48
|
|
|
49
|
+
if (options?.tag && group?.type === 'tag') {
|
|
50
|
+
const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
|
|
51
|
+
|
|
52
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
|
|
53
|
+
}
|
|
54
|
+
|
|
59
55
|
if (mode === 'single') {
|
|
60
56
|
/**
|
|
61
57
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
@@ -64,12 +60,6 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
64
60
|
return path.resolve(root, output.path)
|
|
65
61
|
}
|
|
66
62
|
|
|
67
|
-
if (options?.tag && group?.type === 'tag') {
|
|
68
|
-
const tag = camelCase(options.tag)
|
|
69
|
-
|
|
70
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
63
|
return path.resolve(root, output.path, baseName)
|
|
74
64
|
},
|
|
75
65
|
resolveName(name, type) {
|
|
@@ -106,23 +96,22 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
106
96
|
},
|
|
107
97
|
)
|
|
108
98
|
|
|
109
|
-
const files = await operationGenerator.build(
|
|
99
|
+
const files = await operationGenerator.build(...generators)
|
|
110
100
|
|
|
111
101
|
await this.addFile(...files)
|
|
112
102
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
103
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
104
|
+
type: output.barrelType ?? 'named',
|
|
105
|
+
root,
|
|
106
|
+
output,
|
|
107
|
+
files: this.fileManager.files,
|
|
108
|
+
meta: {
|
|
109
|
+
pluginKey: this.plugin.key,
|
|
110
|
+
},
|
|
111
|
+
logger: this.logger,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
await this.addFile(...barrelFiles)
|
|
126
115
|
},
|
|
127
116
|
}
|
|
128
117
|
})
|
package/src/types.ts
CHANGED
|
@@ -1,58 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type * as KubbFile from '@kubb/fs/types'
|
|
1
|
+
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
3
2
|
|
|
4
|
-
import type {
|
|
5
|
-
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
6
|
-
import type { Client, Operations } from './components/index.ts'
|
|
7
|
-
|
|
8
|
-
type Templates = {
|
|
9
|
-
operations?: typeof Operations.templates | false
|
|
10
|
-
client?: typeof Client.templates | false
|
|
11
|
-
}
|
|
3
|
+
import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
12
4
|
|
|
13
5
|
export type Options = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
path: string
|
|
20
|
-
/**
|
|
21
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
22
|
-
*/
|
|
23
|
-
exportAs?: string
|
|
24
|
-
/**
|
|
25
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
26
|
-
*/
|
|
27
|
-
extName?: KubbFile.Extname
|
|
28
|
-
/**
|
|
29
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
30
|
-
* @default `'barrelNamed'`
|
|
31
|
-
*/
|
|
32
|
-
exportType?: 'barrel' | 'barrelNamed' | false
|
|
33
|
-
}
|
|
6
|
+
/**
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'clients', barrelType: 'named' }
|
|
9
|
+
*/
|
|
10
|
+
output?: Output
|
|
34
11
|
/**
|
|
35
12
|
* Group the clients based on the provided name.
|
|
36
13
|
*/
|
|
37
|
-
group?:
|
|
38
|
-
/**
|
|
39
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
40
|
-
*/
|
|
41
|
-
type: 'tag'
|
|
42
|
-
/**
|
|
43
|
-
* Relative path to save the grouped clients.
|
|
44
|
-
*
|
|
45
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
46
|
-
* @example `${output}/{{tag}}Controller` => `clients/PetController`
|
|
47
|
-
* @default `${output}/{{tag}}Controller`
|
|
48
|
-
*/
|
|
49
|
-
output?: string
|
|
50
|
-
/**
|
|
51
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
52
|
-
* @default `"{{tag}}Service"`
|
|
53
|
-
*/
|
|
54
|
-
exportAs?: string
|
|
55
|
-
}
|
|
14
|
+
group?: Group
|
|
56
15
|
/**
|
|
57
16
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
58
17
|
*/
|
|
@@ -65,23 +24,20 @@ export type Options = {
|
|
|
65
24
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
66
25
|
*/
|
|
67
26
|
override?: Array<Override<ResolvedOptions>>
|
|
68
|
-
client?: {
|
|
69
|
-
/**
|
|
70
|
-
* Path to the client import path that will be used to do the API calls.
|
|
71
|
-
* It will be used as `import client from '${client.importPath}'`.
|
|
72
|
-
* It allows both relative and absolute path.
|
|
73
|
-
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
74
|
-
* @default '@kubb/plugin-client/client'
|
|
75
|
-
*/
|
|
76
|
-
importPath?: string
|
|
77
|
-
/**
|
|
78
|
-
* Define which HttpMethods can be used for queries
|
|
79
|
-
* @default ['get', 'post', 'put', 'delete']
|
|
80
|
-
*/
|
|
81
|
-
methods?: Array<HttpMethod>
|
|
82
|
-
}
|
|
83
27
|
/**
|
|
84
|
-
*
|
|
28
|
+
* Create `operations.ts` file with all operations grouped by methods.
|
|
29
|
+
* @default `false`
|
|
30
|
+
*/
|
|
31
|
+
operations?: boolean
|
|
32
|
+
/**
|
|
33
|
+
* Path to the client import path that will be used to do the API calls.
|
|
34
|
+
* It will be used as `import client from '${client.importPath}'`.
|
|
35
|
+
* It allows both relative and absolute path but be aware that we will not change the path.
|
|
36
|
+
* @default '@kubb/plugin-client/client'
|
|
37
|
+
*/
|
|
38
|
+
importPath?: string
|
|
39
|
+
/**
|
|
40
|
+
* ReturnType that will be used when calling the client.
|
|
85
41
|
*
|
|
86
42
|
* `Data` will return ResponseConfig[data].
|
|
87
43
|
*
|
|
@@ -100,6 +56,12 @@ export type Options = {
|
|
|
100
56
|
* @private
|
|
101
57
|
*/
|
|
102
58
|
pathParamsType?: 'object' | 'inline'
|
|
59
|
+
/**
|
|
60
|
+
* Which parser can be used before returning the data
|
|
61
|
+
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
62
|
+
* @default 'client'
|
|
63
|
+
*/
|
|
64
|
+
parser?: 'client' | 'zod'
|
|
103
65
|
transformers?: {
|
|
104
66
|
/**
|
|
105
67
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -107,23 +69,19 @@ export type Options = {
|
|
|
107
69
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
108
70
|
}
|
|
109
71
|
/**
|
|
110
|
-
*
|
|
72
|
+
* Define some generators next to the client generators
|
|
111
73
|
*/
|
|
112
|
-
|
|
74
|
+
generators?: Array<Generator<PluginClient>>
|
|
113
75
|
}
|
|
114
76
|
|
|
115
77
|
type ResolvedOptions = {
|
|
116
|
-
|
|
78
|
+
output: Output
|
|
79
|
+
group?: Options['group']
|
|
117
80
|
baseURL: string | undefined
|
|
118
|
-
|
|
81
|
+
parser: NonNullable<Options['parser']>
|
|
82
|
+
importPath: NonNullable<Options['importPath']>
|
|
119
83
|
dataReturnType: NonNullable<Options['dataReturnType']>
|
|
120
84
|
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
121
|
-
templates: NonNullable<Templates>
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export type FileMeta = {
|
|
125
|
-
pluginKey?: Plugin['key']
|
|
126
|
-
tag?: string
|
|
127
85
|
}
|
|
128
86
|
|
|
129
87
|
export type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>
|
package/dist/chunk-E562RKCC.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
// src/components/Client.tsx
|
|
2
|
-
import { URLPath } from "@kubb/core/utils";
|
|
3
|
-
import { File, Function, useApp } from "@kubb/react";
|
|
4
|
-
import { pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
-
import { useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
6
|
-
import { getComments, getPathParams } from "@kubb/plugin-oas/utils";
|
|
7
|
-
import { isOptional } from "@kubb/oas";
|
|
8
|
-
import { jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
9
|
-
function Template({ name, generics, returnType, params, JSDoc, client }) {
|
|
10
|
-
const isFormData = client.contentType === "multipart/form-data";
|
|
11
|
-
const headers = [
|
|
12
|
-
client.contentType !== "application/json" ? `'Content-Type': '${client.contentType}'` : void 0,
|
|
13
|
-
client.withHeaders ? "...headers" : void 0
|
|
14
|
-
].filter(Boolean).join(", ");
|
|
15
|
-
const clientParams = {
|
|
16
|
-
data: {
|
|
17
|
-
mode: "object",
|
|
18
|
-
children: {
|
|
19
|
-
method: {
|
|
20
|
-
type: "string",
|
|
21
|
-
value: JSON.stringify(client.method)
|
|
22
|
-
},
|
|
23
|
-
url: {
|
|
24
|
-
type: "string",
|
|
25
|
-
value: client.path.template
|
|
26
|
-
},
|
|
27
|
-
baseURL: client.baseURL ? {
|
|
28
|
-
type: "string",
|
|
29
|
-
value: JSON.stringify(client.baseURL)
|
|
30
|
-
} : void 0,
|
|
31
|
-
params: client.withQueryParams ? {
|
|
32
|
-
type: "any"
|
|
33
|
-
} : void 0,
|
|
34
|
-
data: client.withData ? {
|
|
35
|
-
type: "any",
|
|
36
|
-
value: isFormData ? "formData" : void 0
|
|
37
|
-
} : void 0,
|
|
38
|
-
headers: headers.length ? {
|
|
39
|
-
type: "any",
|
|
40
|
-
value: headers.length ? `{ ${headers}, ...options.headers }` : void 0
|
|
41
|
-
} : void 0,
|
|
42
|
-
options: {
|
|
43
|
-
type: "any",
|
|
44
|
-
mode: "inlineSpread"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const formData = isFormData ? `
|
|
50
|
-
const formData = new FormData()
|
|
51
|
-
if(data) {
|
|
52
|
-
Object.keys(data).forEach((key) => {
|
|
53
|
-
const value = data[key];
|
|
54
|
-
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
55
|
-
formData.append(key, value);
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
` : void 0;
|
|
60
|
-
return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxs(Function, { name, async: true, export: true, generics, returnType, params, JSDoc, children: [
|
|
61
|
-
formData || "",
|
|
62
|
-
/* @__PURE__ */ jsx(Function.Call, { name: "res", to: /* @__PURE__ */ jsx(Function, { name: "client", async: true, generics: client.generics, params: clientParams }) }),
|
|
63
|
-
/* @__PURE__ */ jsx(Function.Return, { children: client.dataReturnType === "data" ? "res.data" : "res" })
|
|
64
|
-
] }) });
|
|
65
|
-
}
|
|
66
|
-
function RootTemplate({ children }) {
|
|
67
|
-
const {
|
|
68
|
-
plugin: {
|
|
69
|
-
options: {
|
|
70
|
-
client: { importPath }
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
} = useApp();
|
|
74
|
-
const { getSchemas, getFile } = useOperationManager();
|
|
75
|
-
const operation = useOperation();
|
|
76
|
-
const file = getFile(operation);
|
|
77
|
-
const fileType = getFile(operation, { pluginKey: [pluginTsName] });
|
|
78
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: "type" });
|
|
79
|
-
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
80
|
-
/* @__PURE__ */ jsx(File.Import, { name: "client", path: importPath }),
|
|
81
|
-
/* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: importPath, isTypeOnly: true }),
|
|
82
|
-
/* @__PURE__ */ jsx(
|
|
83
|
-
File.Import,
|
|
84
|
-
{
|
|
85
|
-
name: [schemas.request?.name, schemas.response.name, schemas.pathParams?.name, schemas.queryParams?.name, schemas.headerParams?.name].filter(Boolean),
|
|
86
|
-
root: file.path,
|
|
87
|
-
path: fileType.path,
|
|
88
|
-
isTypeOnly: true
|
|
89
|
-
}
|
|
90
|
-
),
|
|
91
|
-
children
|
|
92
|
-
] });
|
|
93
|
-
}
|
|
94
|
-
var defaultTemplates = { default: Template, root: RootTemplate };
|
|
95
|
-
function Client({ baseURL, Template: Template3 = defaultTemplates.default }) {
|
|
96
|
-
const {
|
|
97
|
-
plugin: {
|
|
98
|
-
options: { client, dataReturnType, pathParamsType }
|
|
99
|
-
}
|
|
100
|
-
} = useApp();
|
|
101
|
-
const { getSchemas, getName } = useOperationManager();
|
|
102
|
-
const operation = useOperation();
|
|
103
|
-
const contentType = operation.getContentType();
|
|
104
|
-
const name = getName(operation, { type: "function" });
|
|
105
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: "type" });
|
|
106
|
-
return /* @__PURE__ */ jsx(
|
|
107
|
-
Template3,
|
|
108
|
-
{
|
|
109
|
-
name,
|
|
110
|
-
params: {
|
|
111
|
-
pathParams: {
|
|
112
|
-
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
113
|
-
children: getPathParams(schemas.pathParams, { typed: true })
|
|
114
|
-
},
|
|
115
|
-
data: schemas.request?.name ? {
|
|
116
|
-
type: schemas.request?.name,
|
|
117
|
-
optional: isOptional(schemas.request?.schema)
|
|
118
|
-
} : void 0,
|
|
119
|
-
params: schemas.queryParams?.name ? {
|
|
120
|
-
type: schemas.queryParams?.name,
|
|
121
|
-
optional: isOptional(schemas.queryParams?.schema)
|
|
122
|
-
} : void 0,
|
|
123
|
-
headers: schemas.headerParams?.name ? {
|
|
124
|
-
type: schemas.headerParams?.name,
|
|
125
|
-
optional: isOptional(schemas.headerParams?.schema)
|
|
126
|
-
} : void 0,
|
|
127
|
-
options: {
|
|
128
|
-
type: "Partial<Parameters<typeof client>[0]>",
|
|
129
|
-
default: "{}"
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
returnType: dataReturnType === "data" ? `ResponseConfig<${schemas.response.name}>["data"]` : `ResponseConfig<${schemas.response.name}>`,
|
|
133
|
-
JSDoc: {
|
|
134
|
-
comments: getComments(operation)
|
|
135
|
-
},
|
|
136
|
-
client: {
|
|
137
|
-
// only set baseURL from serverIndex(swagger) when no custom client(default) is used
|
|
138
|
-
baseURL: client.importPath === "@kubb/plugin-client/client" ? baseURL : void 0,
|
|
139
|
-
generics: [schemas.response.name, schemas.request?.name].filter(Boolean),
|
|
140
|
-
dataReturnType,
|
|
141
|
-
withQueryParams: !!schemas.queryParams?.name,
|
|
142
|
-
withData: !!schemas.request?.name,
|
|
143
|
-
withHeaders: !!schemas.headerParams?.name,
|
|
144
|
-
method: operation.method,
|
|
145
|
-
path: new URLPath(operation.path),
|
|
146
|
-
contentType
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
Client.File = function({ baseURL, ...props }) {
|
|
152
|
-
const templates = { ...defaultTemplates, ...props.templates };
|
|
153
|
-
const Template3 = templates.default;
|
|
154
|
-
const RootTemplate3 = templates.root;
|
|
155
|
-
return /* @__PURE__ */ jsx(RootTemplate3, { children: /* @__PURE__ */ jsx(Client, { baseURL, Template: Template3 }) });
|
|
156
|
-
};
|
|
157
|
-
Client.templates = defaultTemplates;
|
|
158
|
-
|
|
159
|
-
// src/components/Operations.tsx
|
|
160
|
-
import { URLPath as URLPath2 } from "@kubb/core/utils";
|
|
161
|
-
import { useOperations } from "@kubb/plugin-oas/hooks";
|
|
162
|
-
import { Const, File as File2, useApp as useApp2 } from "@kubb/react";
|
|
163
|
-
import { jsx as jsx2 } from "@kubb/react/jsx-runtime";
|
|
164
|
-
function Template2({ name, operations }) {
|
|
165
|
-
const operationsObject = {};
|
|
166
|
-
operations.forEach((operation) => {
|
|
167
|
-
operationsObject[operation.getOperationId()] = {
|
|
168
|
-
path: new URLPath2(operation.path).URL,
|
|
169
|
-
method: operation.method
|
|
170
|
-
};
|
|
171
|
-
});
|
|
172
|
-
return /* @__PURE__ */ jsx2(File2.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx2(Const, { name, export: true, asConst: true, children: JSON.stringify(operationsObject, void 0, 2) }) });
|
|
173
|
-
}
|
|
174
|
-
function RootTemplate2({ children }) {
|
|
175
|
-
const {
|
|
176
|
-
pluginManager,
|
|
177
|
-
plugin: { key: pluginKey }
|
|
178
|
-
} = useApp2();
|
|
179
|
-
const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
|
|
180
|
-
return /* @__PURE__ */ jsx2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children });
|
|
181
|
-
}
|
|
182
|
-
var defaultTemplates2 = { default: Template2, root: RootTemplate2 };
|
|
183
|
-
function Operations({ baseURL, Template: Template3 = defaultTemplates2.default }) {
|
|
184
|
-
const operations = useOperations();
|
|
185
|
-
return /* @__PURE__ */ jsx2(Template3, { baseURL, name: "operations", operations });
|
|
186
|
-
}
|
|
187
|
-
Operations.File = function({ baseURL, ...props }) {
|
|
188
|
-
const templates = { ...defaultTemplates2, ...props.templates };
|
|
189
|
-
const Template3 = templates.default;
|
|
190
|
-
const RootTemplate3 = templates.root;
|
|
191
|
-
return /* @__PURE__ */ jsx2(RootTemplate3, { children: /* @__PURE__ */ jsx2(Operations, { baseURL, Template: Template3 }) });
|
|
192
|
-
};
|
|
193
|
-
Operations.templates = defaultTemplates2;
|
|
194
|
-
|
|
195
|
-
export {
|
|
196
|
-
Client,
|
|
197
|
-
Operations
|
|
198
|
-
};
|
|
199
|
-
//# sourceMappingURL=chunk-E562RKCC.js.map
|