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