@kubb/plugin-client 5.0.0-beta.42 → 5.0.0-beta.64
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/axios.cjs.map +1 -1
- package/dist/clients/axios.js.map +1 -1
- package/dist/clients/fetch.cjs.map +1 -1
- package/dist/clients/fetch.js.map +1 -1
- package/dist/index.cjs +439 -383
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +60 -25
- package/dist/index.js +435 -383
- package/dist/index.js.map +1 -1
- package/dist/templates/clients/axios.source.cjs.map +1 -1
- package/dist/templates/clients/axios.source.js.map +1 -1
- package/dist/templates/clients/fetch.source.cjs.map +1 -1
- package/dist/templates/clients/fetch.source.js.map +1 -1
- package/dist/templates/config.source.cjs.map +1 -1
- package/dist/templates/config.source.js.map +1 -1
- package/package.json +10 -18
- package/extension.yaml +0 -1267
- package/src/clients/axios.ts +0 -113
- package/src/clients/fetch.ts +0 -201
- package/src/components/ClassClient.tsx +0 -137
- package/src/components/Client.tsx +0 -273
- package/src/components/Operations.tsx +0 -29
- package/src/components/StaticClassClient.tsx +0 -129
- package/src/components/Url.tsx +0 -91
- package/src/components/WrapperClient.tsx +0 -33
- package/src/functionParams.ts +0 -118
- package/src/generators/classClientGenerator.tsx +0 -253
- package/src/generators/clientGenerator.tsx +0 -127
- package/src/generators/groupedClientGenerator.tsx +0 -82
- package/src/generators/operationsGenerator.tsx +0 -34
- package/src/generators/staticClassClientGenerator.tsx +0 -232
- package/src/index.ts +0 -9
- package/src/plugin.ts +0 -160
- package/src/resolvers/resolverClient.ts +0 -45
- package/src/templates/clients/axios.source.ts +0 -4
- package/src/templates/clients/fetch.source.ts +0 -4
- package/src/templates/config.source.ts +0 -4
- package/src/types.ts +0 -268
- package/src/utils.ts +0 -159
package/src/types.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
2
|
-
|
|
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
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Use either a preset `client` type OR a custom `importPath`, not both.
|
|
42
|
-
* `importPath` will override the default `client` preset when both are provided.
|
|
43
|
-
* These options are mutually exclusive. `bundle` and `importPath` are also
|
|
44
|
-
* mutually exclusive since `bundle` only has effect when `importPath` is not set.
|
|
45
|
-
*/
|
|
46
|
-
export type ClientImportPath =
|
|
47
|
-
| {
|
|
48
|
-
/**
|
|
49
|
-
* HTTP client used by the generated code.
|
|
50
|
-
* - `'axios'` — imports from `@kubb/plugin-client/clients/axios`. Requires `axios` at runtime.
|
|
51
|
-
* - `'fetch'` — imports from `@kubb/plugin-client/clients/fetch`. Uses the global `fetch`.
|
|
52
|
-
*
|
|
53
|
-
* @default 'axios'
|
|
54
|
-
*/
|
|
55
|
-
client?: 'axios' | 'fetch'
|
|
56
|
-
importPath?: never
|
|
57
|
-
}
|
|
58
|
-
| {
|
|
59
|
-
client?: never
|
|
60
|
-
/**
|
|
61
|
-
* Path to a custom client module. Generated files import their HTTP runtime from here
|
|
62
|
-
* instead of `@kubb/plugin-client/clients/{client}`. Accepts both relative paths and
|
|
63
|
-
* bare module specifiers; the value is used as-is.
|
|
64
|
-
*
|
|
65
|
-
* @note When combined with a query plugin, the module must export `Client`,
|
|
66
|
-
* `RequestConfig`, and `ResponseErrorConfig` types.
|
|
67
|
-
*/
|
|
68
|
-
importPath: string
|
|
69
|
-
/**
|
|
70
|
-
* `bundle` has no effect when `importPath` is set.
|
|
71
|
-
* Use either `bundle` (with `client`) or `importPath`, not both.
|
|
72
|
-
*/
|
|
73
|
-
bundle?: never
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Discriminated union that ties `pathParamsType` to the `paramsType` values where it is meaningful.
|
|
78
|
-
*
|
|
79
|
-
* - `paramsType: 'object'` — all parameters (including path params) are merged into a single
|
|
80
|
-
* destructured object. `pathParamsType` is never reached in this code path and has no effect.
|
|
81
|
-
* - `paramsType?: 'inline'` (or omitted) — each parameter group is a separate function argument.
|
|
82
|
-
* `pathParamsType` controls whether the path-param group itself is destructured (`'object'`)
|
|
83
|
-
* or spread as individual arguments (`'inline'`).
|
|
84
|
-
*/
|
|
85
|
-
type ParamsTypeOptions =
|
|
86
|
-
| {
|
|
87
|
-
/**
|
|
88
|
-
* Every operation parameter (path, query, headers, body) is wrapped in a single
|
|
89
|
-
* destructured object argument.
|
|
90
|
-
*/
|
|
91
|
-
paramsType: 'object'
|
|
92
|
-
/**
|
|
93
|
-
* `pathParamsType` has no effect when `paramsType` is `'object'`.
|
|
94
|
-
* Path params already live inside the single destructured object.
|
|
95
|
-
*/
|
|
96
|
-
pathParamsType?: never
|
|
97
|
-
}
|
|
98
|
-
| {
|
|
99
|
-
/**
|
|
100
|
-
* Each parameter group is emitted as a separate positional function argument.
|
|
101
|
-
*
|
|
102
|
-
* @default 'inline'
|
|
103
|
-
*/
|
|
104
|
-
paramsType?: 'inline'
|
|
105
|
-
/**
|
|
106
|
-
* How URL path parameters are arranged inside the inline argument list.
|
|
107
|
-
* - `'object'` groups them into one destructured object: `{ petId }: PathParams`.
|
|
108
|
-
* - `'inline'` emits each path param as its own argument: `petId: string`.
|
|
109
|
-
*
|
|
110
|
-
* @default 'inline'
|
|
111
|
-
*/
|
|
112
|
-
pathParamsType?: 'object' | 'inline'
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export type Options = {
|
|
116
|
-
/**
|
|
117
|
-
* Where the generated client files are written and how they are exported.
|
|
118
|
-
*
|
|
119
|
-
* @default { path: 'clients', barrel: { type: 'named' } }
|
|
120
|
-
*/
|
|
121
|
-
output?: Output
|
|
122
|
-
/**
|
|
123
|
-
* Split generated files into subfolders based on the operation's tag.
|
|
124
|
-
*/
|
|
125
|
-
group?: Group
|
|
126
|
-
/**
|
|
127
|
-
* Skip operations matching at least one entry in the list.
|
|
128
|
-
*/
|
|
129
|
-
exclude?: Array<Exclude>
|
|
130
|
-
/**
|
|
131
|
-
* Restrict generation to operations matching at least one entry in the list.
|
|
132
|
-
*/
|
|
133
|
-
include?: Array<Include>
|
|
134
|
-
/**
|
|
135
|
-
* Apply a different options object to operations matching a pattern.
|
|
136
|
-
*/
|
|
137
|
-
override?: Array<Override<ResolvedOptions>>
|
|
138
|
-
/**
|
|
139
|
-
* Emit an `operations.ts` file that re-exports every generated function grouped by HTTP method.
|
|
140
|
-
*
|
|
141
|
-
* @default false
|
|
142
|
-
*/
|
|
143
|
-
operations?: boolean
|
|
144
|
-
/**
|
|
145
|
-
* Whether to also export the URL builder helpers (`get<Operation>Url`).
|
|
146
|
-
* - `'export'` exposes them via the barrel.
|
|
147
|
-
* - `false` keeps them private.
|
|
148
|
-
*
|
|
149
|
-
* @default false
|
|
150
|
-
*/
|
|
151
|
-
urlType?: 'export' | false
|
|
152
|
-
/**
|
|
153
|
-
* Base URL prepended to every request. When omitted, falls back to the adapter's
|
|
154
|
-
* server URL (typically `servers[0].url`).
|
|
155
|
-
*/
|
|
156
|
-
baseURL?: string
|
|
157
|
-
/**
|
|
158
|
-
* Shape of the value returned by each generated client function.
|
|
159
|
-
* - `'data'` — only the response body.
|
|
160
|
-
* - `'full'` — the full response config (body, status, headers, request).
|
|
161
|
-
*
|
|
162
|
-
* @default 'data'
|
|
163
|
-
*/
|
|
164
|
-
dataReturnType?: 'data' | 'full'
|
|
165
|
-
/**
|
|
166
|
-
* Rename parameter properties in the generated client (path, query, headers).
|
|
167
|
-
* The HTTP request still uses the original spec names; Kubb writes the mapping for you.
|
|
168
|
-
*
|
|
169
|
-
* @note Use the same value on `@kubb/plugin-ts` so types stay compatible.
|
|
170
|
-
*/
|
|
171
|
-
paramsCasing?: 'camelcase'
|
|
172
|
-
/**
|
|
173
|
-
* Validator applied to response bodies before they are returned to the caller.
|
|
174
|
-
* - `false` (default) — no validation. The client has no runtime parser; the response is
|
|
175
|
-
* returned as-is, cast to the generated TypeScript type.
|
|
176
|
-
* - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
|
|
177
|
-
*
|
|
178
|
-
* @default false
|
|
179
|
-
*/
|
|
180
|
-
parser?: false | 'zod'
|
|
181
|
-
/**
|
|
182
|
-
* Shape of the generated client.
|
|
183
|
-
* - `'function'` — one standalone async function per operation.
|
|
184
|
-
* - `'class'` — one class per tag with instance methods.
|
|
185
|
-
* - `'staticClass'` — one class per tag with static methods.
|
|
186
|
-
*
|
|
187
|
-
* @default 'function'
|
|
188
|
-
* @note Only `'function'` is compatible with query plugins.
|
|
189
|
-
*/
|
|
190
|
-
clientType?: 'function' | 'class' | 'staticClass'
|
|
191
|
-
/**
|
|
192
|
-
* Copy the HTTP client runtime into the generated output so consumers do not need
|
|
193
|
-
* `@kubb/plugin-client` at runtime. When `false`, generated files import from
|
|
194
|
-
* `@kubb/plugin-client/clients/{client}`.
|
|
195
|
-
*
|
|
196
|
-
* @default false
|
|
197
|
-
*/
|
|
198
|
-
bundle?: boolean
|
|
199
|
-
/**
|
|
200
|
-
* Generate a single SDK class composing every tag-based client into one entry point.
|
|
201
|
-
* Automatically enables `clientType: 'class'`.
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```ts
|
|
205
|
-
* pluginClient({
|
|
206
|
-
* sdk: { className: 'PetStoreSDK' },
|
|
207
|
-
* })
|
|
208
|
-
* // class PetStoreSDK {
|
|
209
|
-
* // readonly petController: petController
|
|
210
|
-
* // readonly storeController: storeController
|
|
211
|
-
* // constructor(config = {}) { ... }
|
|
212
|
-
* // }
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
sdk?: {
|
|
216
|
-
/**
|
|
217
|
-
* Name of the generated SDK facade class. Also the file name.
|
|
218
|
-
*/
|
|
219
|
-
className: string
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Override how names and file paths are built for the generated client.
|
|
223
|
-
* Methods you omit fall back to the default resolver. `this` is bound to the
|
|
224
|
-
* full resolver, so `this.default(name)` delegates to the built-in implementation.
|
|
225
|
-
*/
|
|
226
|
-
resolver?: Partial<ResolverClient> & ThisType<ResolverClient>
|
|
227
|
-
/**
|
|
228
|
-
* AST visitor applied to each operation node before code is printed.
|
|
229
|
-
* Return `null` or `undefined` to leave the node unchanged.
|
|
230
|
-
*/
|
|
231
|
-
transformer?: ast.Visitor
|
|
232
|
-
/**
|
|
233
|
-
* Custom generators that run alongside the built-in client generators.
|
|
234
|
-
*/
|
|
235
|
-
generators?: Array<Generator<PluginClient>>
|
|
236
|
-
} & ClientImportPath &
|
|
237
|
-
ParamsTypeOptions
|
|
238
|
-
|
|
239
|
-
type ResolvedOptions = {
|
|
240
|
-
output: Output
|
|
241
|
-
exclude: Array<Exclude>
|
|
242
|
-
include: Array<Include> | undefined
|
|
243
|
-
override: Array<Override<ResolvedOptions>>
|
|
244
|
-
group: Group | null
|
|
245
|
-
client: Options['client']
|
|
246
|
-
clientType: NonNullable<Options['clientType']>
|
|
247
|
-
bundle: NonNullable<Options['bundle']>
|
|
248
|
-
parser: NonNullable<Options['parser']>
|
|
249
|
-
urlType: NonNullable<Options['urlType']>
|
|
250
|
-
importPath: Options['importPath']
|
|
251
|
-
baseURL: Options['baseURL']
|
|
252
|
-
dataReturnType: NonNullable<Options['dataReturnType']>
|
|
253
|
-
pathParamsType: NonNullable<NonNullable<Options['pathParamsType']>>
|
|
254
|
-
paramsType: NonNullable<Options['paramsType']>
|
|
255
|
-
paramsCasing: Options['paramsCasing']
|
|
256
|
-
sdk: Options['sdk']
|
|
257
|
-
resolver: ResolverClient
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, ResolverClient>
|
|
261
|
-
|
|
262
|
-
declare global {
|
|
263
|
-
namespace Kubb {
|
|
264
|
-
interface PluginRegistry {
|
|
265
|
-
'plugin-client': PluginClient
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { getOperationParameters, getResponseType, resolveSuccessNames } from '@internals/shared'
|
|
2
|
-
import type { URLPath } from '@internals/utils'
|
|
3
|
-
import { ast } from '@kubb/core'
|
|
4
|
-
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
5
|
-
import type { ResolverZod } from '@kubb/plugin-zod'
|
|
6
|
-
import { createFunctionParams } from './functionParams.ts'
|
|
7
|
-
import type { PluginClient } from './types.ts'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Builds HTTP headers array for a client request.
|
|
11
|
-
* Includes Content-Type (if not default) and spreads header parameters if present.
|
|
12
|
-
*/
|
|
13
|
-
export function buildHeaders(contentType: string, hasHeaderParams: boolean): Array<string> {
|
|
14
|
-
return [
|
|
15
|
-
contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : null,
|
|
16
|
-
hasHeaderParams ? '...headers' : null,
|
|
17
|
-
].filter(Boolean) as Array<string>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Builds TypeScript generic parameters for a client method.
|
|
22
|
-
* Includes response type, error type, and optional request type.
|
|
23
|
-
*/
|
|
24
|
-
export function buildGenerics(node: ast.OperationNode, tsResolver: ResolverTs): Array<string> {
|
|
25
|
-
const successNames = resolveSuccessNames(node, tsResolver)
|
|
26
|
-
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
27
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null
|
|
28
|
-
const errorNames = node.responses.filter((r) => Number.parseInt(r.statusCode, 10) >= 400).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode))
|
|
29
|
-
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
30
|
-
return [responseName, TError, requestName || 'unknown'].filter(Boolean)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Builds the parameters object for a class-based client method.
|
|
35
|
-
* Includes URL, method, base URL, headers, and request/response data.
|
|
36
|
-
*/
|
|
37
|
-
export function buildClassClientParams({
|
|
38
|
-
node,
|
|
39
|
-
path,
|
|
40
|
-
baseURL,
|
|
41
|
-
tsResolver,
|
|
42
|
-
isFormData,
|
|
43
|
-
isMultipleContentTypes,
|
|
44
|
-
hasFormData,
|
|
45
|
-
headers,
|
|
46
|
-
}: {
|
|
47
|
-
node: ast.OperationNode
|
|
48
|
-
path: URLPath
|
|
49
|
-
baseURL: string | null | undefined
|
|
50
|
-
tsResolver: ResolverTs
|
|
51
|
-
isFormData: boolean
|
|
52
|
-
isMultipleContentTypes: boolean
|
|
53
|
-
hasFormData: boolean
|
|
54
|
-
headers: Array<string>
|
|
55
|
-
}) {
|
|
56
|
-
const { query: queryParams } = getOperationParameters(node)
|
|
57
|
-
const queryParamsName = queryParams.length > 0 ? tsResolver.resolveQueryParamsName(node, queryParams[0]!) : null
|
|
58
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null
|
|
59
|
-
const responseType = getResponseType(node)
|
|
60
|
-
|
|
61
|
-
return createFunctionParams({
|
|
62
|
-
config: {
|
|
63
|
-
mode: 'object',
|
|
64
|
-
children: {
|
|
65
|
-
requestConfig: {
|
|
66
|
-
mode: 'inlineSpread',
|
|
67
|
-
},
|
|
68
|
-
method: {
|
|
69
|
-
value: JSON.stringify(ast.isHttpOperationNode(node) ? node.method.toUpperCase() : ''),
|
|
70
|
-
},
|
|
71
|
-
url: {
|
|
72
|
-
value: path.template,
|
|
73
|
-
},
|
|
74
|
-
baseURL: baseURL
|
|
75
|
-
? {
|
|
76
|
-
value: JSON.stringify(baseURL),
|
|
77
|
-
}
|
|
78
|
-
: null,
|
|
79
|
-
params: queryParamsName ? {} : null,
|
|
80
|
-
data: requestName
|
|
81
|
-
? {
|
|
82
|
-
value:
|
|
83
|
-
isMultipleContentTypes && hasFormData
|
|
84
|
-
? "contentType === 'multipart/form-data' ? formData as FormData : requestData"
|
|
85
|
-
: isFormData
|
|
86
|
-
? 'formData as FormData'
|
|
87
|
-
: 'requestData',
|
|
88
|
-
}
|
|
89
|
-
: null,
|
|
90
|
-
contentType: isMultipleContentTypes ? {} : null,
|
|
91
|
-
responseType: responseType ? { value: JSON.stringify(responseType) } : null,
|
|
92
|
-
headers: headers.length
|
|
93
|
-
? {
|
|
94
|
-
value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,
|
|
95
|
-
}
|
|
96
|
-
: null,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Builds the request data parsing line for client methods.
|
|
104
|
-
* Applies Zod validation if configured, otherwise uses data directly.
|
|
105
|
-
*/
|
|
106
|
-
export function buildRequestDataLine({
|
|
107
|
-
parser,
|
|
108
|
-
node,
|
|
109
|
-
zodResolver,
|
|
110
|
-
}: {
|
|
111
|
-
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
112
|
-
node: ast.OperationNode
|
|
113
|
-
zodResolver?: ResolverZod | null
|
|
114
|
-
}): string {
|
|
115
|
-
const zodRequestName = zodResolver && parser === 'zod' && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null
|
|
116
|
-
if (parser === 'zod' && zodRequestName) {
|
|
117
|
-
return `const requestData = ${zodRequestName}.parse(data)`
|
|
118
|
-
}
|
|
119
|
-
if (node.requestBody?.content?.[0]?.schema) {
|
|
120
|
-
return 'const requestData = data'
|
|
121
|
-
}
|
|
122
|
-
return ''
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Builds the form data conversion line for file upload requests.
|
|
127
|
-
* Returns empty string if not applicable.
|
|
128
|
-
*/
|
|
129
|
-
export function buildFormDataLine(isFormData: boolean, hasRequest: boolean): string {
|
|
130
|
-
return isFormData && hasRequest ? 'const formData = buildFormData(requestData)' : ''
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Builds the return statement for a client method.
|
|
135
|
-
* Applies Zod validation to response data if configured, otherwise returns raw response.
|
|
136
|
-
*/
|
|
137
|
-
export function buildReturnStatement({
|
|
138
|
-
dataReturnType,
|
|
139
|
-
parser,
|
|
140
|
-
node,
|
|
141
|
-
zodResolver,
|
|
142
|
-
}: {
|
|
143
|
-
dataReturnType: PluginClient['resolvedOptions']['dataReturnType']
|
|
144
|
-
parser: PluginClient['resolvedOptions']['parser'] | undefined
|
|
145
|
-
node: ast.OperationNode
|
|
146
|
-
zodResolver?: ResolverZod | null
|
|
147
|
-
}): string {
|
|
148
|
-
const zodResponseName = zodResolver && parser === 'zod' ? zodResolver.resolveResponseName?.(node) : null
|
|
149
|
-
if (dataReturnType === 'full' && parser === 'zod' && zodResponseName) {
|
|
150
|
-
return `return {...res, data: ${zodResponseName}.parse(res.data)}`
|
|
151
|
-
}
|
|
152
|
-
if (dataReturnType === 'data' && parser === 'zod' && zodResponseName) {
|
|
153
|
-
return `return ${zodResponseName}.parse(res.data)`
|
|
154
|
-
}
|
|
155
|
-
if (dataReturnType === 'full' && parser !== 'zod') {
|
|
156
|
-
return 'return res'
|
|
157
|
-
}
|
|
158
|
-
return 'return res.data'
|
|
159
|
-
}
|