@kubb/plugin-ts 5.0.0-alpha.2 → 5.0.0-alpha.20
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/Type-B70QnSzH.cjs +688 -0
- package/dist/Type-B70QnSzH.cjs.map +1 -0
- package/dist/Type-CMC7L-38.js +671 -0
- package/dist/Type-CMC7L-38.js.map +1 -0
- package/dist/casing-Cp-jbC_k.js +84 -0
- package/dist/casing-Cp-jbC_k.js.map +1 -0
- package/dist/casing-D2uQKLWS.cjs +144 -0
- package/dist/casing-D2uQKLWS.cjs.map +1 -0
- package/dist/components.cjs +3 -2
- package/dist/components.d.ts +41 -11
- package/dist/components.js +2 -2
- package/dist/generators-BFkr7ecU.js +556 -0
- package/dist/generators-BFkr7ecU.js.map +1 -0
- package/dist/generators-xHWQCNd9.cjs +560 -0
- package/dist/generators-xHWQCNd9.cjs.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.d.ts +3 -491
- package/dist/generators.js +1 -1
- package/dist/index.cjs +146 -3
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +145 -1
- package/dist/index.js.map +1 -0
- package/dist/resolvers-DsKabI0F.js +184 -0
- package/dist/resolvers-DsKabI0F.js.map +1 -0
- package/dist/resolvers-YIpeP5YD.cjs +194 -0
- package/dist/resolvers-YIpeP5YD.cjs.map +1 -0
- package/dist/resolvers.cjs +4 -0
- package/dist/resolvers.d.ts +52 -0
- package/dist/resolvers.js +2 -0
- package/dist/types-zqLMbIqZ.d.ts +340 -0
- package/package.json +15 -8
- package/src/components/Enum.tsx +83 -0
- package/src/components/Type.tsx +25 -144
- package/src/components/index.ts +1 -0
- package/src/constants.ts +29 -0
- package/src/factory.ts +14 -16
- package/src/generators/typeGenerator.tsx +221 -414
- package/src/generators/utils.ts +308 -0
- package/src/index.ts +1 -1
- package/src/plugin.ts +74 -87
- package/src/presets.ts +23 -0
- package/src/printer.ts +256 -92
- package/src/resolvers/index.ts +2 -0
- package/src/resolvers/resolverTs.ts +104 -0
- package/src/resolvers/resolverTsLegacy.ts +87 -0
- package/src/types.ts +234 -63
- package/dist/components-9wydyqUx.cjs +0 -848
- package/dist/components-9wydyqUx.cjs.map +0 -1
- package/dist/components-LmqJfxMv.js +0 -721
- package/dist/components-LmqJfxMv.js.map +0 -1
- package/dist/plugin-CNkzbtpl.cjs +0 -508
- package/dist/plugin-CNkzbtpl.cjs.map +0 -1
- package/dist/plugin-DoLrDl9P.js +0 -476
- package/dist/plugin-DoLrDl9P.js.map +0 -1
- package/dist/types-BpeKGgCn.d.ts +0 -170
- package/src/parser.ts +0 -396
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { pascalCase } from '@internals/utils'
|
|
2
|
+
import { createProperty, createSchema, narrowSchema, transform } from '@kubb/ast'
|
|
3
|
+
import type { OperationNode, ParameterNode, SchemaNode } from '@kubb/ast/types'
|
|
4
|
+
import type { ResolverTs } from '../types.ts'
|
|
5
|
+
|
|
6
|
+
type BuildParamsSchemaOptions = {
|
|
7
|
+
params: Array<ParameterNode>
|
|
8
|
+
node: OperationNode
|
|
9
|
+
resolver: ResolverTs
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Builds an `ObjectSchemaNode` for a group of parameters (path/query/header).
|
|
14
|
+
* Each property is a `ref` schema pointing to the individually-resolved parameter type.
|
|
15
|
+
* The ref name includes the parameter location so generated type names follow
|
|
16
|
+
* the `<OperationId><Location><ParamName>` convention.
|
|
17
|
+
*/
|
|
18
|
+
export function buildParamsSchema({ params, node, resolver }: BuildParamsSchemaOptions): SchemaNode {
|
|
19
|
+
return createSchema({
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: params.map((param) =>
|
|
22
|
+
createProperty({
|
|
23
|
+
name: param.name,
|
|
24
|
+
required: param.required,
|
|
25
|
+
schema: createSchema({
|
|
26
|
+
type: 'ref',
|
|
27
|
+
name: resolver.resolveParamName(node, param),
|
|
28
|
+
}),
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type BuildOperationSchemaOptions = {
|
|
35
|
+
node: OperationNode
|
|
36
|
+
resolver: ResolverTs
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Builds an `ObjectSchemaNode` representing the `<OperationId>RequestConfig` type:
|
|
41
|
+
* - `data` → request body ref (optional) or `never`
|
|
42
|
+
* - `pathParams` → inline object of path param refs, or `never`
|
|
43
|
+
* - `queryParams` → inline object of query param refs (optional), or `never`
|
|
44
|
+
* - `headerParams` → inline object of header param refs (optional), or `never`
|
|
45
|
+
* - `url` → Express-style template literal (plugin-ts extension, handled by printer)
|
|
46
|
+
*/
|
|
47
|
+
export function buildDataSchemaNode({ node, resolver }: BuildOperationSchemaOptions): SchemaNode {
|
|
48
|
+
const pathParams = node.parameters.filter((p) => p.in === 'path')
|
|
49
|
+
const queryParams = node.parameters.filter((p) => p.in === 'query')
|
|
50
|
+
const headerParams = node.parameters.filter((p) => p.in === 'header')
|
|
51
|
+
|
|
52
|
+
return createSchema({
|
|
53
|
+
type: 'object',
|
|
54
|
+
deprecated: node.deprecated,
|
|
55
|
+
properties: [
|
|
56
|
+
createProperty({
|
|
57
|
+
name: 'data',
|
|
58
|
+
schema: node.requestBody?.schema
|
|
59
|
+
? createSchema({
|
|
60
|
+
type: 'ref',
|
|
61
|
+
name: resolver.resolveDataTypedName(node),
|
|
62
|
+
optional: true,
|
|
63
|
+
})
|
|
64
|
+
: createSchema({ type: 'never', optional: true }),
|
|
65
|
+
}),
|
|
66
|
+
createProperty({
|
|
67
|
+
name: 'pathParams',
|
|
68
|
+
required: pathParams.length > 0,
|
|
69
|
+
schema: pathParams.length > 0 ? buildParamsSchema({ params: pathParams, node, resolver }) : createSchema({ type: 'never' }),
|
|
70
|
+
}),
|
|
71
|
+
createProperty({
|
|
72
|
+
name: 'queryParams',
|
|
73
|
+
schema:
|
|
74
|
+
queryParams.length > 0
|
|
75
|
+
? createSchema({ ...buildParamsSchema({ params: queryParams, node, resolver }), optional: true })
|
|
76
|
+
: createSchema({ type: 'never', optional: true }),
|
|
77
|
+
}),
|
|
78
|
+
createProperty({
|
|
79
|
+
name: 'headerParams',
|
|
80
|
+
schema:
|
|
81
|
+
headerParams.length > 0
|
|
82
|
+
? createSchema({ ...buildParamsSchema({ params: headerParams, node, resolver }), optional: true })
|
|
83
|
+
: createSchema({ type: 'never', optional: true }),
|
|
84
|
+
}),
|
|
85
|
+
createProperty({
|
|
86
|
+
name: 'url',
|
|
87
|
+
required: true,
|
|
88
|
+
schema: createSchema({ type: 'url', path: node.path }),
|
|
89
|
+
}),
|
|
90
|
+
],
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Builds an `ObjectSchemaNode` representing `<OperationId>Responses` — keyed by HTTP status code.
|
|
96
|
+
* Numeric status codes produce unquoted numeric keys (e.g. `200:`).
|
|
97
|
+
* All responses are included; those without a schema are represented as a ref to a `never` type.
|
|
98
|
+
*/
|
|
99
|
+
export function buildResponsesSchemaNode({ node, resolver }: BuildOperationSchemaOptions): SchemaNode | null {
|
|
100
|
+
if (node.responses.length === 0) {
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return createSchema({
|
|
105
|
+
type: 'object',
|
|
106
|
+
properties: node.responses.map((res) =>
|
|
107
|
+
createProperty({
|
|
108
|
+
name: String(res.statusCode),
|
|
109
|
+
required: true,
|
|
110
|
+
schema: createSchema({
|
|
111
|
+
type: 'ref',
|
|
112
|
+
name: resolver.resolveResponseStatusTypedName(node, res.statusCode),
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
115
|
+
),
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Builds a `UnionSchemaNode` representing `<OperationId>Response` — all response types in union format.
|
|
121
|
+
* Returns `null` when the operation has no responses with schemas.
|
|
122
|
+
*/
|
|
123
|
+
export function buildResponseUnionSchemaNode({ node, resolver }: BuildOperationSchemaOptions): SchemaNode | null {
|
|
124
|
+
const responsesWithSchema = node.responses.filter((res) => res.schema)
|
|
125
|
+
|
|
126
|
+
if (responsesWithSchema.length === 0) {
|
|
127
|
+
return null
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return createSchema({
|
|
131
|
+
type: 'union',
|
|
132
|
+
members: responsesWithSchema.map((res) =>
|
|
133
|
+
createSchema({
|
|
134
|
+
type: 'ref',
|
|
135
|
+
name: resolver.resolveResponseStatusTypedName(node, res.statusCode),
|
|
136
|
+
}),
|
|
137
|
+
),
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
type BuildGroupedParamsSchemaOptions = {
|
|
142
|
+
params: Array<ParameterNode>
|
|
143
|
+
/**
|
|
144
|
+
* Parent type name (e.g. `FindPetsByStatusQueryParams`) used to derive enum names
|
|
145
|
+
* for inline enum properties (e.g. `FindPetsByStatusQueryParamsStatusEnum`).
|
|
146
|
+
*/
|
|
147
|
+
parentName?: string
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Builds an `ObjectSchemaNode` for a grouped parameters type (path/query/header) in legacy mode.
|
|
152
|
+
* Each property directly embeds the parameter's schema inline (not a ref).
|
|
153
|
+
* Used to generate `<OperationId>PathParams`, `<OperationId>QueryParams`, `<OperationId>HeaderParams`.
|
|
154
|
+
* @deprecated Legacy only — will be removed in v6.
|
|
155
|
+
*/
|
|
156
|
+
export function buildGroupedParamsSchema({ params, parentName }: BuildGroupedParamsSchemaOptions): SchemaNode {
|
|
157
|
+
return createSchema({
|
|
158
|
+
type: 'object',
|
|
159
|
+
properties: params.map((param) => {
|
|
160
|
+
let schema = param.schema
|
|
161
|
+
if (narrowSchema(schema, 'enum') && !schema.name && parentName) {
|
|
162
|
+
schema = { ...schema, name: pascalCase([parentName, param.name, 'enum'].join(' ')) }
|
|
163
|
+
}
|
|
164
|
+
return createProperty({
|
|
165
|
+
name: param.name,
|
|
166
|
+
required: param.required,
|
|
167
|
+
schema,
|
|
168
|
+
})
|
|
169
|
+
}),
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Builds the legacy wrapper `ObjectSchemaNode` for `<OperationId>Mutation` / `<OperationId>Query`.
|
|
175
|
+
* Structure: `{ Response, Request?, QueryParams?, PathParams?, HeaderParams?, Errors }`.
|
|
176
|
+
* Mirrors the v4 naming convention where this type acts as a namespace for the operation's shapes.
|
|
177
|
+
*
|
|
178
|
+
* @deprecated Legacy only — will be removed in v6.
|
|
179
|
+
*/
|
|
180
|
+
export function buildLegacyResponsesSchemaNode({ node, resolver }: BuildOperationSchemaOptions): SchemaNode | null {
|
|
181
|
+
const isGet = node.method.toLowerCase() === 'get'
|
|
182
|
+
const successResponses = node.responses.filter((res) => {
|
|
183
|
+
const code = Number(res.statusCode)
|
|
184
|
+
return !Number.isNaN(code) && code >= 200 && code < 300
|
|
185
|
+
})
|
|
186
|
+
const errorResponses = node.responses.filter((res) => res.statusCode === 'default' || Number(res.statusCode) >= 400)
|
|
187
|
+
|
|
188
|
+
const responseSchema =
|
|
189
|
+
successResponses.length > 0
|
|
190
|
+
? successResponses.length === 1
|
|
191
|
+
? createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, successResponses[0]!.statusCode) })
|
|
192
|
+
: createSchema({
|
|
193
|
+
type: 'union',
|
|
194
|
+
members: successResponses.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, res.statusCode) })),
|
|
195
|
+
})
|
|
196
|
+
: createSchema({ type: 'any' })
|
|
197
|
+
|
|
198
|
+
const errorsSchema =
|
|
199
|
+
errorResponses.length > 0
|
|
200
|
+
? errorResponses.length === 1
|
|
201
|
+
? createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, errorResponses[0]!.statusCode) })
|
|
202
|
+
: createSchema({
|
|
203
|
+
type: 'union',
|
|
204
|
+
members: errorResponses.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, res.statusCode) })),
|
|
205
|
+
})
|
|
206
|
+
: createSchema({ type: 'any' })
|
|
207
|
+
|
|
208
|
+
const properties = [createProperty({ name: 'Response', required: true, schema: responseSchema })]
|
|
209
|
+
|
|
210
|
+
if (!isGet && node.requestBody?.schema) {
|
|
211
|
+
properties.push(
|
|
212
|
+
createProperty({
|
|
213
|
+
name: 'Request',
|
|
214
|
+
required: true,
|
|
215
|
+
schema: createSchema({ type: 'ref', name: resolver.resolveDataTypedName(node) }),
|
|
216
|
+
}),
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (node.parameters.some((p) => p.in === 'query') && resolver.resolveQueryParamsTypedName) {
|
|
221
|
+
properties.push(
|
|
222
|
+
createProperty({
|
|
223
|
+
name: 'QueryParams',
|
|
224
|
+
required: true,
|
|
225
|
+
schema: createSchema({ type: 'ref', name: resolver.resolveQueryParamsTypedName(node) }),
|
|
226
|
+
}),
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (node.parameters.some((p) => p.in === 'path') && resolver.resolvePathParamsTypedName) {
|
|
231
|
+
properties.push(
|
|
232
|
+
createProperty({
|
|
233
|
+
name: 'PathParams',
|
|
234
|
+
required: true,
|
|
235
|
+
schema: createSchema({ type: 'ref', name: resolver.resolvePathParamsTypedName(node) }),
|
|
236
|
+
}),
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (node.parameters.some((p) => p.in === 'header') && resolver.resolveHeaderParamsTypedName) {
|
|
241
|
+
properties.push(
|
|
242
|
+
createProperty({
|
|
243
|
+
name: 'HeaderParams',
|
|
244
|
+
required: true,
|
|
245
|
+
schema: createSchema({ type: 'ref', name: resolver.resolveHeaderParamsTypedName(node) }),
|
|
246
|
+
}),
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
properties.push(createProperty({ name: 'Errors', required: true, schema: errorsSchema }))
|
|
251
|
+
|
|
252
|
+
return createSchema({ type: 'object', properties })
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Builds the legacy response union for `<OperationId>MutationResponse` / `<OperationId>QueryResponse`.
|
|
257
|
+
* In legacy mode this is the **success** response only (not the full union including errors).
|
|
258
|
+
* Returns an `any` schema when there is no success response, matching v4 behavior.
|
|
259
|
+
* @deprecated Legacy only — will be removed in v6.
|
|
260
|
+
*/
|
|
261
|
+
export function buildLegacyResponseUnionSchemaNode({ node, resolver }: BuildOperationSchemaOptions): SchemaNode {
|
|
262
|
+
const successResponses = node.responses.filter((res) => {
|
|
263
|
+
const code = Number(res.statusCode)
|
|
264
|
+
return !Number.isNaN(code) && code >= 200 && code < 300
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
if (successResponses.length === 0) {
|
|
268
|
+
return createSchema({ type: 'any' })
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (successResponses.length === 1) {
|
|
272
|
+
return createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, successResponses[0]!.statusCode) })
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return createSchema({
|
|
276
|
+
type: 'union',
|
|
277
|
+
members: successResponses.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, res.statusCode) })),
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Names unnamed enum nodes within a schema tree based on the parent type name.
|
|
283
|
+
* Used in legacy mode to ensure inline enums in response/request schemas get
|
|
284
|
+
* extracted as named enum declarations (e.g. `DeletePet200Enum`).
|
|
285
|
+
*
|
|
286
|
+
* @deprecated Legacy only — will be removed in v6.
|
|
287
|
+
*/
|
|
288
|
+
export function nameUnnamedEnums(node: SchemaNode, parentName: string): SchemaNode {
|
|
289
|
+
return transform(node, {
|
|
290
|
+
schema(n) {
|
|
291
|
+
const enumNode = narrowSchema(n, 'enum')
|
|
292
|
+
if (enumNode && !enumNode.name) {
|
|
293
|
+
return { ...enumNode, name: pascalCase([parentName, 'enum'].join(' ')) }
|
|
294
|
+
}
|
|
295
|
+
return undefined
|
|
296
|
+
},
|
|
297
|
+
property(p) {
|
|
298
|
+
const enumNode = narrowSchema(p.schema, 'enum')
|
|
299
|
+
if (enumNode && !enumNode.name) {
|
|
300
|
+
return {
|
|
301
|
+
...p,
|
|
302
|
+
schema: { ...enumNode, name: pascalCase([parentName, p.name, 'enum'].join(' ')) },
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return undefined
|
|
306
|
+
},
|
|
307
|
+
})
|
|
308
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { pluginTs, pluginTsName } from './plugin.ts'
|
|
2
|
-
export type { PluginTs } from './types.ts'
|
|
2
|
+
export type { PluginTs, ResolverTs } from './types.ts'
|
package/src/plugin.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { camelCase
|
|
2
|
+
import { camelCase } from '@internals/utils'
|
|
3
3
|
import { walk } from '@kubb/ast'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { createPlugin, type Group, getBarrelFiles, getMode, renderOperation, renderSchema } from '@kubb/core'
|
|
5
|
+
import { typeGenerator } from './generators/index.ts'
|
|
6
|
+
import { getPreset } from './presets.ts'
|
|
7
7
|
import type { PluginTs } from './types.ts'
|
|
8
8
|
|
|
9
9
|
export const pluginTsName = 'plugin-ts' satisfies PluginTs['name']
|
|
10
10
|
|
|
11
|
-
export const pluginTs =
|
|
11
|
+
export const pluginTs = createPlugin<PluginTs>((options) => {
|
|
12
12
|
const {
|
|
13
13
|
output = { path: 'types', barrelType: 'named' },
|
|
14
14
|
group,
|
|
@@ -17,47 +17,40 @@ export const pluginTs = definePlugin<PluginTs>((options) => {
|
|
|
17
17
|
override = [],
|
|
18
18
|
enumType = 'asConst',
|
|
19
19
|
enumKeyCasing = 'none',
|
|
20
|
-
enumSuffix = 'enum',
|
|
21
|
-
dateType = 'string',
|
|
22
|
-
integerType = 'number',
|
|
23
|
-
unknownType = 'any',
|
|
24
20
|
optionalType = 'questionToken',
|
|
25
21
|
arrayType = 'array',
|
|
26
|
-
emptySchemaType = unknownType,
|
|
27
22
|
syntaxType = 'type',
|
|
28
|
-
transformers = {},
|
|
29
|
-
mapper = {},
|
|
30
23
|
paramsCasing,
|
|
31
24
|
generators = [typeGenerator].filter(Boolean),
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
compatibilityPreset = 'default',
|
|
26
|
+
resolvers: userResolvers,
|
|
27
|
+
transformers: userTransformers = [],
|
|
34
28
|
} = options
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
const { baseResolver, resolver, transformers } = getPreset(compatibilityPreset, {
|
|
31
|
+
resolvers: userResolvers,
|
|
32
|
+
transformers: userTransformers,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
let resolveNameWarning = false
|
|
38
36
|
|
|
39
37
|
return {
|
|
40
38
|
name: pluginTsName,
|
|
41
39
|
options: {
|
|
42
40
|
output,
|
|
43
|
-
transformers,
|
|
44
|
-
dateType,
|
|
45
|
-
integerType,
|
|
46
41
|
optionalType,
|
|
47
42
|
arrayType,
|
|
48
43
|
enumType,
|
|
49
44
|
enumKeyCasing,
|
|
50
|
-
enumSuffix,
|
|
51
|
-
unknownType,
|
|
52
|
-
emptySchemaType,
|
|
53
45
|
syntaxType,
|
|
54
46
|
group,
|
|
55
47
|
override,
|
|
56
|
-
mapper,
|
|
57
48
|
paramsCasing,
|
|
58
|
-
|
|
49
|
+
compatibilityPreset,
|
|
50
|
+
baseResolver,
|
|
51
|
+
resolver,
|
|
52
|
+
transformers,
|
|
59
53
|
},
|
|
60
|
-
pre: [pluginOasName],
|
|
61
54
|
resolvePath(baseName, pathMode, options) {
|
|
62
55
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
63
56
|
const mode = pathMode ?? getMode(path.resolve(root, output.path))
|
|
@@ -93,83 +86,77 @@ export const pluginTs = definePlugin<PluginTs>((options) => {
|
|
|
93
86
|
return path.resolve(root, output.path, baseName)
|
|
94
87
|
},
|
|
95
88
|
resolveName(name, type) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return transformers?.name?.(resolvedName, type) || resolvedName
|
|
89
|
+
if (!resolveNameWarning) {
|
|
90
|
+
this.driver.events.emit('warn', 'Do not use resolveName for pluginTs, use resolverTs instead')
|
|
91
|
+
resolveNameWarning = true
|
|
100
92
|
}
|
|
101
93
|
|
|
102
|
-
return
|
|
94
|
+
return resolver.default(name, type)
|
|
103
95
|
},
|
|
104
96
|
async install() {
|
|
105
|
-
const { config, fabric, plugin } = this
|
|
97
|
+
const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this
|
|
106
98
|
|
|
107
99
|
const root = path.resolve(config.root, config.output.path)
|
|
108
100
|
const mode = getMode(path.resolve(root, output.path))
|
|
109
101
|
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
102
|
+
if (!adapter) {
|
|
103
|
+
throw new Error('Plugin cannot work without adapter being set')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
await openInStudio({ ast: true })
|
|
107
|
+
|
|
108
|
+
await walk(rootNode, {
|
|
109
|
+
depth: 'shallow',
|
|
110
|
+
async schema(schemaNode) {
|
|
111
|
+
const writeTasks = generators.map(async (generator) => {
|
|
112
|
+
if (generator.type === 'react' && generator.version === '2') {
|
|
113
|
+
const options = resolver.resolveOptions(schemaNode, { options: plugin.options, exclude, include, override })
|
|
114
|
+
|
|
115
|
+
if (options === null) {
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
await renderSchema(schemaNode, {
|
|
120
|
+
options,
|
|
121
|
+
adapter,
|
|
122
|
+
config,
|
|
123
|
+
fabric,
|
|
124
|
+
Component: generator.Schema,
|
|
125
|
+
plugin,
|
|
126
|
+
driver,
|
|
127
|
+
mode,
|
|
127
128
|
})
|
|
129
|
+
}
|
|
130
|
+
})
|
|
128
131
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
await Promise.all(writeTasks)
|
|
133
|
+
},
|
|
134
|
+
async operation(operationNode) {
|
|
135
|
+
const writeTasks = generators.map(async (generator) => {
|
|
136
|
+
if (generator.type === 'react' && generator.version === '2') {
|
|
137
|
+
const options = resolver.resolveOptions(operationNode, { options: plugin.options, exclude, include, override })
|
|
134
138
|
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
if (options === null) {
|
|
140
|
+
return
|
|
141
|
+
}
|
|
137
142
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
output: output.path,
|
|
151
|
-
})
|
|
143
|
+
await renderOperation(operationNode, {
|
|
144
|
+
options,
|
|
145
|
+
adapter,
|
|
146
|
+
config,
|
|
147
|
+
fabric,
|
|
148
|
+
Component: generator.Operation,
|
|
149
|
+
plugin,
|
|
150
|
+
driver,
|
|
151
|
+
mode,
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
})
|
|
152
155
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
157
|
-
fabric: this.fabric,
|
|
158
|
-
oas,
|
|
159
|
-
pluginManager: this.pluginManager,
|
|
160
|
-
events: this.events,
|
|
161
|
-
plugin: this.plugin,
|
|
162
|
-
contentType,
|
|
163
|
-
exclude,
|
|
164
|
-
include,
|
|
165
|
-
override,
|
|
166
|
-
mode,
|
|
167
|
-
UNSTABLE_NAMING,
|
|
156
|
+
await Promise.all(writeTasks)
|
|
157
|
+
},
|
|
168
158
|
})
|
|
169
159
|
|
|
170
|
-
const operationFiles = await operationGenerator.build(...generators)
|
|
171
|
-
await this.upsertFile(...operationFiles)
|
|
172
|
-
|
|
173
160
|
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
174
161
|
type: output.barrelType ?? 'named',
|
|
175
162
|
root,
|
package/src/presets.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Visitor } from '@kubb/ast/types'
|
|
2
|
+
import { type CompatibilityPreset, definePreset, definePresets, getPreset as getCorePreset } from '@kubb/core'
|
|
3
|
+
import { resolverTs, resolverTsLegacy } from './resolvers/index.ts'
|
|
4
|
+
import type { ResolverTs } from './types.ts'
|
|
5
|
+
|
|
6
|
+
export const presets = definePresets<ResolverTs>({
|
|
7
|
+
default: definePreset('default', { resolvers: [resolverTs] }),
|
|
8
|
+
kubbV4: definePreset('kubbV4', { resolvers: [resolverTsLegacy] }),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
type GetPresetOptions = {
|
|
12
|
+
resolvers?: Array<ResolverTs>
|
|
13
|
+
transformers?: Array<Visitor>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getPreset(preset: CompatibilityPreset, { resolvers, transformers }: GetPresetOptions = {}) {
|
|
17
|
+
return getCorePreset({
|
|
18
|
+
preset,
|
|
19
|
+
presets,
|
|
20
|
+
resolvers: [resolverTs, ...(resolvers ?? [])],
|
|
21
|
+
transformers,
|
|
22
|
+
})
|
|
23
|
+
}
|