@kubb/plugin-client 5.0.0-beta.30 → 5.0.0-beta.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/clients/fetch.cjs +60 -10
- package/dist/clients/fetch.cjs.map +1 -1
- package/dist/clients/fetch.js +60 -10
- package/dist/clients/fetch.js.map +1 -1
- package/dist/index.cjs +107 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +107 -56
- package/dist/index.js.map +1 -1
- package/dist/templates/clients/fetch.source.cjs +1 -1
- package/dist/templates/clients/fetch.source.js +1 -1
- package/extension.yaml +20 -46
- package/package.json +6 -6
- package/src/clients/fetch.ts +80 -7
- package/src/components/ClassClient.tsx +2 -1
- package/src/components/Client.tsx +6 -2
- package/src/components/Operations.tsx +2 -1
- package/src/components/StaticClassClient.tsx +2 -1
- package/src/components/Url.tsx +1 -0
- package/src/generators/classClientGenerator.tsx +13 -11
- package/src/generators/clientGenerator.tsx +14 -22
- package/src/generators/operationsGenerator.tsx +2 -2
- package/src/generators/staticClassClientGenerator.tsx +13 -11
- package/src/plugin.ts +4 -16
- package/src/types.ts +4 -3
- package/src/utils.ts +6 -4
package/src/types.ts
CHANGED
|
@@ -171,12 +171,13 @@ export type Options = {
|
|
|
171
171
|
paramsCasing?: 'camelcase'
|
|
172
172
|
/**
|
|
173
173
|
* Validator applied to response bodies before they are returned to the caller.
|
|
174
|
-
* - `
|
|
174
|
+
* - `false` (default) — no validation. The client has no runtime parser; the response is
|
|
175
|
+
* returned as-is, cast to the generated TypeScript type.
|
|
175
176
|
* - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
|
|
176
177
|
*
|
|
177
|
-
* @default
|
|
178
|
+
* @default false
|
|
178
179
|
*/
|
|
179
|
-
parser?:
|
|
180
|
+
parser?: false | 'zod'
|
|
180
181
|
/**
|
|
181
182
|
* Shape of the generated client.
|
|
182
183
|
* - `'function'` — one standalone async function per operation.
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getOperationParameters, resolveSuccessNames } from '@internals/shared'
|
|
1
|
+
import { getOperationParameters, getResponseType, resolveSuccessNames } from '@internals/shared'
|
|
2
2
|
import type { URLPath } from '@internals/utils'
|
|
3
|
-
import
|
|
3
|
+
import { ast } from '@kubb/core'
|
|
4
4
|
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
5
5
|
import type { ResolverZod } from '@kubb/plugin-zod'
|
|
6
6
|
import { createFunctionParams } from './functionParams.ts'
|
|
@@ -56,6 +56,7 @@ export function buildClassClientParams({
|
|
|
56
56
|
const { query: queryParams } = getOperationParameters(node)
|
|
57
57
|
const queryParamsName = queryParams.length > 0 ? tsResolver.resolveQueryParamsName(node, queryParams[0]!) : null
|
|
58
58
|
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null
|
|
59
|
+
const responseType = getResponseType(node)
|
|
59
60
|
|
|
60
61
|
return createFunctionParams({
|
|
61
62
|
config: {
|
|
@@ -65,7 +66,7 @@ export function buildClassClientParams({
|
|
|
65
66
|
mode: 'inlineSpread',
|
|
66
67
|
},
|
|
67
68
|
method: {
|
|
68
|
-
value: JSON.stringify(node.method.toUpperCase()),
|
|
69
|
+
value: JSON.stringify(ast.isHttpOperationNode(node) ? node.method.toUpperCase() : ''),
|
|
69
70
|
},
|
|
70
71
|
url: {
|
|
71
72
|
value: path.template,
|
|
@@ -87,6 +88,7 @@ export function buildClassClientParams({
|
|
|
87
88
|
}
|
|
88
89
|
: null,
|
|
89
90
|
contentType: isMultipleContentTypes ? {} : null,
|
|
91
|
+
responseType: responseType ? { value: JSON.stringify(responseType) } : null,
|
|
90
92
|
headers: headers.length
|
|
91
93
|
? {
|
|
92
94
|
value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,
|
|
@@ -150,7 +152,7 @@ export function buildReturnStatement({
|
|
|
150
152
|
if (dataReturnType === 'data' && parser === 'zod' && zodResponseName) {
|
|
151
153
|
return `return ${zodResponseName}.parse(res.data)`
|
|
152
154
|
}
|
|
153
|
-
if (dataReturnType === 'full' && parser
|
|
155
|
+
if (dataReturnType === 'full' && parser !== 'zod') {
|
|
154
156
|
return 'return res'
|
|
155
157
|
}
|
|
156
158
|
return 'return res.data'
|