@kubb/plugin-ts 5.0.0-alpha.10 → 5.0.0-alpha.12
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/{components-CRu8IKY3.js → Type-CX1HRooG.js} +377 -365
- package/dist/Type-CX1HRooG.js.map +1 -0
- package/dist/Type-Cat0_htq.cjs +808 -0
- package/dist/Type-Cat0_htq.cjs.map +1 -0
- package/dist/components.cjs +3 -2
- package/dist/components.d.ts +40 -9
- package/dist/components.js +2 -2
- package/dist/generators-CLuCmfUz.js +532 -0
- package/dist/generators-CLuCmfUz.js.map +1 -0
- package/dist/generators-DWBU-MuW.cjs +536 -0
- package/dist/generators-DWBU-MuW.cjs.map +1 -0
- package/dist/generators.cjs +2 -3
- package/dist/generators.d.ts +3 -503
- package/dist/generators.js +2 -2
- package/dist/index.cjs +308 -4
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +26 -21
- package/dist/index.js +305 -2
- package/dist/index.js.map +1 -0
- package/dist/{types-mSXmB8WU.d.ts → types-BA1ZCQ5p.d.ts} +73 -57
- package/package.json +5 -5
- package/src/components/{v2/Enum.tsx → Enum.tsx} +27 -11
- package/src/components/Type.tsx +23 -141
- package/src/components/index.ts +1 -0
- package/src/generators/index.ts +0 -1
- package/src/generators/typeGenerator.tsx +189 -413
- package/src/generators/utils.ts +298 -0
- package/src/index.ts +1 -1
- package/src/plugin.ts +81 -129
- package/src/printer.ts +15 -4
- package/src/resolverTs.ts +109 -1
- package/src/types.ts +68 -52
- package/dist/components-CRu8IKY3.js.map +0 -1
- package/dist/components-DeNDKlzf.cjs +0 -982
- package/dist/components-DeNDKlzf.cjs.map +0 -1
- package/dist/plugin-BZkBwnEA.js +0 -1269
- package/dist/plugin-BZkBwnEA.js.map +0 -1
- package/dist/plugin-Bunz1oGa.cjs +0 -1322
- package/dist/plugin-Bunz1oGa.cjs.map +0 -1
- package/src/components/v2/Type.tsx +0 -59
- package/src/generators/v2/typeGenerator.tsx +0 -167
- package/src/generators/v2/utils.ts +0 -140
- package/src/parser.ts +0 -389
|
@@ -1,466 +1,242 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import type { Operation } from '@kubb/oas'
|
|
6
|
-
import { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
7
|
-
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
8
|
-
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
|
|
9
|
-
import { applyParamsCasing, getBanner, getFooter, getImports, isParameterSchema } from '@kubb/plugin-oas/utils'
|
|
1
|
+
import { applyParamsCasing } from '@kubb/ast'
|
|
2
|
+
import type { SchemaNode } from '@kubb/ast/types'
|
|
3
|
+
import { defineGenerator } from '@kubb/core'
|
|
4
|
+
import { useKubb } from '@kubb/core/hooks'
|
|
10
5
|
import { File } from '@kubb/react-fabric'
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import * as factory from '../factory.ts'
|
|
14
|
-
import { createUrlTemplateType, getUnknownType, keywordTypeNodes } from '../factory.ts'
|
|
15
|
-
import { pluginTsName } from '../plugin.ts'
|
|
6
|
+
import { Type } from '../components/Type.tsx'
|
|
7
|
+
import { ENUM_TYPES_WITH_KEY_SUFFIX } from '../constants.ts'
|
|
16
8
|
import type { PluginTs } from '../types'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
31
|
-
}),
|
|
32
|
-
})!
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (schemas.request) {
|
|
36
|
-
const identifier = driver.resolveName({
|
|
37
|
-
name: schemas.request.name,
|
|
38
|
-
pluginName: pluginTsName,
|
|
39
|
-
type: 'function',
|
|
40
|
-
})
|
|
41
|
-
properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (schemas.pathParams) {
|
|
45
|
-
const identifier = driver.resolveName({
|
|
46
|
-
name: schemas.pathParams.name,
|
|
47
|
-
pluginName: pluginTsName,
|
|
48
|
-
type: 'function',
|
|
49
|
-
})
|
|
50
|
-
properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (schemas.queryParams) {
|
|
54
|
-
const identifier = driver.resolveName({
|
|
55
|
-
name: schemas.queryParams.name,
|
|
56
|
-
pluginName: pluginTsName,
|
|
57
|
-
type: 'function',
|
|
58
|
-
})
|
|
59
|
-
properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (schemas.headerParams) {
|
|
63
|
-
const identifier = driver.resolveName({
|
|
64
|
-
name: schemas.headerParams.name,
|
|
65
|
-
pluginName: pluginTsName,
|
|
66
|
-
type: 'function',
|
|
67
|
-
})
|
|
68
|
-
properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (schemas.errors) {
|
|
72
|
-
properties['errors'] = factory.createUnionDeclaration({
|
|
73
|
-
nodes: schemas.errors.map((error) => {
|
|
74
|
-
const identifier = driver.resolveName({
|
|
75
|
-
name: error.name,
|
|
76
|
-
pluginName: pluginTsName,
|
|
77
|
-
type: 'function',
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
81
|
-
}),
|
|
82
|
-
})!
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const namespaceNode = factory.createTypeAliasDeclaration({
|
|
86
|
-
name,
|
|
87
|
-
type: factory.createTypeLiteralNode(
|
|
88
|
-
Object.keys(properties)
|
|
89
|
-
.map((key) => {
|
|
90
|
-
const type = properties[key]
|
|
91
|
-
if (!type) {
|
|
92
|
-
return undefined
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return factory.createPropertySignature({
|
|
96
|
-
name: pascalCase(key),
|
|
97
|
-
type,
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
.filter(Boolean),
|
|
101
|
-
),
|
|
102
|
-
modifiers: [factory.modifiers.export],
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
return safePrint(namespaceNode)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function printRequestSchema({
|
|
109
|
-
baseName,
|
|
110
|
-
operation,
|
|
111
|
-
schemas,
|
|
112
|
-
driver,
|
|
113
|
-
}: {
|
|
114
|
-
baseName: string
|
|
115
|
-
operation: Operation
|
|
116
|
-
schemas: OperationSchemas
|
|
117
|
-
driver: PluginDriver
|
|
118
|
-
}): string {
|
|
119
|
-
const name = driver.resolveName({
|
|
120
|
-
name: `${baseName} Request`,
|
|
121
|
-
pluginName: pluginTsName,
|
|
122
|
-
type: 'type',
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
const results: string[] = []
|
|
126
|
-
|
|
127
|
-
// Generate DataRequest type
|
|
128
|
-
const dataRequestProperties: ts.PropertySignature[] = []
|
|
129
|
-
|
|
130
|
-
if (schemas.request) {
|
|
131
|
-
const identifier = driver.resolveName({
|
|
132
|
-
name: schemas.request.name,
|
|
133
|
-
pluginName: pluginTsName,
|
|
134
|
-
type: 'type',
|
|
135
|
-
})
|
|
136
|
-
dataRequestProperties.push(
|
|
137
|
-
factory.createPropertySignature({
|
|
138
|
-
name: 'data',
|
|
139
|
-
questionToken: true,
|
|
140
|
-
type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),
|
|
141
|
-
}),
|
|
142
|
-
)
|
|
143
|
-
} else {
|
|
144
|
-
dataRequestProperties.push(
|
|
145
|
-
factory.createPropertySignature({
|
|
146
|
-
name: 'data',
|
|
147
|
-
questionToken: true,
|
|
148
|
-
type: keywordTypeNodes.never,
|
|
149
|
-
}),
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Add pathParams property
|
|
154
|
-
if (schemas.pathParams) {
|
|
155
|
-
const identifier = driver.resolveName({
|
|
156
|
-
name: schemas.pathParams.name,
|
|
157
|
-
pluginName: pluginTsName,
|
|
158
|
-
type: 'type',
|
|
159
|
-
})
|
|
160
|
-
dataRequestProperties.push(
|
|
161
|
-
factory.createPropertySignature({
|
|
162
|
-
name: 'pathParams',
|
|
163
|
-
type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),
|
|
164
|
-
}),
|
|
165
|
-
)
|
|
166
|
-
} else {
|
|
167
|
-
dataRequestProperties.push(
|
|
168
|
-
factory.createPropertySignature({
|
|
169
|
-
name: 'pathParams',
|
|
170
|
-
questionToken: true,
|
|
171
|
-
type: keywordTypeNodes.never,
|
|
172
|
-
}),
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Add queryParams property
|
|
177
|
-
if (schemas.queryParams) {
|
|
178
|
-
const identifier = driver.resolveName({
|
|
179
|
-
name: schemas.queryParams.name,
|
|
180
|
-
pluginName: pluginTsName,
|
|
181
|
-
type: 'type',
|
|
182
|
-
})
|
|
183
|
-
dataRequestProperties.push(
|
|
184
|
-
factory.createPropertySignature({
|
|
185
|
-
name: 'queryParams',
|
|
186
|
-
questionToken: true,
|
|
187
|
-
type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),
|
|
188
|
-
}),
|
|
189
|
-
)
|
|
190
|
-
} else {
|
|
191
|
-
dataRequestProperties.push(
|
|
192
|
-
factory.createPropertySignature({
|
|
193
|
-
name: 'queryParams',
|
|
194
|
-
questionToken: true,
|
|
195
|
-
type: keywordTypeNodes.never,
|
|
196
|
-
}),
|
|
197
|
-
)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Add headerParams property
|
|
201
|
-
if (schemas.headerParams) {
|
|
202
|
-
const identifier = driver.resolveName({
|
|
203
|
-
name: schemas.headerParams.name,
|
|
204
|
-
pluginName: pluginTsName,
|
|
205
|
-
type: 'type',
|
|
206
|
-
})
|
|
207
|
-
dataRequestProperties.push(
|
|
208
|
-
factory.createPropertySignature({
|
|
209
|
-
name: 'headerParams',
|
|
210
|
-
questionToken: true,
|
|
211
|
-
type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),
|
|
212
|
-
}),
|
|
213
|
-
)
|
|
214
|
-
} else {
|
|
215
|
-
dataRequestProperties.push(
|
|
216
|
-
factory.createPropertySignature({
|
|
217
|
-
name: 'headerParams',
|
|
218
|
-
questionToken: true,
|
|
219
|
-
type: keywordTypeNodes.never,
|
|
220
|
-
}),
|
|
221
|
-
)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Add url property with template literal type
|
|
225
|
-
dataRequestProperties.push(
|
|
226
|
-
factory.createPropertySignature({
|
|
227
|
-
name: 'url',
|
|
228
|
-
type: createUrlTemplateType(operation.path),
|
|
229
|
-
}),
|
|
230
|
-
)
|
|
231
|
-
|
|
232
|
-
const dataRequestNode = factory.createTypeAliasDeclaration({
|
|
233
|
-
name,
|
|
234
|
-
type: factory.createTypeLiteralNode(dataRequestProperties),
|
|
235
|
-
modifiers: [factory.modifiers.export],
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
results.push(safePrint(dataRequestNode))
|
|
239
|
-
|
|
240
|
-
return results.join('\n\n')
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function printResponseSchema({
|
|
244
|
-
baseName,
|
|
245
|
-
schemas,
|
|
246
|
-
driver,
|
|
247
|
-
unknownType,
|
|
248
|
-
}: {
|
|
249
|
-
baseName: string
|
|
250
|
-
schemas: OperationSchemas
|
|
251
|
-
driver: PluginDriver
|
|
252
|
-
unknownType: PluginTs['resolvedOptions']['unknownType']
|
|
253
|
-
}): string {
|
|
254
|
-
const results: string[] = []
|
|
255
|
-
|
|
256
|
-
const name = driver.resolveName({
|
|
257
|
-
name: `${baseName} ResponseData`,
|
|
258
|
-
pluginName: pluginTsName,
|
|
259
|
-
type: 'type',
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
// Generate Responses type (mapping status codes to response types)
|
|
263
|
-
if (schemas.responses && schemas.responses.length > 0) {
|
|
264
|
-
const responsesProperties: ts.PropertySignature[] = schemas.responses.map((res) => {
|
|
265
|
-
const identifier = driver.resolveName({
|
|
266
|
-
name: res.name,
|
|
267
|
-
pluginName: pluginTsName,
|
|
268
|
-
type: 'type',
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
return factory.createPropertySignature({
|
|
272
|
-
name: res.statusCode?.toString() ?? 'default',
|
|
273
|
-
type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),
|
|
274
|
-
})
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
const responsesNode = factory.createTypeAliasDeclaration({
|
|
278
|
-
name: `${baseName}Responses`,
|
|
279
|
-
type: factory.createTypeLiteralNode(responsesProperties),
|
|
280
|
-
modifiers: [factory.modifiers.export],
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
results.push(safePrint(responsesNode))
|
|
284
|
-
|
|
285
|
-
// Generate Response type (union via indexed access)
|
|
286
|
-
const responseNode = factory.createTypeAliasDeclaration({
|
|
287
|
-
name,
|
|
288
|
-
type: factory.createIndexedAccessTypeNode(
|
|
289
|
-
factory.createTypeReferenceNode(factory.createIdentifier(`${baseName}Responses`), undefined),
|
|
290
|
-
factory.createTypeOperatorNode(
|
|
291
|
-
ts.SyntaxKind.KeyOfKeyword,
|
|
292
|
-
factory.createTypeReferenceNode(factory.createIdentifier(`${baseName}Responses`), undefined),
|
|
293
|
-
),
|
|
294
|
-
),
|
|
295
|
-
modifiers: [factory.modifiers.export],
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
results.push(safePrint(responseNode))
|
|
299
|
-
} else {
|
|
300
|
-
const responseNode = factory.createTypeAliasDeclaration({
|
|
301
|
-
name,
|
|
302
|
-
modifiers: [factory.modifiers.export],
|
|
303
|
-
type: getUnknownType(unknownType),
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
results.push(safePrint(responseNode))
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
return results.join('\n\n')
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export const typeGenerator = createReactGenerator<PluginTs>({
|
|
9
|
+
import {
|
|
10
|
+
buildDataSchemaNode,
|
|
11
|
+
buildGroupedParamsSchema,
|
|
12
|
+
buildLegacyResponsesSchemaNode,
|
|
13
|
+
buildLegacyResponseUnionSchemaNode,
|
|
14
|
+
buildResponsesSchemaNode,
|
|
15
|
+
buildResponseUnionSchemaNode,
|
|
16
|
+
nameUnnamedEnums,
|
|
17
|
+
} from './utils.ts'
|
|
18
|
+
|
|
19
|
+
export const typeGenerator = defineGenerator<PluginTs>({
|
|
313
20
|
name: 'typescript',
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const oas = useOas()
|
|
324
|
-
const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)
|
|
325
|
-
const schemaManager = useSchemaManager()
|
|
326
|
-
|
|
327
|
-
const name = getName(operation, { type: 'type', pluginName: pluginTsName })
|
|
328
|
-
|
|
329
|
-
const file = getFile(operation)
|
|
330
|
-
const schemas = getSchemas(operation)
|
|
331
|
-
const schemaGenerator = new SchemaGenerator(options, {
|
|
332
|
-
fabric: generator.context.fabric,
|
|
333
|
-
oas,
|
|
334
|
-
events: generator.context.events,
|
|
335
|
-
plugin,
|
|
336
|
-
driver,
|
|
21
|
+
type: 'react',
|
|
22
|
+
Operation({ node, adapter, options }) {
|
|
23
|
+
const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, resolver, legacy } = options
|
|
24
|
+
const { mode, getFile, resolveBanner, resolveFooter } = useKubb<PluginTs>()
|
|
25
|
+
|
|
26
|
+
const file = getFile({
|
|
27
|
+
name: node.operationId,
|
|
28
|
+
extname: '.ts',
|
|
337
29
|
mode,
|
|
338
|
-
|
|
30
|
+
options: {
|
|
31
|
+
group: group ? (group.type === 'tag' ? { tag: node.tags[0] ?? 'default' } : { path: node.path }) : undefined,
|
|
32
|
+
},
|
|
339
33
|
})
|
|
34
|
+
const params = applyParamsCasing(node.parameters, paramsCasing)
|
|
340
35
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
typedName: schemaManager.getName(name, { type: 'type' }),
|
|
357
|
-
file: schemaManager.getFile(options.operationName || name, { group }),
|
|
36
|
+
function renderSchemaType({
|
|
37
|
+
node: schemaNode,
|
|
38
|
+
name,
|
|
39
|
+
typedName,
|
|
40
|
+
description,
|
|
41
|
+
keysToOmit,
|
|
42
|
+
}: {
|
|
43
|
+
node: SchemaNode | null
|
|
44
|
+
name: string
|
|
45
|
+
typedName: string
|
|
46
|
+
description?: string
|
|
47
|
+
keysToOmit?: Array<string>
|
|
48
|
+
}) {
|
|
49
|
+
if (!schemaNode) {
|
|
50
|
+
return null
|
|
358
51
|
}
|
|
359
52
|
|
|
53
|
+
const imports = adapter.getImports(schemaNode, (schemaName) => ({
|
|
54
|
+
name: resolver.default(schemaName, 'type'),
|
|
55
|
+
path: getFile({ name: schemaName, extname: '.ts', mode }).path,
|
|
56
|
+
}))
|
|
57
|
+
|
|
360
58
|
return (
|
|
361
59
|
<>
|
|
362
60
|
{mode === 'split' &&
|
|
363
|
-
imports.map((imp) => (
|
|
364
|
-
<File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />
|
|
365
|
-
))}
|
|
61
|
+
imports.map((imp) => <File.Import key={[name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />)}
|
|
366
62
|
<Type
|
|
367
|
-
name={
|
|
368
|
-
typedName={
|
|
63
|
+
name={name}
|
|
64
|
+
typedName={typedName}
|
|
65
|
+
node={schemaNode}
|
|
369
66
|
description={description}
|
|
370
|
-
tree={tree}
|
|
371
|
-
schema={transformedSchema}
|
|
372
67
|
enumType={enumType}
|
|
373
68
|
enumKeyCasing={enumKeyCasing}
|
|
374
69
|
optionalType={optionalType}
|
|
375
70
|
arrayType={arrayType}
|
|
376
|
-
keysToOmit={keysToOmit}
|
|
377
71
|
syntaxType={syntaxType}
|
|
72
|
+
resolver={resolver}
|
|
73
|
+
keysToOmit={keysToOmit}
|
|
378
74
|
/>
|
|
379
75
|
</>
|
|
380
76
|
)
|
|
381
77
|
}
|
|
382
78
|
|
|
383
|
-
const
|
|
384
|
-
|
|
79
|
+
const responseTypes = legacy
|
|
80
|
+
? node.responses.map((res) => {
|
|
81
|
+
const responseName = resolver.resolveResponseStatusName(node, res.statusCode)
|
|
82
|
+
|
|
83
|
+
return renderSchemaType({
|
|
84
|
+
node: res.schema ? nameUnnamedEnums(res.schema, responseName) : res.schema,
|
|
85
|
+
name: responseName,
|
|
86
|
+
typedName: resolver.resolveResponseStatusTypedName(node, res.statusCode),
|
|
87
|
+
description: res.description,
|
|
88
|
+
keysToOmit: res.keysToOmit,
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
: node.responses.map((res) =>
|
|
92
|
+
renderSchemaType({
|
|
93
|
+
node: res.schema,
|
|
94
|
+
name: resolver.resolveResponseStatusName(node, res.statusCode),
|
|
95
|
+
typedName: resolver.resolveResponseStatusTypedName(node, res.statusCode),
|
|
96
|
+
description: res.description,
|
|
97
|
+
keysToOmit: res.keysToOmit,
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
const requestType = node.requestBody?.schema
|
|
102
|
+
? renderSchemaType({
|
|
103
|
+
node: legacy ? nameUnnamedEnums(node.requestBody.schema, resolver.resolveDataName(node)) : node.requestBody.schema,
|
|
104
|
+
name: resolver.resolveDataName(node),
|
|
105
|
+
typedName: resolver.resolveDataTypedName(node),
|
|
106
|
+
description: node.requestBody.schema.description,
|
|
107
|
+
keysToOmit: node.requestBody.keysToOmit,
|
|
108
|
+
})
|
|
109
|
+
: null
|
|
110
|
+
|
|
111
|
+
if (legacy) {
|
|
112
|
+
const pathParams = params.filter((p) => p.in === 'path')
|
|
113
|
+
const queryParams = params.filter((p) => p.in === 'query')
|
|
114
|
+
const headerParams = params.filter((p) => p.in === 'header')
|
|
115
|
+
|
|
116
|
+
const legacyParamTypes = [
|
|
117
|
+
pathParams.length > 0
|
|
118
|
+
? renderSchemaType({
|
|
119
|
+
node: buildGroupedParamsSchema({ params: pathParams, parentName: resolver.resolvePathParamsName!(node) }),
|
|
120
|
+
name: resolver.resolvePathParamsName!(node),
|
|
121
|
+
typedName: resolver.resolvePathParamsTypedName!(node),
|
|
122
|
+
})
|
|
123
|
+
: null,
|
|
124
|
+
queryParams.length > 0
|
|
125
|
+
? renderSchemaType({
|
|
126
|
+
node: buildGroupedParamsSchema({ params: queryParams, parentName: resolver.resolveQueryParamsName!(node) }),
|
|
127
|
+
name: resolver.resolveQueryParamsName!(node),
|
|
128
|
+
typedName: resolver.resolveQueryParamsTypedName!(node),
|
|
129
|
+
})
|
|
130
|
+
: null,
|
|
131
|
+
headerParams.length > 0
|
|
132
|
+
? renderSchemaType({
|
|
133
|
+
node: buildGroupedParamsSchema({ params: headerParams, parentName: resolver.resolveHeaderParamsName!(node) }),
|
|
134
|
+
name: resolver.resolveHeaderParamsName!(node),
|
|
135
|
+
typedName: resolver.resolveHeaderParamsTypedName!(node),
|
|
136
|
+
})
|
|
137
|
+
: null,
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
const legacyResponsesType = renderSchemaType({
|
|
141
|
+
node: buildLegacyResponsesSchemaNode({ node, resolver }),
|
|
142
|
+
name: resolver.resolveResponsesName(node),
|
|
143
|
+
typedName: resolver.resolveResponsesTypedName(node),
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
const legacyResponseType = renderSchemaType({
|
|
147
|
+
node: buildLegacyResponseUnionSchemaNode({ node, resolver }),
|
|
148
|
+
name: resolver.resolveResponseName(node),
|
|
149
|
+
typedName: resolver.resolveResponseTypedName(node),
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={resolveBanner()} footer={resolveFooter()}>
|
|
154
|
+
{legacyParamTypes}
|
|
155
|
+
{responseTypes}
|
|
156
|
+
{requestType}
|
|
157
|
+
{legacyResponsesType}
|
|
158
|
+
{legacyResponseType}
|
|
159
|
+
</File>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const paramTypes = params.map((param) =>
|
|
164
|
+
renderSchemaType({
|
|
165
|
+
node: param.schema,
|
|
166
|
+
name: resolver.resolveParamName(node, param),
|
|
167
|
+
typedName: resolver.resolveParamTypedName(node, param),
|
|
168
|
+
}),
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
const dataType = renderSchemaType({
|
|
172
|
+
node: buildDataSchemaNode({ node: { ...node, parameters: params }, resolver }),
|
|
173
|
+
name: resolver.resolveRequestConfigName(node),
|
|
174
|
+
typedName: resolver.resolveRequestConfigTypedName(node),
|
|
385
175
|
})
|
|
386
176
|
|
|
387
|
-
const
|
|
177
|
+
const responsesType = renderSchemaType({
|
|
178
|
+
node: buildResponsesSchemaNode({ node, resolver }),
|
|
179
|
+
name: resolver.resolveResponsesName(node),
|
|
180
|
+
typedName: resolver.resolveResponsesTypedName(node),
|
|
181
|
+
})
|
|
388
182
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
footer={getFooter({ oas, output: plugin.options.output })}
|
|
396
|
-
>
|
|
397
|
-
{operationSchemas.map(mapOperationSchema)}
|
|
183
|
+
const responseType = renderSchemaType({
|
|
184
|
+
node: buildResponseUnionSchemaNode({ node, resolver }),
|
|
185
|
+
name: resolver.resolveResponseName(node),
|
|
186
|
+
typedName: resolver.resolveResponseTypedName(node),
|
|
187
|
+
description: 'Union of all possible responses',
|
|
188
|
+
})
|
|
398
189
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
</>
|
|
408
|
-
) : (
|
|
409
|
-
<File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>
|
|
410
|
-
{printCombinedSchema({ name: combinedSchemaName, schemas, driver })}
|
|
411
|
-
</File.Source>
|
|
412
|
-
)}
|
|
190
|
+
return (
|
|
191
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={resolveBanner()} footer={resolveFooter()}>
|
|
192
|
+
{paramTypes}
|
|
193
|
+
{responseTypes}
|
|
194
|
+
{requestType}
|
|
195
|
+
{dataType}
|
|
196
|
+
{responsesType}
|
|
197
|
+
{responseType}
|
|
413
198
|
</File>
|
|
414
199
|
)
|
|
415
200
|
},
|
|
416
|
-
Schema({
|
|
417
|
-
const {
|
|
418
|
-
|
|
419
|
-
} = plugin
|
|
420
|
-
const mode = useMode()
|
|
201
|
+
Schema({ node, adapter, options }) {
|
|
202
|
+
const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, resolver } = options
|
|
203
|
+
const { mode, getFile, resolveBanner, resolveFooter } = useKubb<PluginTs>()
|
|
421
204
|
|
|
422
|
-
|
|
423
|
-
|
|
205
|
+
if (!node.name) {
|
|
206
|
+
return
|
|
207
|
+
}
|
|
424
208
|
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
209
|
+
const imports = adapter.getImports(node, (schemaName) => ({
|
|
210
|
+
name: resolver.default(schemaName, 'type'),
|
|
211
|
+
path: getFile({ name: schemaName, extname: '.ts', mode }).path,
|
|
212
|
+
}))
|
|
428
213
|
|
|
429
|
-
|
|
214
|
+
const isEnumSchema = node.type === 'enum'
|
|
430
215
|
|
|
431
|
-
|
|
432
|
-
typedName = typedName += 'Key' //Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)
|
|
433
|
-
}
|
|
216
|
+
const typedName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyTypedName(node) : resolver.resolveTypedName(node.name)
|
|
434
217
|
|
|
435
218
|
const type = {
|
|
436
|
-
name:
|
|
219
|
+
name: resolver.resolveName(node.name),
|
|
437
220
|
typedName,
|
|
438
|
-
file: getFile(
|
|
439
|
-
}
|
|
221
|
+
file: getFile({ name: node.name, extname: '.ts', mode }),
|
|
222
|
+
} as const
|
|
440
223
|
|
|
441
224
|
return (
|
|
442
|
-
<File
|
|
443
|
-
baseName={type.file.baseName}
|
|
444
|
-
path={type.file.path}
|
|
445
|
-
meta={type.file.meta}
|
|
446
|
-
banner={getBanner({ oas, output, config: driver.config })}
|
|
447
|
-
footer={getFooter({ oas, output })}
|
|
448
|
-
>
|
|
225
|
+
<File baseName={type.file.baseName} path={type.file.path} meta={type.file.meta} banner={resolveBanner()} footer={resolveFooter()}>
|
|
449
226
|
{mode === 'split' &&
|
|
450
227
|
imports.map((imp) => (
|
|
451
|
-
<File.Import key={[
|
|
228
|
+
<File.Import key={[node.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />
|
|
452
229
|
))}
|
|
453
230
|
<Type
|
|
454
231
|
name={type.name}
|
|
455
232
|
typedName={type.typedName}
|
|
456
|
-
|
|
457
|
-
tree={schema.tree}
|
|
458
|
-
schema={schema.value}
|
|
233
|
+
node={node}
|
|
459
234
|
enumType={enumType}
|
|
460
235
|
enumKeyCasing={enumKeyCasing}
|
|
461
236
|
optionalType={optionalType}
|
|
462
237
|
arrayType={arrayType}
|
|
463
238
|
syntaxType={syntaxType}
|
|
239
|
+
resolver={resolver}
|
|
464
240
|
/>
|
|
465
241
|
</File>
|
|
466
242
|
)
|