@kubb/plugin-client 5.0.0-alpha.31 → 5.0.0-alpha.33
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/dist/index.cjs +132 -136
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -9
- package/dist/index.js +31 -35
- package/dist/index.js.map +1 -1
- package/package.json +8 -10
- package/src/components/ClassClient.tsx +4 -4
- package/src/components/Client.tsx +7 -6
- package/src/components/ClientLegacy.tsx +7 -5
- package/src/components/Operations.tsx +3 -3
- package/src/components/StaticClassClient.tsx +4 -4
- package/src/components/Url.tsx +3 -3
- package/src/components/WrapperClient.tsx +3 -3
- package/src/generators/classClientGenerator.tsx +13 -14
- package/src/generators/clientGenerator.tsx +4 -4
- package/src/generators/groupedClientGenerator.tsx +5 -5
- package/src/generators/operationsGenerator.tsx +3 -3
- package/src/generators/staticClassClientGenerator.tsx +11 -12
- package/src/plugin.ts +29 -28
- package/src/utils.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-client",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.33",
|
|
4
4
|
"description": "API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -94,21 +94,19 @@
|
|
|
94
94
|
}
|
|
95
95
|
],
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@kubb/
|
|
98
|
-
"@kubb/
|
|
99
|
-
"@kubb/
|
|
100
|
-
"@kubb/
|
|
101
|
-
"@kubb/
|
|
102
|
-
"@kubb/plugin-zod": "5.0.0-alpha.31"
|
|
97
|
+
"@kubb/ast": "5.0.0-alpha.33",
|
|
98
|
+
"@kubb/core": "5.0.0-alpha.33",
|
|
99
|
+
"@kubb/plugin-ts": "5.0.0-alpha.33",
|
|
100
|
+
"@kubb/plugin-zod": "5.0.0-alpha.33",
|
|
101
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.33"
|
|
103
102
|
},
|
|
104
103
|
"devDependencies": {
|
|
105
104
|
"axios": "^1.14.0",
|
|
106
105
|
"@internals/utils": "0.0.0"
|
|
107
106
|
},
|
|
108
107
|
"peerDependencies": {
|
|
109
|
-
"
|
|
110
|
-
"@kubb/
|
|
111
|
-
"axios": "^1.7.2"
|
|
108
|
+
"axios": "^1.7.2",
|
|
109
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.33"
|
|
112
110
|
},
|
|
113
111
|
"peerDependenciesMeta": {
|
|
114
112
|
"axios": {
|
|
@@ -3,8 +3,8 @@ import type { OperationNode } from '@kubb/ast/types'
|
|
|
3
3
|
import type { PluginTs } from '@kubb/plugin-ts'
|
|
4
4
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
5
5
|
import type { PluginZod } from '@kubb/plugin-zod'
|
|
6
|
-
import { File } from '@kubb/
|
|
7
|
-
import type {
|
|
6
|
+
import { File } from '@kubb/renderer-jsx'
|
|
7
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
8
8
|
import type { PluginClient } from '../types.ts'
|
|
9
9
|
import { buildClassClientParams, buildFormDataLine, buildGenerics, buildHeaders, buildRequestDataLine, buildReturnStatement, getComments } from '../utils.ts'
|
|
10
10
|
|
|
@@ -28,7 +28,7 @@ type Props = {
|
|
|
28
28
|
paramsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
29
29
|
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
30
30
|
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
31
|
-
children?:
|
|
31
|
+
children?: KubbReactNode
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
type GenerateMethodProps = {
|
|
@@ -103,7 +103,7 @@ export function ClassClient({
|
|
|
103
103
|
paramsCasing,
|
|
104
104
|
pathParamsType,
|
|
105
105
|
children,
|
|
106
|
-
}: Props):
|
|
106
|
+
}: Props): KubbReactNode {
|
|
107
107
|
const methods = operations.map(({ node, name: methodName, tsResolver, zodResolver }) =>
|
|
108
108
|
generateMethod({
|
|
109
109
|
node,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isValidVarName, URLPath } from '@internals/utils'
|
|
2
|
-
import { caseParams, createFunctionParameter, createOperationParams,
|
|
2
|
+
import { caseParams, createFunctionParameter, createOperationParams, createParamsType } from '@kubb/ast'
|
|
3
3
|
import type { FunctionParametersNode, OperationNode } from '@kubb/ast/types'
|
|
4
|
+
import { FunctionParams } from '@kubb/core'
|
|
4
5
|
import type { PluginTs } from '@kubb/plugin-ts'
|
|
5
6
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
6
7
|
import type { PluginZod } from '@kubb/plugin-zod'
|
|
7
|
-
import { File, Function
|
|
8
|
-
import type {
|
|
8
|
+
import { File, Function } from '@kubb/renderer-jsx'
|
|
9
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
9
10
|
import type { PluginClient } from '../types.ts'
|
|
10
11
|
import { buildParamsMapping, getComments } from '../utils.ts'
|
|
11
12
|
import { Url } from './Url.tsx'
|
|
@@ -27,7 +28,7 @@ type Props = {
|
|
|
27
28
|
node: OperationNode
|
|
28
29
|
tsResolver: PluginTs['resolver']
|
|
29
30
|
zodResolver?: PluginZod['resolver']
|
|
30
|
-
children?:
|
|
31
|
+
children?: KubbReactNode
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
type GetParamsProps = {
|
|
@@ -53,7 +54,7 @@ function getParams({ paramsType, paramsCasing, pathParamsType, node, tsResolver,
|
|
|
53
54
|
? [
|
|
54
55
|
createFunctionParameter({
|
|
55
56
|
name: 'config',
|
|
56
|
-
type:
|
|
57
|
+
type: createParamsType({
|
|
57
58
|
variant: 'reference',
|
|
58
59
|
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }',
|
|
59
60
|
}),
|
|
@@ -81,7 +82,7 @@ export function Client({
|
|
|
81
82
|
urlName,
|
|
82
83
|
children,
|
|
83
84
|
isConfigurable = true,
|
|
84
|
-
}: Props):
|
|
85
|
+
}: Props): KubbReactNode {
|
|
85
86
|
const path = new URLPath(node.path)
|
|
86
87
|
const contentType = node.requestBody?.contentType ?? 'application/json'
|
|
87
88
|
const isFormData = contentType === 'multipart/form-data'
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { camelCase, isValidVarName, URLPath } from '@internals/utils'
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import type { Params } from '@kubb/core'
|
|
3
|
+
import { FunctionParams } from '@kubb/core'
|
|
4
|
+
import { Const, File, Function } from '@kubb/renderer-jsx'
|
|
5
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Structural type matching OperationSchema from @kubb/plugin-oas.
|
|
@@ -148,7 +150,7 @@ type Props = {
|
|
|
148
150
|
typeSchemas: LegacyOperationSchemas
|
|
149
151
|
zodSchemas: LegacyOperationSchemas | undefined
|
|
150
152
|
operation: LegacyOperation
|
|
151
|
-
children?:
|
|
153
|
+
children?: KubbReactNode
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
type GetParamsProps = {
|
|
@@ -264,7 +266,7 @@ export function ClientLegacy({
|
|
|
264
266
|
urlName,
|
|
265
267
|
children,
|
|
266
268
|
isConfigurable = true,
|
|
267
|
-
}: Props):
|
|
269
|
+
}: Props): KubbReactNode {
|
|
268
270
|
const path = new URLPath(operation.path)
|
|
269
271
|
const contentType = operation.getContentType?.() ?? 'application/json'
|
|
270
272
|
const isFormData = contentType === 'multipart/form-data'
|
|
@@ -470,7 +472,7 @@ export function UrlLegacy({
|
|
|
470
472
|
paramsCasing,
|
|
471
473
|
pathParamsType,
|
|
472
474
|
operation,
|
|
473
|
-
}: UrlProps):
|
|
475
|
+
}: UrlProps): KubbReactNode {
|
|
474
476
|
const path = new URLPath(operation.path)
|
|
475
477
|
const params = getUrlParams({
|
|
476
478
|
paramsType,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { URLPath } from '@internals/utils'
|
|
2
2
|
import type { OperationNode } from '@kubb/ast/types'
|
|
3
|
-
import { Const, File } from '@kubb/
|
|
4
|
-
import type {
|
|
3
|
+
import { Const, File } from '@kubb/renderer-jsx'
|
|
4
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
5
5
|
|
|
6
6
|
type OperationsProps = {
|
|
7
7
|
name: string
|
|
8
8
|
nodes: Array<OperationNode>
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export function Operations({ name, nodes }: OperationsProps):
|
|
11
|
+
export function Operations({ name, nodes }: OperationsProps): KubbReactNode {
|
|
12
12
|
const operationsObject: Record<string, { path: string; method: string }> = {}
|
|
13
13
|
|
|
14
14
|
nodes.forEach((node) => {
|
|
@@ -3,8 +3,8 @@ import type { OperationNode } from '@kubb/ast/types'
|
|
|
3
3
|
import type { PluginTs } from '@kubb/plugin-ts'
|
|
4
4
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
5
5
|
import type { PluginZod } from '@kubb/plugin-zod'
|
|
6
|
-
import { File } from '@kubb/
|
|
7
|
-
import type {
|
|
6
|
+
import { File } from '@kubb/renderer-jsx'
|
|
7
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
8
8
|
import type { PluginClient } from '../types.ts'
|
|
9
9
|
import { buildClassClientParams, buildFormDataLine, buildGenerics, buildHeaders, buildRequestDataLine, buildReturnStatement, getComments } from '../utils.ts'
|
|
10
10
|
import { Client } from './Client.tsx'
|
|
@@ -27,7 +27,7 @@ type Props = {
|
|
|
27
27
|
paramsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
28
28
|
pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
|
|
29
29
|
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
30
|
-
children?:
|
|
30
|
+
children?: KubbReactNode
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
type GenerateMethodProps = {
|
|
@@ -102,7 +102,7 @@ export function StaticClassClient({
|
|
|
102
102
|
paramsCasing,
|
|
103
103
|
pathParamsType,
|
|
104
104
|
children,
|
|
105
|
-
}: Props):
|
|
105
|
+
}: Props): KubbReactNode {
|
|
106
106
|
const methods = operations.map(({ node, name: methodName, tsResolver, zodResolver }) =>
|
|
107
107
|
generateMethod({
|
|
108
108
|
node,
|
package/src/components/Url.tsx
CHANGED
|
@@ -3,8 +3,8 @@ import { caseParams, createOperationParams } from '@kubb/ast'
|
|
|
3
3
|
import type { FunctionParametersNode, OperationNode } from '@kubb/ast/types'
|
|
4
4
|
import type { PluginTs } from '@kubb/plugin-ts'
|
|
5
5
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
6
|
-
import { Const, File, Function } from '@kubb/
|
|
7
|
-
import type {
|
|
6
|
+
import { Const, File, Function } from '@kubb/renderer-jsx'
|
|
7
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
8
8
|
import type { PluginClient } from '../types.ts'
|
|
9
9
|
import { buildParamsMapping } from '../utils.ts'
|
|
10
10
|
|
|
@@ -57,7 +57,7 @@ export function Url({
|
|
|
57
57
|
pathParamsType,
|
|
58
58
|
node,
|
|
59
59
|
tsResolver,
|
|
60
|
-
}: Props):
|
|
60
|
+
}: Props): KubbReactNode {
|
|
61
61
|
const path = new URLPath(node.path)
|
|
62
62
|
|
|
63
63
|
const paramsNode = getParams({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { camelCase } from '@internals/utils'
|
|
2
|
-
import { File } from '@kubb/
|
|
3
|
-
import type {
|
|
2
|
+
import { File } from '@kubb/renderer-jsx'
|
|
3
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
4
4
|
|
|
5
5
|
type Props = {
|
|
6
6
|
name: string
|
|
@@ -9,7 +9,7 @@ type Props = {
|
|
|
9
9
|
isIndexable?: boolean
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function WrapperClient({ name, classNames, isExportable = true, isIndexable = true }: Props):
|
|
12
|
+
export function WrapperClient({ name, classNames, isExportable = true, isIndexable = true }: Props): KubbReactNode {
|
|
13
13
|
const properties = classNames.map((className) => ` readonly ${camelCase(className)}: ${className}`).join('\n')
|
|
14
14
|
const assignments = classNames.map((className) => ` this.${camelCase(className)} = new ${className}(config)`).join('\n')
|
|
15
15
|
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { camelCase, pascalCase } from '@internals/utils'
|
|
3
|
-
import type { OperationNode } from '@kubb/ast/types'
|
|
4
|
-
import type { KubbFile } from '@kubb/core'
|
|
3
|
+
import type { FileNode, OperationNode } from '@kubb/ast/types'
|
|
5
4
|
import { defineGenerator } from '@kubb/core'
|
|
6
5
|
import type { PluginTs } from '@kubb/plugin-ts'
|
|
7
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
8
7
|
import type { PluginZod } from '@kubb/plugin-zod'
|
|
9
8
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
-
import { File } from '@kubb/
|
|
9
|
+
import { File } from '@kubb/renderer-jsx'
|
|
11
10
|
import { ClassClient } from '../components/ClassClient'
|
|
12
11
|
import { WrapperClient } from '../components/WrapperClient'
|
|
13
12
|
import type { PluginClient } from '../types'
|
|
@@ -17,13 +16,13 @@ type OperationData = {
|
|
|
17
16
|
name: string
|
|
18
17
|
tsResolver: PluginTs['resolver']
|
|
19
18
|
zodResolver: PluginZod['resolver'] | undefined
|
|
20
|
-
typeFile:
|
|
21
|
-
zodFile:
|
|
19
|
+
typeFile: FileNode
|
|
20
|
+
zodFile: FileNode | undefined
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
type Controller = {
|
|
25
24
|
name: string
|
|
26
|
-
file:
|
|
25
|
+
file: FileNode
|
|
27
26
|
operations: Array<OperationData>
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -49,7 +48,7 @@ export const classClientGenerator = defineGenerator<PluginClient>({
|
|
|
49
48
|
operations(nodes, options) {
|
|
50
49
|
const { adapter, config, driver, resolver, root } = this
|
|
51
50
|
const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, wrapper } = options
|
|
52
|
-
const baseURL = options.baseURL ?? adapter.
|
|
51
|
+
const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL
|
|
53
52
|
|
|
54
53
|
const pluginTs = driver.getPlugin(pluginTsName)
|
|
55
54
|
if (!pluginTs?.resolver) return null
|
|
@@ -118,7 +117,7 @@ export const classClientGenerator = defineGenerator<PluginClient>({
|
|
|
118
117
|
|
|
119
118
|
function collectTypeImports(ops: Array<OperationData>) {
|
|
120
119
|
const typeImportsByFile = new Map<string, Set<string>>()
|
|
121
|
-
const typeFilesByPath = new Map<string,
|
|
120
|
+
const typeFilesByPath = new Map<string, FileNode>()
|
|
122
121
|
|
|
123
122
|
ops.forEach((op) => {
|
|
124
123
|
const names = resolveTypeImportNames(op.node, tsResolver)
|
|
@@ -137,7 +136,7 @@ export const classClientGenerator = defineGenerator<PluginClient>({
|
|
|
137
136
|
|
|
138
137
|
function collectZodImports(ops: Array<OperationData>) {
|
|
139
138
|
const zodImportsByFile = new Map<string, Set<string>>()
|
|
140
|
-
const zodFilesByPath = new Map<string,
|
|
139
|
+
const zodFilesByPath = new Map<string, FileNode>()
|
|
141
140
|
|
|
142
141
|
ops.forEach((op) => {
|
|
143
142
|
if (!op.zodFile || !zodResolver) return
|
|
@@ -158,7 +157,7 @@ export const classClientGenerator = defineGenerator<PluginClient>({
|
|
|
158
157
|
const files = controllers.map(({ name, file, operations: ops }) => {
|
|
159
158
|
const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops)
|
|
160
159
|
const { zodImportsByFile, zodFilesByPath } =
|
|
161
|
-
parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string,
|
|
160
|
+
parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string, FileNode>() }
|
|
162
161
|
const hasFormData = ops.some((op) => op.node.requestBody?.contentType === 'multipart/form-data')
|
|
163
162
|
|
|
164
163
|
return (
|
|
@@ -167,8 +166,8 @@ export const classClientGenerator = defineGenerator<PluginClient>({
|
|
|
167
166
|
baseName={file.baseName}
|
|
168
167
|
path={file.path}
|
|
169
168
|
meta={file.meta}
|
|
170
|
-
banner={resolver.resolveBanner(adapter.
|
|
171
|
-
footer={resolver.resolveFooter(adapter.
|
|
169
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
170
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
172
171
|
>
|
|
173
172
|
{importPath ? (
|
|
174
173
|
<>
|
|
@@ -226,8 +225,8 @@ export const classClientGenerator = defineGenerator<PluginClient>({
|
|
|
226
225
|
baseName={wrapperFile.baseName}
|
|
227
226
|
path={wrapperFile.path}
|
|
228
227
|
meta={wrapperFile.meta}
|
|
229
|
-
banner={resolver.resolveBanner(adapter.
|
|
230
|
-
footer={resolver.resolveFooter(adapter.
|
|
228
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
229
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
231
230
|
>
|
|
232
231
|
{importPath ? (
|
|
233
232
|
<File.Import name={['Client', 'RequestConfig']} path={importPath} isTypeOnly />
|
|
@@ -3,7 +3,7 @@ import { caseParams } from '@kubb/ast'
|
|
|
3
3
|
import { defineGenerator } from '@kubb/core'
|
|
4
4
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
5
5
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
6
|
-
import { File } from '@kubb/
|
|
6
|
+
import { File } from '@kubb/renderer-jsx'
|
|
7
7
|
import { Client } from '../components/Client'
|
|
8
8
|
import { Url } from '../components/Url.tsx'
|
|
9
9
|
import type { PluginClient } from '../types'
|
|
@@ -13,7 +13,7 @@ export const clientGenerator = defineGenerator<PluginClient>({
|
|
|
13
13
|
operation(node, options) {
|
|
14
14
|
const { adapter, config, driver, resolver, root } = this
|
|
15
15
|
const { output, urlType, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, group } = options
|
|
16
|
-
const baseURL = options.baseURL ?? adapter.
|
|
16
|
+
const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL
|
|
17
17
|
|
|
18
18
|
const pluginTs = driver.getPlugin(pluginTsName)
|
|
19
19
|
|
|
@@ -77,8 +77,8 @@ export const clientGenerator = defineGenerator<PluginClient>({
|
|
|
77
77
|
baseName={meta.file.baseName}
|
|
78
78
|
path={meta.file.path}
|
|
79
79
|
meta={meta.file.meta}
|
|
80
|
-
banner={resolver.resolveBanner(adapter.
|
|
81
|
-
footer={resolver.resolveFooter(adapter.
|
|
80
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
81
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
82
82
|
>
|
|
83
83
|
{importPath ? (
|
|
84
84
|
<>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { camelCase } from '@internals/utils'
|
|
2
|
-
import type {
|
|
2
|
+
import type { FileNode } from '@kubb/ast/types'
|
|
3
3
|
import { defineGenerator } from '@kubb/core'
|
|
4
|
-
import { File, Function } from '@kubb/
|
|
4
|
+
import { File, Function } from '@kubb/renderer-jsx'
|
|
5
5
|
import type { PluginClient } from '../types'
|
|
6
6
|
|
|
7
7
|
export const groupedClientGenerator = defineGenerator<PluginClient>({
|
|
@@ -42,7 +42,7 @@ export const groupedClientGenerator = defineGenerator<PluginClient>({
|
|
|
42
42
|
|
|
43
43
|
return acc
|
|
44
44
|
},
|
|
45
|
-
[] as Array<{ name: string; file:
|
|
45
|
+
[] as Array<{ name: string; file: FileNode; clients: Array<{ name: string; file: FileNode }> }>,
|
|
46
46
|
)
|
|
47
47
|
|
|
48
48
|
return (
|
|
@@ -54,8 +54,8 @@ export const groupedClientGenerator = defineGenerator<PluginClient>({
|
|
|
54
54
|
baseName={file.baseName}
|
|
55
55
|
path={file.path}
|
|
56
56
|
meta={file.meta}
|
|
57
|
-
banner={resolver.resolveBanner(adapter.
|
|
58
|
-
footer={resolver.resolveFooter(adapter.
|
|
57
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
58
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
59
59
|
>
|
|
60
60
|
{clients.map((client) => (
|
|
61
61
|
<File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineGenerator } from '@kubb/core'
|
|
2
|
-
import { File } from '@kubb/
|
|
2
|
+
import { File } from '@kubb/renderer-jsx'
|
|
3
3
|
import { Operations } from '../components/Operations'
|
|
4
4
|
import type { PluginClient } from '../types'
|
|
5
5
|
|
|
@@ -17,8 +17,8 @@ export const operationsGenerator = defineGenerator<PluginClient>({
|
|
|
17
17
|
baseName={file.baseName}
|
|
18
18
|
path={file.path}
|
|
19
19
|
meta={file.meta}
|
|
20
|
-
banner={resolver.resolveBanner(adapter.
|
|
21
|
-
footer={resolver.resolveFooter(adapter.
|
|
20
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
21
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
22
22
|
>
|
|
23
23
|
<Operations name={name} nodes={nodes} />
|
|
24
24
|
</File>
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { camelCase, pascalCase } from '@internals/utils'
|
|
3
|
-
import type { OperationNode } from '@kubb/ast/types'
|
|
4
|
-
import type { KubbFile } from '@kubb/core'
|
|
3
|
+
import type { FileNode, OperationNode } from '@kubb/ast/types'
|
|
5
4
|
import { defineGenerator } from '@kubb/core'
|
|
6
5
|
import type { PluginTs } from '@kubb/plugin-ts'
|
|
7
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
8
7
|
import type { PluginZod } from '@kubb/plugin-zod'
|
|
9
8
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
-
import { File } from '@kubb/
|
|
9
|
+
import { File } from '@kubb/renderer-jsx'
|
|
11
10
|
import { StaticClassClient } from '../components/StaticClassClient'
|
|
12
11
|
import type { PluginClient } from '../types'
|
|
13
12
|
|
|
@@ -16,13 +15,13 @@ type OperationData = {
|
|
|
16
15
|
name: string
|
|
17
16
|
tsResolver: PluginTs['resolver']
|
|
18
17
|
zodResolver: PluginZod['resolver'] | undefined
|
|
19
|
-
typeFile:
|
|
20
|
-
zodFile:
|
|
18
|
+
typeFile: FileNode
|
|
19
|
+
zodFile: FileNode | undefined
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
type Controller = {
|
|
24
23
|
name: string
|
|
25
|
-
file:
|
|
24
|
+
file: FileNode
|
|
26
25
|
operations: Array<OperationData>
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -48,7 +47,7 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
|
|
|
48
47
|
operations(nodes, options) {
|
|
49
48
|
const { adapter, config, driver, resolver, root } = this
|
|
50
49
|
const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = options
|
|
51
|
-
const baseURL = options.baseURL ?? adapter.
|
|
50
|
+
const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL
|
|
52
51
|
|
|
53
52
|
const pluginTs = driver.getPlugin(pluginTsName)
|
|
54
53
|
if (!pluginTs?.resolver) return null
|
|
@@ -117,7 +116,7 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
|
|
|
117
116
|
|
|
118
117
|
function collectTypeImports(ops: Array<OperationData>) {
|
|
119
118
|
const typeImportsByFile = new Map<string, Set<string>>()
|
|
120
|
-
const typeFilesByPath = new Map<string,
|
|
119
|
+
const typeFilesByPath = new Map<string, FileNode>()
|
|
121
120
|
|
|
122
121
|
ops.forEach((op) => {
|
|
123
122
|
const names = resolveTypeImportNames(op.node, tsResolver)
|
|
@@ -136,7 +135,7 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
|
|
|
136
135
|
|
|
137
136
|
function collectZodImports(ops: Array<OperationData>) {
|
|
138
137
|
const zodImportsByFile = new Map<string, Set<string>>()
|
|
139
|
-
const zodFilesByPath = new Map<string,
|
|
138
|
+
const zodFilesByPath = new Map<string, FileNode>()
|
|
140
139
|
|
|
141
140
|
ops.forEach((op) => {
|
|
142
141
|
if (!op.zodFile || !zodResolver) return
|
|
@@ -159,7 +158,7 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
|
|
|
159
158
|
{controllers.map(({ name, file, operations: ops }) => {
|
|
160
159
|
const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops)
|
|
161
160
|
const { zodImportsByFile, zodFilesByPath } =
|
|
162
|
-
parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string,
|
|
161
|
+
parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string, FileNode>() }
|
|
163
162
|
const hasFormData = ops.some((op) => op.node.requestBody?.contentType === 'multipart/form-data')
|
|
164
163
|
|
|
165
164
|
return (
|
|
@@ -168,8 +167,8 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
|
|
|
168
167
|
baseName={file.baseName}
|
|
169
168
|
path={file.path}
|
|
170
169
|
meta={file.meta}
|
|
171
|
-
banner={resolver.resolveBanner(adapter.
|
|
172
|
-
footer={resolver.resolveFooter(adapter.
|
|
170
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
171
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
173
172
|
>
|
|
174
173
|
{importPath ? (
|
|
175
174
|
<>
|
package/src/plugin.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { camelCase } from '@internals/utils'
|
|
3
|
+
import { createFile, createSource, createText } from '@kubb/ast'
|
|
3
4
|
import { createPlugin, type Group, getPreset, mergeGenerators } from '@kubb/core'
|
|
4
5
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
5
6
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
@@ -161,36 +162,36 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
161
162
|
|
|
162
163
|
// pre add bundled fetch
|
|
163
164
|
if (bundle && !plugin.options.importPath) {
|
|
164
|
-
await this.addFile(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
165
|
+
await this.addFile(
|
|
166
|
+
createFile({
|
|
167
|
+
baseName: 'fetch.ts',
|
|
168
|
+
path: path.resolve(root, '.kubb/fetch.ts'),
|
|
169
|
+
sources: [
|
|
170
|
+
createSource({
|
|
171
|
+
name: 'fetch',
|
|
172
|
+
nodes: [createText(plugin.options.client === 'fetch' ? fetchClientSource : axiosClientSource)],
|
|
173
|
+
isExportable: true,
|
|
174
|
+
isIndexable: true,
|
|
175
|
+
}),
|
|
176
|
+
],
|
|
177
|
+
}),
|
|
178
|
+
)
|
|
178
179
|
}
|
|
179
180
|
|
|
180
|
-
await this.addFile(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
181
|
+
await this.addFile(
|
|
182
|
+
createFile({
|
|
183
|
+
baseName: 'config.ts',
|
|
184
|
+
path: path.resolve(root, '.kubb/config.ts'),
|
|
185
|
+
sources: [
|
|
186
|
+
createSource({
|
|
187
|
+
name: 'config',
|
|
188
|
+
nodes: [createText(configSource)],
|
|
189
|
+
isExportable: false,
|
|
190
|
+
isIndexable: false,
|
|
191
|
+
}),
|
|
192
|
+
],
|
|
193
|
+
}),
|
|
194
|
+
)
|
|
194
195
|
},
|
|
195
196
|
}
|
|
196
197
|
})
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { URLPath } from '@internals/utils'
|
|
2
2
|
import type { OperationNode, ParameterNode } from '@kubb/ast/types'
|
|
3
|
+
import { FunctionParams } from '@kubb/core'
|
|
3
4
|
import type { PluginTs } from '@kubb/plugin-ts'
|
|
4
5
|
import type { PluginZod } from '@kubb/plugin-zod'
|
|
5
|
-
import { FunctionParams } from '@kubb/react-fabric'
|
|
6
6
|
import type { PluginClient } from './types.ts'
|
|
7
7
|
|
|
8
8
|
export function getComments(node: OperationNode): Array<string> {
|