@kubb/plugin-ts 5.0.0-alpha.3 → 5.0.0-alpha.30
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 +1806 -3
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +590 -4
- package/dist/index.js +1776 -2
- package/dist/index.js.map +1 -0
- package/package.json +7 -27
- package/src/components/Enum.tsx +82 -0
- package/src/components/Type.tsx +29 -162
- package/src/constants.ts +39 -0
- package/src/factory.ts +134 -49
- package/src/generators/typeGenerator.tsx +165 -428
- package/src/generators/typeGeneratorLegacy.tsx +349 -0
- package/src/index.ts +9 -1
- package/src/plugin.ts +98 -176
- package/src/presets.ts +28 -0
- package/src/printers/functionPrinter.ts +196 -0
- package/src/printers/printerTs.ts +310 -0
- package/src/resolvers/resolverTs.ts +66 -0
- package/src/resolvers/resolverTsLegacy.ts +60 -0
- package/src/types.ts +258 -98
- package/src/utils.ts +131 -0
- package/dist/components-CRjwjdyE.js +0 -725
- package/dist/components-CRjwjdyE.js.map +0 -1
- package/dist/components-DI0aTIBg.cjs +0 -978
- package/dist/components-DI0aTIBg.cjs.map +0 -1
- package/dist/components.cjs +0 -3
- package/dist/components.d.ts +0 -38
- package/dist/components.js +0 -2
- package/dist/generators.cjs +0 -4
- package/dist/generators.d.ts +0 -503
- package/dist/generators.js +0 -2
- package/dist/plugin-D5rCK1zO.cjs +0 -992
- package/dist/plugin-D5rCK1zO.cjs.map +0 -1
- package/dist/plugin-DmwgRHK8.js +0 -944
- package/dist/plugin-DmwgRHK8.js.map +0 -1
- package/dist/types-BpeKGgCn.d.ts +0 -170
- package/src/components/index.ts +0 -1
- package/src/components/v2/Type.tsx +0 -165
- package/src/generators/index.ts +0 -2
- package/src/generators/v2/typeGenerator.tsx +0 -196
- package/src/parser.ts +0 -396
- package/src/printer.ts +0 -244
|
@@ -1,470 +1,207 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import { safePrint } from '@kubb/fabric-core/parsers/typescript'
|
|
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 { caseParams, narrowSchema, schemaTypes } from '@kubb/ast'
|
|
2
|
+
import type { SchemaNode } from '@kubb/ast/types'
|
|
3
|
+
import { defineGenerator } from '@kubb/core'
|
|
10
4
|
import { File } from '@kubb/react-fabric'
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import { createUrlTemplateType, getUnknownType, keywordTypeNodes } from '../factory.ts'
|
|
15
|
-
import { pluginTsName } from '../plugin.ts'
|
|
5
|
+
import { Type } from '../components/Type.tsx'
|
|
6
|
+
import { ENUM_TYPES_WITH_KEY_SUFFIX } from '../constants.ts'
|
|
7
|
+
import { printerTs } from '../printers/printerTs.ts'
|
|
16
8
|
import type { PluginTs } from '../types'
|
|
9
|
+
import { buildData, buildResponses, buildResponseUnion } from '../utils.ts'
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
nodes: schemas.responses.map((res) => {
|
|
24
|
-
const identifier = pluginManager.resolveName({
|
|
25
|
-
name: res.name,
|
|
26
|
-
pluginName: pluginTsName,
|
|
27
|
-
type: 'function',
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
31
|
-
}),
|
|
32
|
-
})!
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (schemas.request) {
|
|
36
|
-
const identifier = pluginManager.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 = pluginManager.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 = pluginManager.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 = pluginManager.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 = pluginManager.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
|
-
pluginManager,
|
|
113
|
-
}: {
|
|
114
|
-
baseName: string
|
|
115
|
-
operation: Operation
|
|
116
|
-
schemas: OperationSchemas
|
|
117
|
-
pluginManager: PluginManager
|
|
118
|
-
}): string {
|
|
119
|
-
const name = pluginManager.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 = pluginManager.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
|
-
}
|
|
11
|
+
export const typeGenerator = defineGenerator<PluginTs>({
|
|
12
|
+
name: 'typescript',
|
|
13
|
+
schema(node, options) {
|
|
14
|
+
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group, printer } = options
|
|
15
|
+
const { adapter, config, resolver, root } = this
|
|
152
16
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
dataRequestProperties.push(
|
|
168
|
-
factory.createPropertySignature({
|
|
169
|
-
name: 'pathParams',
|
|
170
|
-
questionToken: true,
|
|
171
|
-
type: keywordTypeNodes.never,
|
|
172
|
-
}),
|
|
173
|
-
)
|
|
174
|
-
}
|
|
17
|
+
if (!node.name) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
const mode = this.getMode(output)
|
|
21
|
+
// Build a set of schema names that are enums so the ref handler and getImports
|
|
22
|
+
// callback can use the suffixed type name (e.g. `StatusKey`) for those refs.
|
|
23
|
+
const enumSchemaNames = new Set((adapter.rootNode?.schemas ?? []).filter((s) => narrowSchema(s, schemaTypes.enum) && s.name).map((s) => s.name!))
|
|
24
|
+
|
|
25
|
+
function resolveImportName(schemaName: string): string {
|
|
26
|
+
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) {
|
|
27
|
+
return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix)
|
|
28
|
+
}
|
|
29
|
+
return resolver.resolveTypeName(schemaName)
|
|
30
|
+
}
|
|
175
31
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
32
|
+
const imports = adapter.getImports(node, (schemaName) => ({
|
|
33
|
+
name: resolveImportName(schemaName),
|
|
34
|
+
path: resolver.resolveFile({ name: schemaName, extname: '.ts' }, { root, output, group }).path,
|
|
35
|
+
}))
|
|
36
|
+
|
|
37
|
+
const isEnumSchema = !!narrowSchema(node, schemaTypes.enum)
|
|
38
|
+
|
|
39
|
+
const meta = {
|
|
40
|
+
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(node, enumTypeSuffix) : resolver.resolveTypeName(node.name),
|
|
41
|
+
file: resolver.resolveFile({ name: node.name, extname: '.ts' }, { root, output, group }),
|
|
42
|
+
} as const
|
|
43
|
+
|
|
44
|
+
const schemaPrinter = printerTs({
|
|
45
|
+
optionalType,
|
|
46
|
+
arrayType,
|
|
47
|
+
enumType,
|
|
48
|
+
enumTypeSuffix,
|
|
49
|
+
name: meta.name,
|
|
50
|
+
syntaxType,
|
|
51
|
+
description: node.description,
|
|
52
|
+
resolver,
|
|
53
|
+
enumSchemaNames,
|
|
54
|
+
nodes: printer?.nodes,
|
|
182
55
|
})
|
|
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
56
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
57
|
+
return (
|
|
58
|
+
<File
|
|
59
|
+
baseName={meta.file.baseName}
|
|
60
|
+
path={meta.file.path}
|
|
61
|
+
meta={meta.file.meta}
|
|
62
|
+
banner={resolver.resolveBanner(adapter.rootNode, { output, config })}
|
|
63
|
+
footer={resolver.resolveFooter(adapter.rootNode, { output, config })}
|
|
64
|
+
>
|
|
65
|
+
{mode === 'split' &&
|
|
66
|
+
imports.map((imp) => (
|
|
67
|
+
<File.Import key={[node.name, imp.path, imp.isTypeOnly].join('-')} root={meta.file.path} path={imp.path} name={imp.name} isTypeOnly />
|
|
68
|
+
))}
|
|
69
|
+
<Type
|
|
70
|
+
name={meta.name}
|
|
71
|
+
node={node}
|
|
72
|
+
enumType={enumType}
|
|
73
|
+
enumTypeSuffix={enumTypeSuffix}
|
|
74
|
+
enumKeyCasing={enumKeyCasing}
|
|
75
|
+
resolver={resolver}
|
|
76
|
+
printer={schemaPrinter}
|
|
77
|
+
/>
|
|
78
|
+
</File>
|
|
221
79
|
)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
})
|
|
80
|
+
},
|
|
81
|
+
operation(node, options) {
|
|
82
|
+
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output, printer } = options
|
|
83
|
+
const { adapter, config, resolver, root } = this
|
|
237
84
|
|
|
238
|
-
|
|
85
|
+
const mode = this.getMode(output)
|
|
239
86
|
|
|
240
|
-
|
|
241
|
-
}
|
|
87
|
+
const params = caseParams(node.parameters, paramsCasing)
|
|
242
88
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
pluginManager,
|
|
247
|
-
unknownType,
|
|
248
|
-
}: {
|
|
249
|
-
baseName: string
|
|
250
|
-
schemas: OperationSchemas
|
|
251
|
-
pluginManager: PluginManager
|
|
252
|
-
unknownType: PluginTs['resolvedOptions']['unknownType']
|
|
253
|
-
}): string {
|
|
254
|
-
const results: string[] = []
|
|
89
|
+
const meta = {
|
|
90
|
+
file: resolver.resolveFile({ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
|
|
91
|
+
} as const
|
|
255
92
|
|
|
256
|
-
|
|
257
|
-
name
|
|
258
|
-
|
|
259
|
-
type: 'type',
|
|
260
|
-
})
|
|
93
|
+
// Build a set of schema names that are enums so the ref handler and getImports
|
|
94
|
+
// callback can use the suffixed type name (e.g. `StatusKey`) for those refs.
|
|
95
|
+
const enumSchemaNames = new Set((adapter.rootNode?.schemas ?? []).filter((s) => narrowSchema(s, schemaTypes.enum) && s.name).map((s) => s.name!))
|
|
261
96
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
type: 'type',
|
|
269
|
-
})
|
|
97
|
+
function resolveImportName(schemaName: string): string {
|
|
98
|
+
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) {
|
|
99
|
+
return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix)
|
|
100
|
+
}
|
|
101
|
+
return resolver.resolveTypeName(schemaName)
|
|
102
|
+
}
|
|
270
103
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
104
|
+
function renderSchemaType({ schema, name, keysToOmit }: { schema: SchemaNode | null; name: string; keysToOmit?: Array<string> }) {
|
|
105
|
+
if (!schema) return null
|
|
106
|
+
|
|
107
|
+
const imports = adapter.getImports(schema, (schemaName) => ({
|
|
108
|
+
name: resolveImportName(schemaName),
|
|
109
|
+
path: resolver.resolveFile({ name: schemaName, extname: '.ts' }, { root, output, group }).path,
|
|
110
|
+
}))
|
|
111
|
+
|
|
112
|
+
const schemaPrinter = printerTs({
|
|
113
|
+
optionalType,
|
|
114
|
+
arrayType,
|
|
115
|
+
enumType,
|
|
116
|
+
enumTypeSuffix,
|
|
117
|
+
name,
|
|
118
|
+
syntaxType,
|
|
119
|
+
description: schema.description,
|
|
120
|
+
keysToOmit,
|
|
121
|
+
resolver,
|
|
122
|
+
enumSchemaNames,
|
|
123
|
+
nodes: printer?.nodes,
|
|
274
124
|
})
|
|
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, '1'>({
|
|
313
|
-
name: 'typescript',
|
|
314
|
-
version: '1',
|
|
315
|
-
Operation({ operation, generator, plugin }) {
|
|
316
|
-
const {
|
|
317
|
-
options,
|
|
318
|
-
options: { mapper, enumType, enumKeyCasing, syntaxType, optionalType, arrayType, unknownType, paramsCasing },
|
|
319
|
-
} = plugin
|
|
320
|
-
|
|
321
|
-
const mode = useMode()
|
|
322
|
-
const pluginManager = usePluginManager()
|
|
323
|
-
|
|
324
|
-
const oas = useOas()
|
|
325
|
-
const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)
|
|
326
|
-
const schemaManager = useSchemaManager()
|
|
327
|
-
|
|
328
|
-
const name = getName(operation, { type: 'type', pluginName: pluginTsName })
|
|
329
|
-
|
|
330
|
-
const file = getFile(operation)
|
|
331
|
-
const schemas = getSchemas(operation)
|
|
332
|
-
const schemaGenerator = new SchemaGenerator(options, {
|
|
333
|
-
fabric: generator.context.fabric,
|
|
334
|
-
oas,
|
|
335
|
-
events: generator.context.events,
|
|
336
|
-
plugin,
|
|
337
|
-
pluginManager,
|
|
338
|
-
mode,
|
|
339
|
-
override: options.override,
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]
|
|
343
|
-
.flat()
|
|
344
|
-
.filter(Boolean)
|
|
345
|
-
|
|
346
|
-
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType) => {
|
|
347
|
-
// Apply paramsCasing transformation to pathParams, queryParams, and headerParams (not response)
|
|
348
|
-
const shouldTransform = paramsCasing && isParameterSchema(name)
|
|
349
|
-
const transformedSchema = shouldTransform ? applyParamsCasing(schema, paramsCasing) : schema
|
|
350
|
-
|
|
351
|
-
const tree = schemaGenerator.parse({ schema: transformedSchema, name, parentName: null })
|
|
352
|
-
const imports = getImports(tree)
|
|
353
|
-
const group = options.operation ? getGroup(options.operation) : undefined
|
|
354
|
-
|
|
355
|
-
const type = {
|
|
356
|
-
name: schemaManager.getName(name, { type: 'type' }),
|
|
357
|
-
typedName: schemaManager.getName(name, { type: 'type' }),
|
|
358
|
-
file: schemaManager.getFile(options.operationName || name, { group }),
|
|
359
|
-
}
|
|
360
125
|
|
|
361
126
|
return (
|
|
362
127
|
<>
|
|
363
128
|
{mode === 'split' &&
|
|
364
129
|
imports.map((imp) => (
|
|
365
|
-
<File.Import key={[name, imp.
|
|
130
|
+
<File.Import key={[name, imp.path, imp.isTypeOnly].join('-')} root={meta.file.path} path={imp.path} name={imp.name} isTypeOnly />
|
|
366
131
|
))}
|
|
367
132
|
<Type
|
|
368
|
-
name={
|
|
369
|
-
|
|
370
|
-
description={description}
|
|
371
|
-
tree={tree}
|
|
372
|
-
schema={transformedSchema}
|
|
373
|
-
mapper={mapper}
|
|
133
|
+
name={name}
|
|
134
|
+
node={schema}
|
|
374
135
|
enumType={enumType}
|
|
136
|
+
enumTypeSuffix={enumTypeSuffix}
|
|
375
137
|
enumKeyCasing={enumKeyCasing}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
keysToOmit={keysToOmit}
|
|
379
|
-
syntaxType={syntaxType}
|
|
138
|
+
resolver={resolver}
|
|
139
|
+
printer={schemaPrinter}
|
|
380
140
|
/>
|
|
381
141
|
</>
|
|
382
142
|
)
|
|
383
143
|
}
|
|
384
144
|
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
return (
|
|
392
|
-
<File
|
|
393
|
-
baseName={file.baseName}
|
|
394
|
-
path={file.path}
|
|
395
|
-
meta={file.meta}
|
|
396
|
-
banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}
|
|
397
|
-
footer={getFooter({ oas, output: plugin.options.output })}
|
|
398
|
-
>
|
|
399
|
-
{operationSchemas.map(mapOperationSchema)}
|
|
400
|
-
|
|
401
|
-
{generator.context.UNSTABLE_NAMING ? (
|
|
402
|
-
<>
|
|
403
|
-
<File.Source name={`${name}Request`} isExportable isIndexable isTypeOnly>
|
|
404
|
-
{printRequestSchema({ baseName: name, operation, schemas, pluginManager })}
|
|
405
|
-
</File.Source>
|
|
406
|
-
<File.Source name={responseName} isExportable isIndexable isTypeOnly>
|
|
407
|
-
{printResponseSchema({ baseName: name, schemas, pluginManager, unknownType })}
|
|
408
|
-
</File.Source>
|
|
409
|
-
</>
|
|
410
|
-
) : (
|
|
411
|
-
<File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>
|
|
412
|
-
{printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}
|
|
413
|
-
</File.Source>
|
|
414
|
-
)}
|
|
415
|
-
</File>
|
|
145
|
+
const paramTypes = params.map((param) =>
|
|
146
|
+
renderSchemaType({
|
|
147
|
+
schema: param.schema,
|
|
148
|
+
name: resolver.resolveParamName(node, param),
|
|
149
|
+
}),
|
|
416
150
|
)
|
|
417
|
-
},
|
|
418
|
-
Schema({ schema, plugin }) {
|
|
419
|
-
const {
|
|
420
|
-
options: { mapper, enumType, enumKeyCasing, syntaxType, optionalType, arrayType, output },
|
|
421
|
-
} = plugin
|
|
422
|
-
const mode = useMode()
|
|
423
151
|
|
|
424
|
-
const
|
|
425
|
-
|
|
152
|
+
const requestType = node.requestBody?.schema
|
|
153
|
+
? renderSchemaType({
|
|
154
|
+
schema: {
|
|
155
|
+
...node.requestBody.schema,
|
|
156
|
+
description: node.requestBody.description ?? node.requestBody.schema.description,
|
|
157
|
+
},
|
|
158
|
+
name: resolver.resolveDataName(node),
|
|
159
|
+
keysToOmit: node.requestBody.keysToOmit,
|
|
160
|
+
})
|
|
161
|
+
: null
|
|
426
162
|
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
163
|
+
const responseTypes = node.responses.map((res) =>
|
|
164
|
+
renderSchemaType({
|
|
165
|
+
schema: res.schema,
|
|
166
|
+
name: resolver.resolveResponseStatusName(node, res.statusCode),
|
|
167
|
+
keysToOmit: res.keysToOmit,
|
|
168
|
+
}),
|
|
169
|
+
)
|
|
430
170
|
|
|
431
|
-
|
|
171
|
+
const dataType = renderSchemaType({
|
|
172
|
+
schema: buildData({ ...node, parameters: params }, { resolver }),
|
|
173
|
+
name: resolver.resolveRequestConfigName(node),
|
|
174
|
+
})
|
|
432
175
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
176
|
+
const responsesType = renderSchemaType({
|
|
177
|
+
schema: buildResponses(node, { resolver }),
|
|
178
|
+
name: resolver.resolveResponsesName(node),
|
|
179
|
+
})
|
|
436
180
|
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
181
|
+
const responseType = renderSchemaType({
|
|
182
|
+
schema: node.responses.some((res) => res.schema)
|
|
183
|
+
? {
|
|
184
|
+
...buildResponseUnion(node, { resolver })!,
|
|
185
|
+
description: 'Union of all possible responses',
|
|
186
|
+
}
|
|
187
|
+
: null,
|
|
188
|
+
name: resolver.resolveResponseName(node),
|
|
189
|
+
})
|
|
442
190
|
|
|
443
191
|
return (
|
|
444
192
|
<File
|
|
445
|
-
baseName={
|
|
446
|
-
path={
|
|
447
|
-
meta={
|
|
448
|
-
banner={
|
|
449
|
-
footer={
|
|
193
|
+
baseName={meta.file.baseName}
|
|
194
|
+
path={meta.file.path}
|
|
195
|
+
meta={meta.file.meta}
|
|
196
|
+
banner={resolver.resolveBanner(adapter.rootNode, { output, config })}
|
|
197
|
+
footer={resolver.resolveFooter(adapter.rootNode, { output, config })}
|
|
450
198
|
>
|
|
451
|
-
{
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
typedName={type.typedName}
|
|
458
|
-
description={schema.value.description}
|
|
459
|
-
tree={schema.tree}
|
|
460
|
-
schema={schema.value}
|
|
461
|
-
mapper={mapper}
|
|
462
|
-
enumType={enumType}
|
|
463
|
-
enumKeyCasing={enumKeyCasing}
|
|
464
|
-
optionalType={optionalType}
|
|
465
|
-
arrayType={arrayType}
|
|
466
|
-
syntaxType={syntaxType}
|
|
467
|
-
/>
|
|
199
|
+
{paramTypes}
|
|
200
|
+
{responseTypes}
|
|
201
|
+
{requestType}
|
|
202
|
+
{dataType}
|
|
203
|
+
{responsesType}
|
|
204
|
+
{responseType}
|
|
468
205
|
</File>
|
|
469
206
|
)
|
|
470
207
|
},
|