@kubb/plugin-client 5.0.0-alpha.9 → 5.0.0-beta.15
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 +17 -10
- package/README.md +27 -7
- package/dist/clients/axios.cjs +10 -3
- package/dist/clients/axios.cjs.map +1 -1
- package/dist/clients/axios.d.ts +5 -4
- package/dist/clients/axios.js +9 -2
- package/dist/clients/axios.js.map +1 -1
- package/dist/clients/fetch.cjs +5 -2
- package/dist/clients/fetch.cjs.map +1 -1
- package/dist/clients/fetch.d.ts +3 -2
- package/dist/clients/fetch.js +5 -2
- package/dist/clients/fetch.js.map +1 -1
- package/dist/index.cjs +1830 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +330 -4
- package/dist/index.js +1816 -95
- package/dist/index.js.map +1 -1
- package/dist/templates/clients/axios.source.cjs +1 -1
- package/dist/templates/clients/axios.source.js +1 -1
- package/dist/templates/clients/fetch.source.cjs +1 -1
- package/dist/templates/clients/fetch.source.js +1 -1
- package/extension.yaml +779 -0
- package/package.json +62 -85
- package/src/clients/axios.ts +19 -4
- package/src/clients/fetch.ts +10 -2
- package/src/components/ClassClient.tsx +46 -145
- package/src/components/Client.tsx +109 -139
- package/src/components/Operations.tsx +10 -10
- package/src/components/StaticClassClient.tsx +46 -142
- package/src/components/Url.tsx +38 -50
- package/src/components/WrapperClient.tsx +11 -7
- package/src/functionParams.ts +118 -0
- package/src/generators/classClientGenerator.tsx +143 -172
- package/src/generators/clientGenerator.tsx +83 -81
- package/src/generators/groupedClientGenerator.tsx +50 -52
- package/src/generators/operationsGenerator.tsx +11 -18
- package/src/generators/staticClassClientGenerator.tsx +172 -184
- package/src/index.ts +9 -2
- package/src/plugin.ts +115 -145
- package/src/resolvers/resolverClient.ts +38 -0
- package/src/types.ts +128 -44
- package/src/utils.ts +156 -0
- package/dist/StaticClassClient-By-aMAe4.cjs +0 -677
- package/dist/StaticClassClient-By-aMAe4.cjs.map +0 -1
- package/dist/StaticClassClient-CCn9g9eF.js +0 -636
- package/dist/StaticClassClient-CCn9g9eF.js.map +0 -1
- package/dist/components.cjs +0 -7
- package/dist/components.d.ts +0 -216
- package/dist/components.js +0 -2
- package/dist/generators-BYUJaeZP.js +0 -723
- package/dist/generators-BYUJaeZP.js.map +0 -1
- package/dist/generators-DTxD9FDY.cjs +0 -753
- package/dist/generators-DTxD9FDY.cjs.map +0 -1
- package/dist/generators.cjs +0 -7
- package/dist/generators.d.ts +0 -517
- package/dist/generators.js +0 -2
- package/dist/types-DBQdg-BV.d.ts +0 -169
- package/src/components/index.ts +0 -5
- package/src/generators/index.ts +0 -5
- package/templates/clients/axios.ts +0 -70
- package/templates/clients/fetch.ts +0 -93
- package/templates/config.ts +0 -43
package/src/plugin.ts
CHANGED
|
@@ -1,189 +1,159 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { camelCase } from '@internals/utils'
|
|
3
|
-
|
|
4
|
-
import {
|
|
3
|
+
|
|
4
|
+
import { ast, definePlugin, type Group } from '@kubb/core'
|
|
5
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
5
6
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
6
|
-
import { classClientGenerator
|
|
7
|
+
import { classClientGenerator } from './generators/classClientGenerator.tsx'
|
|
7
8
|
import { clientGenerator } from './generators/clientGenerator.tsx'
|
|
8
9
|
import { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'
|
|
10
|
+
import { operationsGenerator } from './generators/operationsGenerator.tsx'
|
|
9
11
|
import { staticClassClientGenerator } from './generators/staticClassClientGenerator.tsx'
|
|
12
|
+
import { resolverClient } from './resolvers/resolverClient.ts'
|
|
10
13
|
import { source as axiosClientSource } from './templates/clients/axios.source.ts'
|
|
11
14
|
import { source as fetchClientSource } from './templates/clients/fetch.source.ts'
|
|
12
15
|
import { source as configSource } from './templates/config.source.ts'
|
|
13
16
|
import type { PluginClient } from './types.ts'
|
|
14
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Canonical plugin name for `@kubb/plugin-client`, used in driver lookups and warnings.
|
|
20
|
+
*/
|
|
15
21
|
export const pluginClientName = 'plugin-client' satisfies PluginClient['name']
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Generates type-safe HTTP client functions or classes from an OpenAPI specification.
|
|
25
|
+
* Creates client APIs by walking operations and delegating to generators.
|
|
26
|
+
* Writes barrel files based on the configured `barrelType`.
|
|
27
|
+
*
|
|
28
|
+
* @example Client generator
|
|
29
|
+
* ```ts
|
|
30
|
+
* import pluginClient from '@kubb/plugin-client'
|
|
31
|
+
* export default defineConfig({
|
|
32
|
+
* plugins: [pluginClient({ output: { path: 'clients' } })]
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const pluginClient = definePlugin<PluginClient>((options) => {
|
|
18
37
|
const {
|
|
19
38
|
output = { path: 'clients', barrelType: 'named' },
|
|
20
39
|
group,
|
|
21
|
-
urlType = false,
|
|
22
40
|
exclude = [],
|
|
23
41
|
include,
|
|
24
42
|
override = [],
|
|
25
|
-
|
|
43
|
+
urlType = false,
|
|
26
44
|
dataReturnType = 'data',
|
|
27
45
|
paramsType = 'inline',
|
|
28
46
|
pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
|
|
29
47
|
operations = false,
|
|
30
|
-
baseURL,
|
|
31
48
|
paramsCasing,
|
|
32
|
-
clientType = 'function',
|
|
49
|
+
clientType = options.sdk ? 'class' : 'function',
|
|
33
50
|
parser = 'client',
|
|
34
51
|
client = 'axios',
|
|
35
52
|
importPath,
|
|
36
|
-
contentType,
|
|
37
53
|
bundle = false,
|
|
38
|
-
|
|
54
|
+
sdk,
|
|
55
|
+
baseURL,
|
|
56
|
+
resolver: userResolver,
|
|
57
|
+
transformer: userTransformer,
|
|
39
58
|
} = options
|
|
40
59
|
|
|
41
60
|
const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : undefined)
|
|
42
61
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
clientType,
|
|
56
|
-
bundle,
|
|
57
|
-
output,
|
|
58
|
-
group,
|
|
59
|
-
parser,
|
|
60
|
-
dataReturnType,
|
|
61
|
-
importPath: resolvedImportPath,
|
|
62
|
-
paramsType,
|
|
63
|
-
paramsCasing,
|
|
64
|
-
pathParamsType,
|
|
65
|
-
baseURL,
|
|
66
|
-
urlType,
|
|
67
|
-
wrapper,
|
|
68
|
-
},
|
|
69
|
-
pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
70
|
-
resolvePath(baseName, pathMode, options) {
|
|
71
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
72
|
-
const mode = pathMode ?? getMode(path.resolve(root, output.path))
|
|
73
|
-
|
|
74
|
-
if (mode === 'single') {
|
|
75
|
-
/**
|
|
76
|
-
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
77
|
-
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
78
|
-
*/
|
|
79
|
-
return path.resolve(root, output.path)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
83
|
-
const groupName: Group['name'] = group?.name
|
|
62
|
+
const selectedGenerators =
|
|
63
|
+
options.generators ??
|
|
64
|
+
[
|
|
65
|
+
clientType === 'staticClass' ? staticClassClientGenerator : clientType === 'class' ? classClientGenerator : clientGenerator,
|
|
66
|
+
group && clientType === 'function' ? groupedClientGenerator : undefined,
|
|
67
|
+
operations ? operationsGenerator : undefined,
|
|
68
|
+
].filter((x): x is NonNullable<typeof x> => Boolean(x))
|
|
69
|
+
|
|
70
|
+
const groupConfig = group
|
|
71
|
+
? ({
|
|
72
|
+
...group,
|
|
73
|
+
name: group.name
|
|
84
74
|
? group.name
|
|
85
|
-
: (ctx) => {
|
|
86
|
-
if (group
|
|
75
|
+
: (ctx: { group: string }) => {
|
|
76
|
+
if (group.type === 'path') {
|
|
87
77
|
return `${ctx.group.split('/')[1]}`
|
|
88
78
|
}
|
|
89
79
|
return `${camelCase(ctx.group)}Controller`
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return path.resolve(
|
|
93
|
-
root,
|
|
94
|
-
output.path,
|
|
95
|
-
groupName({
|
|
96
|
-
group: group.type === 'path' ? options.group.path! : options.group.tag!,
|
|
97
|
-
}),
|
|
98
|
-
baseName,
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return path.resolve(root, output.path, baseName)
|
|
103
|
-
},
|
|
104
|
-
resolveName(name, type) {
|
|
105
|
-
const resolvedName = camelCase(name, { isFile: type === 'file' })
|
|
106
|
-
|
|
107
|
-
if (type) {
|
|
108
|
-
return transformers?.name?.(resolvedName, type) || resolvedName
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return resolvedName
|
|
112
|
-
},
|
|
113
|
-
async install() {
|
|
114
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
115
|
-
const mode = getMode(path.resolve(root, output.path))
|
|
116
|
-
const oas = await this.getOas()
|
|
117
|
-
const baseURL = await this.getBaseURL()
|
|
118
|
-
|
|
119
|
-
// pre add bundled fetch
|
|
120
|
-
if (bundle && !this.plugin.options.importPath) {
|
|
121
|
-
await this.addFile({
|
|
122
|
-
baseName: 'fetch.ts',
|
|
123
|
-
path: path.resolve(root, '.kubb/fetch.ts'),
|
|
124
|
-
sources: [
|
|
125
|
-
{
|
|
126
|
-
name: 'fetch',
|
|
127
|
-
value: this.plugin.options.client === 'fetch' ? fetchClientSource : axiosClientSource,
|
|
128
|
-
isExportable: true,
|
|
129
|
-
isIndexable: true,
|
|
130
80
|
},
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
exports: [],
|
|
134
|
-
})
|
|
135
|
-
}
|
|
81
|
+
} satisfies Group)
|
|
82
|
+
: undefined
|
|
136
83
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
const operationGenerator = new OperationGenerator(
|
|
153
|
-
baseURL
|
|
154
|
-
? {
|
|
155
|
-
...this.plugin.options,
|
|
156
|
-
baseURL,
|
|
157
|
-
}
|
|
158
|
-
: this.plugin.options,
|
|
159
|
-
{
|
|
160
|
-
fabric: this.fabric,
|
|
161
|
-
oas,
|
|
162
|
-
driver: this.driver,
|
|
163
|
-
events: this.events,
|
|
164
|
-
plugin: this.plugin,
|
|
165
|
-
contentType,
|
|
84
|
+
return {
|
|
85
|
+
name: pluginClientName,
|
|
86
|
+
options,
|
|
87
|
+
dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),
|
|
88
|
+
hooks: {
|
|
89
|
+
'kubb:plugin:setup'(ctx) {
|
|
90
|
+
const resolver = userResolver ? { ...resolverClient, ...userResolver } : resolverClient
|
|
91
|
+
|
|
92
|
+
ctx.setOptions({
|
|
93
|
+
client,
|
|
94
|
+
clientType,
|
|
95
|
+
bundle,
|
|
96
|
+
output,
|
|
166
97
|
exclude,
|
|
167
98
|
include,
|
|
168
99
|
override,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
100
|
+
group: groupConfig,
|
|
101
|
+
parser,
|
|
102
|
+
dataReturnType,
|
|
103
|
+
importPath: resolvedImportPath,
|
|
104
|
+
baseURL,
|
|
105
|
+
paramsType,
|
|
106
|
+
paramsCasing,
|
|
107
|
+
pathParamsType,
|
|
108
|
+
urlType,
|
|
109
|
+
sdk,
|
|
110
|
+
resolver,
|
|
111
|
+
})
|
|
112
|
+
ctx.setResolver(resolver)
|
|
113
|
+
if (userTransformer) {
|
|
114
|
+
ctx.setTransformer(userTransformer)
|
|
115
|
+
}
|
|
116
|
+
for (const gen of selectedGenerators) {
|
|
117
|
+
ctx.addGenerator(gen)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const root = path.resolve(ctx.config.root, ctx.config.output.path)
|
|
121
|
+
|
|
122
|
+
const isRelativePath = resolvedImportPath?.startsWith('.')
|
|
123
|
+
|
|
124
|
+
if (!isRelativePath) {
|
|
125
|
+
const isInlineSource = bundle && !resolvedImportPath
|
|
126
|
+
|
|
127
|
+
ctx.injectFile({
|
|
128
|
+
baseName: 'client.ts',
|
|
129
|
+
path: path.resolve(root, '.kubb/client.ts'),
|
|
130
|
+
sources: [
|
|
131
|
+
ast.createSource({
|
|
132
|
+
name: 'client',
|
|
133
|
+
nodes: isInlineSource ? [ast.createText(client === 'fetch' ? fetchClientSource : axiosClientSource)] : [],
|
|
134
|
+
isExportable: true,
|
|
135
|
+
isIndexable: true,
|
|
136
|
+
}),
|
|
137
|
+
],
|
|
138
|
+
exports: !isInlineSource && resolvedImportPath ? [ast.createExport({ path: resolvedImportPath })] : [],
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
ctx.injectFile({
|
|
143
|
+
baseName: 'config.ts',
|
|
144
|
+
path: path.resolve(root, '.kubb/config.ts'),
|
|
145
|
+
sources: [
|
|
146
|
+
ast.createSource({
|
|
147
|
+
name: 'config',
|
|
148
|
+
nodes: [ast.createText(configSource)],
|
|
149
|
+
isExportable: false,
|
|
150
|
+
isIndexable: false,
|
|
151
|
+
}),
|
|
152
|
+
],
|
|
153
|
+
})
|
|
154
|
+
},
|
|
187
155
|
},
|
|
188
156
|
}
|
|
189
157
|
})
|
|
158
|
+
|
|
159
|
+
export default pluginClient
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { camelCase, pascalCase } from '@internals/utils'
|
|
2
|
+
import { defineResolver } from '@kubb/core'
|
|
3
|
+
import type { PluginClient } from '../types.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Naming convention resolver for client plugin.
|
|
7
|
+
*
|
|
8
|
+
* Provides default naming helpers using camelCase for functions and file paths.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* `resolverClient.default('list pets', 'function') // → 'listPets'`
|
|
12
|
+
*/
|
|
13
|
+
export const resolverClient = defineResolver<PluginClient>(() => ({
|
|
14
|
+
name: 'default',
|
|
15
|
+
pluginName: 'plugin-client',
|
|
16
|
+
default(name, type) {
|
|
17
|
+
return camelCase(name, { isFile: type === 'file' })
|
|
18
|
+
},
|
|
19
|
+
resolveName(name) {
|
|
20
|
+
return this.default(name, 'function')
|
|
21
|
+
},
|
|
22
|
+
resolvePathName(name, type) {
|
|
23
|
+
return this.default(name, type)
|
|
24
|
+
},
|
|
25
|
+
resolveClassName(name) {
|
|
26
|
+
return pascalCase(name)
|
|
27
|
+
},
|
|
28
|
+
resolveGroupName(name) {
|
|
29
|
+
return pascalCase(name)
|
|
30
|
+
},
|
|
31
|
+
resolveClientPropertyName(name) {
|
|
32
|
+
return camelCase(name)
|
|
33
|
+
},
|
|
34
|
+
resolveUrlName(node) {
|
|
35
|
+
const name = this.resolveName(node.operationId)
|
|
36
|
+
return `get${name.charAt(0).toUpperCase()}${name.slice(1)}Url`
|
|
37
|
+
},
|
|
38
|
+
}))
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,41 @@
|
|
|
1
|
-
import type { Group, Output, PluginFactoryOptions,
|
|
1
|
+
import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The concrete resolver type for `@kubb/plugin-client`.
|
|
5
|
+
* Extends the base `Resolver` with a `resolveName` helper for client function names.
|
|
6
|
+
*/
|
|
7
|
+
export type ResolverClient = Resolver & {
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the function name for a given raw operation name.
|
|
10
|
+
*
|
|
11
|
+
* @example Resolving operation names
|
|
12
|
+
* `resolver.resolveName('show pet by id') // -> 'showPetById'`
|
|
13
|
+
*/
|
|
14
|
+
resolveName(this: ResolverClient, name: string): string
|
|
15
|
+
/**
|
|
16
|
+
* Resolves the output file name for a client module.
|
|
17
|
+
*/
|
|
18
|
+
resolvePathName(this: ResolverClient, name: string, type?: 'file' | 'function' | 'type' | 'const'): string
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the generated class name for class-based clients.
|
|
21
|
+
*/
|
|
22
|
+
resolveClassName(this: ResolverClient, name: string): string
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the generated class name for tag-based client groups.
|
|
25
|
+
*/
|
|
26
|
+
resolveGroupName(this: ResolverClient, name: string): string
|
|
27
|
+
/**
|
|
28
|
+
* Resolves the generated SDK facade property name for a client class.
|
|
29
|
+
*/
|
|
30
|
+
resolveClientPropertyName(this: ResolverClient, name: string): string
|
|
31
|
+
/**
|
|
32
|
+
* Resolves the URL helper function name for an operation.
|
|
33
|
+
*
|
|
34
|
+
* @example Resolving URL helper names
|
|
35
|
+
* `resolver.resolveUrlName(node) // -> 'getShowPetByIdUrl'`
|
|
36
|
+
*/
|
|
37
|
+
resolveUrlName(this: ResolverClient, node: ast.OperationNode): string
|
|
38
|
+
}
|
|
6
39
|
|
|
7
40
|
/**
|
|
8
41
|
* Use either a preset `client` type OR a custom `importPath`, not both.
|
|
@@ -36,17 +69,52 @@ export type ClientImportPath =
|
|
|
36
69
|
bundle?: never
|
|
37
70
|
}
|
|
38
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Discriminated union that ties `pathParamsType` to the `paramsType` values where it is meaningful.
|
|
74
|
+
*
|
|
75
|
+
* - `paramsType: 'object'` — all parameters (including path params) are merged into a single
|
|
76
|
+
* destructured object. `pathParamsType` is never reached in this code path and has no effect.
|
|
77
|
+
* - `paramsType?: 'inline'` (or omitted) — each parameter group is a separate function argument.
|
|
78
|
+
* `pathParamsType` controls whether the path-param group itself is destructured (`'object'`)
|
|
79
|
+
* or spread as individual arguments (`'inline'`).
|
|
80
|
+
*/
|
|
81
|
+
type ParamsTypeOptions =
|
|
82
|
+
| {
|
|
83
|
+
/**
|
|
84
|
+
* All parameters — path, query, headers, and body — are merged into a single
|
|
85
|
+
* destructured object argument.
|
|
86
|
+
* - 'object' returns the params and pathParams as an object.
|
|
87
|
+
* @default 'inline'
|
|
88
|
+
*/
|
|
89
|
+
paramsType: 'object'
|
|
90
|
+
/**
|
|
91
|
+
* `pathParamsType` has no effect when `paramsType` is `'object'`.
|
|
92
|
+
* Path params are already inside the single destructured object.
|
|
93
|
+
*/
|
|
94
|
+
pathParamsType?: never
|
|
95
|
+
}
|
|
96
|
+
| {
|
|
97
|
+
/**
|
|
98
|
+
* Each parameter group is emitted as a separate function argument.
|
|
99
|
+
* - 'inline' returns the params as comma separated params.
|
|
100
|
+
* @default 'inline'
|
|
101
|
+
*/
|
|
102
|
+
paramsType?: 'inline'
|
|
103
|
+
/**
|
|
104
|
+
* Controls how path parameters are arranged within the inline argument list.
|
|
105
|
+
* - 'object' groups path params into a destructured object: `{ petId }: PathParams`.
|
|
106
|
+
* - 'inline' emits each path param as its own argument: `petId: string`.
|
|
107
|
+
* @default 'inline'
|
|
108
|
+
*/
|
|
109
|
+
pathParamsType?: 'object' | 'inline'
|
|
110
|
+
}
|
|
111
|
+
|
|
39
112
|
export type Options = {
|
|
40
113
|
/**
|
|
41
|
-
* Specify the export location for the files and define the behavior of the output
|
|
114
|
+
* Specify the export location for the files and define the behavior of the output.
|
|
42
115
|
* @default { path: 'clients', barrelType: 'named' }
|
|
43
116
|
*/
|
|
44
|
-
output?: Output
|
|
45
|
-
/**
|
|
46
|
-
* Define which contentType should be used.
|
|
47
|
-
* By default, the first JSON valid mediaType is used
|
|
48
|
-
*/
|
|
49
|
-
contentType?: contentType
|
|
117
|
+
output?: Output
|
|
50
118
|
/**
|
|
51
119
|
* Group the clients based on the provided name.
|
|
52
120
|
*/
|
|
@@ -88,25 +156,11 @@ export type Options = {
|
|
|
88
156
|
*/
|
|
89
157
|
dataReturnType?: 'data' | 'full'
|
|
90
158
|
/**
|
|
91
|
-
* How to style your params, by default no casing is applied
|
|
159
|
+
* How to style your params, by default no casing is applied.
|
|
92
160
|
* - 'camelcase' uses camelCase for pathParams, queryParams and headerParams names
|
|
93
161
|
* @note response types (data/body) are not affected by this option
|
|
94
162
|
*/
|
|
95
163
|
paramsCasing?: 'camelcase'
|
|
96
|
-
/**
|
|
97
|
-
* How to pass your params.
|
|
98
|
-
* - 'object' returns the params and pathParams as an object.
|
|
99
|
-
* - 'inline' returns the params as comma separated params.
|
|
100
|
-
* @default 'inline'
|
|
101
|
-
*/
|
|
102
|
-
paramsType?: 'object' | 'inline'
|
|
103
|
-
/**
|
|
104
|
-
* How to pass your pathParams.
|
|
105
|
-
* - 'object' returns the pathParams as an object.
|
|
106
|
-
* - 'inline' returns the pathParams as comma separated params.
|
|
107
|
-
* @default 'inline'
|
|
108
|
-
*/
|
|
109
|
-
pathParamsType?: 'object' | 'inline'
|
|
110
164
|
/**
|
|
111
165
|
* Which parser can be used before returning the data.
|
|
112
166
|
* - 'client' returns the data as-is from the client.
|
|
@@ -130,41 +184,71 @@ export type Options = {
|
|
|
130
184
|
*/
|
|
131
185
|
bundle?: boolean
|
|
132
186
|
/**
|
|
133
|
-
* Generate
|
|
134
|
-
|
|
135
|
-
|
|
187
|
+
* Generate an SDK facade class that composes all tag-based client classes into a single entry point.
|
|
188
|
+
* Setting this option automatically enables `clientType: 'class'`.
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* pluginClient({
|
|
192
|
+
* sdk: { className: 'PetStoreSDK' },
|
|
193
|
+
* })
|
|
194
|
+
* // Generates a class with a shared constructor config and one property per tag:
|
|
195
|
+
* // class PetStoreSDK {
|
|
196
|
+
* // readonly petController: petController
|
|
197
|
+
* // readonly storeController: storeController
|
|
198
|
+
* // constructor(config = {}) { ... }
|
|
199
|
+
* // }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
sdk?: {
|
|
136
203
|
/**
|
|
137
|
-
* Name of the
|
|
204
|
+
* Name of the generated SDK facade class.
|
|
138
205
|
*/
|
|
139
206
|
className: string
|
|
140
207
|
}
|
|
141
|
-
transformers?: {
|
|
142
|
-
/**
|
|
143
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
144
|
-
*/
|
|
145
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
146
|
-
}
|
|
147
208
|
/**
|
|
148
|
-
*
|
|
209
|
+
* Override individual resolver methods. Any method you omit falls back to the
|
|
210
|
+
* preset resolver's implementation. Use `this.default(...)` to call it.
|
|
211
|
+
*/
|
|
212
|
+
resolver?: Partial<ResolverClient> & ThisType<ResolverClient>
|
|
213
|
+
/**
|
|
214
|
+
* Single AST visitor applied to each node before printing.
|
|
215
|
+
* Return `null` or `undefined` from a method to leave the node unchanged.
|
|
216
|
+
*/
|
|
217
|
+
transformer?: ast.Visitor
|
|
218
|
+
/**
|
|
219
|
+
* Define some generators next to the client generators.
|
|
149
220
|
*/
|
|
150
221
|
generators?: Array<Generator<PluginClient>>
|
|
151
|
-
} & ClientImportPath
|
|
222
|
+
} & ClientImportPath &
|
|
223
|
+
ParamsTypeOptions
|
|
152
224
|
|
|
153
225
|
type ResolvedOptions = {
|
|
154
|
-
output: Output
|
|
155
|
-
|
|
156
|
-
|
|
226
|
+
output: Output
|
|
227
|
+
exclude: Array<Exclude>
|
|
228
|
+
include: Array<Include> | undefined
|
|
229
|
+
override: Array<Override<ResolvedOptions>>
|
|
230
|
+
group: Group | undefined
|
|
157
231
|
client: Options['client']
|
|
158
232
|
clientType: NonNullable<Options['clientType']>
|
|
159
233
|
bundle: NonNullable<Options['bundle']>
|
|
160
234
|
parser: NonNullable<Options['parser']>
|
|
161
235
|
urlType: NonNullable<Options['urlType']>
|
|
162
236
|
importPath: Options['importPath']
|
|
237
|
+
baseURL: Options['baseURL']
|
|
163
238
|
dataReturnType: NonNullable<Options['dataReturnType']>
|
|
164
|
-
pathParamsType: NonNullable<Options['pathParamsType']
|
|
239
|
+
pathParamsType: NonNullable<NonNullable<Options['pathParamsType']>>
|
|
165
240
|
paramsType: NonNullable<Options['paramsType']>
|
|
166
241
|
paramsCasing: Options['paramsCasing']
|
|
167
|
-
|
|
242
|
+
sdk: Options['sdk']
|
|
243
|
+
resolver: ResolverClient
|
|
168
244
|
}
|
|
169
245
|
|
|
170
|
-
export type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions,
|
|
246
|
+
export type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, ResolverClient>
|
|
247
|
+
|
|
248
|
+
declare global {
|
|
249
|
+
namespace Kubb {
|
|
250
|
+
interface PluginRegistry {
|
|
251
|
+
'plugin-client': PluginClient
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|