@kubb/plugin-ts 5.0.0-alpha.11 → 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 +80 -126
- 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-CJ29AwE2.cjs +0 -1320
- package/dist/plugin-CJ29AwE2.cjs.map +0 -1
- package/dist/plugin-D60XNJSD.js +0 -1267
- package/dist/plugin-D60XNJSD.js.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
package/dist/plugin-CJ29AwE2.cjs
DELETED
|
@@ -1,1320 +0,0 @@
|
|
|
1
|
-
const require_components = require("./components-DeNDKlzf.cjs");
|
|
2
|
-
let node_path = require("node:path");
|
|
3
|
-
node_path = require_components.__toESM(node_path);
|
|
4
|
-
let _kubb_ast = require("@kubb/ast");
|
|
5
|
-
let _kubb_core = require("@kubb/core");
|
|
6
|
-
let _kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
7
|
-
let _kubb_core_hooks = require("@kubb/core/hooks");
|
|
8
|
-
let _kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
|
|
9
|
-
let _kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
|
|
10
|
-
let _kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
|
|
11
|
-
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
12
|
-
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
13
|
-
let typescript = require("typescript");
|
|
14
|
-
typescript = require_components.__toESM(typescript);
|
|
15
|
-
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
16
|
-
//#region ../../internals/utils/src/object.ts
|
|
17
|
-
/**
|
|
18
|
-
* Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* stringify('hello') // '"hello"'
|
|
22
|
-
* stringify('"hello"') // '"hello"'
|
|
23
|
-
*/
|
|
24
|
-
function stringify(value) {
|
|
25
|
-
if (value === void 0 || value === null) return "\"\"";
|
|
26
|
-
return JSON.stringify(require_components.trimQuotes(value.toString()));
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/generators/typeGenerator.tsx
|
|
30
|
-
function printCombinedSchema({ name, schemas, driver }) {
|
|
31
|
-
const properties = {};
|
|
32
|
-
if (schemas.response) properties["response"] = require_components.createUnionDeclaration({ nodes: schemas.responses.map((res) => {
|
|
33
|
-
const identifier = driver.resolveName({
|
|
34
|
-
name: res.name,
|
|
35
|
-
pluginName: pluginTsName,
|
|
36
|
-
type: "function"
|
|
37
|
-
});
|
|
38
|
-
return require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
39
|
-
}) });
|
|
40
|
-
if (schemas.request) {
|
|
41
|
-
const identifier = driver.resolveName({
|
|
42
|
-
name: schemas.request.name,
|
|
43
|
-
pluginName: pluginTsName,
|
|
44
|
-
type: "function"
|
|
45
|
-
});
|
|
46
|
-
properties["request"] = require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
47
|
-
}
|
|
48
|
-
if (schemas.pathParams) {
|
|
49
|
-
const identifier = driver.resolveName({
|
|
50
|
-
name: schemas.pathParams.name,
|
|
51
|
-
pluginName: pluginTsName,
|
|
52
|
-
type: "function"
|
|
53
|
-
});
|
|
54
|
-
properties["pathParams"] = require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
55
|
-
}
|
|
56
|
-
if (schemas.queryParams) {
|
|
57
|
-
const identifier = driver.resolveName({
|
|
58
|
-
name: schemas.queryParams.name,
|
|
59
|
-
pluginName: pluginTsName,
|
|
60
|
-
type: "function"
|
|
61
|
-
});
|
|
62
|
-
properties["queryParams"] = require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
63
|
-
}
|
|
64
|
-
if (schemas.headerParams) {
|
|
65
|
-
const identifier = driver.resolveName({
|
|
66
|
-
name: schemas.headerParams.name,
|
|
67
|
-
pluginName: pluginTsName,
|
|
68
|
-
type: "function"
|
|
69
|
-
});
|
|
70
|
-
properties["headerParams"] = require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
71
|
-
}
|
|
72
|
-
if (schemas.errors) properties["errors"] = require_components.createUnionDeclaration({ nodes: schemas.errors.map((error) => {
|
|
73
|
-
const identifier = driver.resolveName({
|
|
74
|
-
name: error.name,
|
|
75
|
-
pluginName: pluginTsName,
|
|
76
|
-
type: "function"
|
|
77
|
-
});
|
|
78
|
-
return require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
79
|
-
}) });
|
|
80
|
-
return (0, _kubb_fabric_core_parsers_typescript.safePrint)(require_components.createTypeAliasDeclaration({
|
|
81
|
-
name,
|
|
82
|
-
type: require_components.createTypeLiteralNode(Object.keys(properties).map((key) => {
|
|
83
|
-
const type = properties[key];
|
|
84
|
-
if (!type) return;
|
|
85
|
-
return require_components.createPropertySignature({
|
|
86
|
-
name: require_components.pascalCase(key),
|
|
87
|
-
type
|
|
88
|
-
});
|
|
89
|
-
}).filter(Boolean)),
|
|
90
|
-
modifiers: [require_components.modifiers.export]
|
|
91
|
-
}));
|
|
92
|
-
}
|
|
93
|
-
function printRequestSchema({ baseName, operation, schemas, driver }) {
|
|
94
|
-
const name = driver.resolveName({
|
|
95
|
-
name: `${baseName} Request`,
|
|
96
|
-
pluginName: pluginTsName,
|
|
97
|
-
type: "type"
|
|
98
|
-
});
|
|
99
|
-
const results = [];
|
|
100
|
-
const dataRequestProperties = [];
|
|
101
|
-
if (schemas.request) {
|
|
102
|
-
const identifier = driver.resolveName({
|
|
103
|
-
name: schemas.request.name,
|
|
104
|
-
pluginName: pluginTsName,
|
|
105
|
-
type: "type"
|
|
106
|
-
});
|
|
107
|
-
dataRequestProperties.push(require_components.createPropertySignature({
|
|
108
|
-
name: "data",
|
|
109
|
-
questionToken: true,
|
|
110
|
-
type: require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0)
|
|
111
|
-
}));
|
|
112
|
-
} else dataRequestProperties.push(require_components.createPropertySignature({
|
|
113
|
-
name: "data",
|
|
114
|
-
questionToken: true,
|
|
115
|
-
type: require_components.keywordTypeNodes.never
|
|
116
|
-
}));
|
|
117
|
-
if (schemas.pathParams) {
|
|
118
|
-
const identifier = driver.resolveName({
|
|
119
|
-
name: schemas.pathParams.name,
|
|
120
|
-
pluginName: pluginTsName,
|
|
121
|
-
type: "type"
|
|
122
|
-
});
|
|
123
|
-
dataRequestProperties.push(require_components.createPropertySignature({
|
|
124
|
-
name: "pathParams",
|
|
125
|
-
type: require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0)
|
|
126
|
-
}));
|
|
127
|
-
} else dataRequestProperties.push(require_components.createPropertySignature({
|
|
128
|
-
name: "pathParams",
|
|
129
|
-
questionToken: true,
|
|
130
|
-
type: require_components.keywordTypeNodes.never
|
|
131
|
-
}));
|
|
132
|
-
if (schemas.queryParams) {
|
|
133
|
-
const identifier = driver.resolveName({
|
|
134
|
-
name: schemas.queryParams.name,
|
|
135
|
-
pluginName: pluginTsName,
|
|
136
|
-
type: "type"
|
|
137
|
-
});
|
|
138
|
-
dataRequestProperties.push(require_components.createPropertySignature({
|
|
139
|
-
name: "queryParams",
|
|
140
|
-
questionToken: true,
|
|
141
|
-
type: require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0)
|
|
142
|
-
}));
|
|
143
|
-
} else dataRequestProperties.push(require_components.createPropertySignature({
|
|
144
|
-
name: "queryParams",
|
|
145
|
-
questionToken: true,
|
|
146
|
-
type: require_components.keywordTypeNodes.never
|
|
147
|
-
}));
|
|
148
|
-
if (schemas.headerParams) {
|
|
149
|
-
const identifier = driver.resolveName({
|
|
150
|
-
name: schemas.headerParams.name,
|
|
151
|
-
pluginName: pluginTsName,
|
|
152
|
-
type: "type"
|
|
153
|
-
});
|
|
154
|
-
dataRequestProperties.push(require_components.createPropertySignature({
|
|
155
|
-
name: "headerParams",
|
|
156
|
-
questionToken: true,
|
|
157
|
-
type: require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0)
|
|
158
|
-
}));
|
|
159
|
-
} else dataRequestProperties.push(require_components.createPropertySignature({
|
|
160
|
-
name: "headerParams",
|
|
161
|
-
questionToken: true,
|
|
162
|
-
type: require_components.keywordTypeNodes.never
|
|
163
|
-
}));
|
|
164
|
-
dataRequestProperties.push(require_components.createPropertySignature({
|
|
165
|
-
name: "url",
|
|
166
|
-
type: require_components.createUrlTemplateType(operation.path)
|
|
167
|
-
}));
|
|
168
|
-
const dataRequestNode = require_components.createTypeAliasDeclaration({
|
|
169
|
-
name,
|
|
170
|
-
type: require_components.createTypeLiteralNode(dataRequestProperties),
|
|
171
|
-
modifiers: [require_components.modifiers.export]
|
|
172
|
-
});
|
|
173
|
-
results.push((0, _kubb_fabric_core_parsers_typescript.safePrint)(dataRequestNode));
|
|
174
|
-
return results.join("\n\n");
|
|
175
|
-
}
|
|
176
|
-
function printResponseSchema({ baseName, schemas, driver, unknownType }) {
|
|
177
|
-
const results = [];
|
|
178
|
-
const name = driver.resolveName({
|
|
179
|
-
name: `${baseName} ResponseData`,
|
|
180
|
-
pluginName: pluginTsName,
|
|
181
|
-
type: "type"
|
|
182
|
-
});
|
|
183
|
-
if (schemas.responses && schemas.responses.length > 0) {
|
|
184
|
-
const responsesProperties = schemas.responses.map((res) => {
|
|
185
|
-
const identifier = driver.resolveName({
|
|
186
|
-
name: res.name,
|
|
187
|
-
pluginName: pluginTsName,
|
|
188
|
-
type: "type"
|
|
189
|
-
});
|
|
190
|
-
return require_components.createPropertySignature({
|
|
191
|
-
name: res.statusCode?.toString() ?? "default",
|
|
192
|
-
type: require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0)
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
const responsesNode = require_components.createTypeAliasDeclaration({
|
|
196
|
-
name: `${baseName}Responses`,
|
|
197
|
-
type: require_components.createTypeLiteralNode(responsesProperties),
|
|
198
|
-
modifiers: [require_components.modifiers.export]
|
|
199
|
-
});
|
|
200
|
-
results.push((0, _kubb_fabric_core_parsers_typescript.safePrint)(responsesNode));
|
|
201
|
-
const responseNode = require_components.createTypeAliasDeclaration({
|
|
202
|
-
name,
|
|
203
|
-
type: require_components.createIndexedAccessTypeNode(require_components.createTypeReferenceNode(require_components.createIdentifier(`${baseName}Responses`), void 0), require_components.createTypeOperatorNode(typescript.default.SyntaxKind.KeyOfKeyword, require_components.createTypeReferenceNode(require_components.createIdentifier(`${baseName}Responses`), void 0))),
|
|
204
|
-
modifiers: [require_components.modifiers.export]
|
|
205
|
-
});
|
|
206
|
-
results.push((0, _kubb_fabric_core_parsers_typescript.safePrint)(responseNode));
|
|
207
|
-
} else {
|
|
208
|
-
const responseNode = require_components.createTypeAliasDeclaration({
|
|
209
|
-
name,
|
|
210
|
-
modifiers: [require_components.modifiers.export],
|
|
211
|
-
type: require_components.getUnknownType(unknownType)
|
|
212
|
-
});
|
|
213
|
-
results.push((0, _kubb_fabric_core_parsers_typescript.safePrint)(responseNode));
|
|
214
|
-
}
|
|
215
|
-
return results.join("\n\n");
|
|
216
|
-
}
|
|
217
|
-
const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
218
|
-
name: "typescript",
|
|
219
|
-
Operation({ operation, generator, plugin }) {
|
|
220
|
-
const { options, options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, unknownType, paramsCasing } } = plugin;
|
|
221
|
-
const mode = (0, _kubb_core_hooks.useMode)();
|
|
222
|
-
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
223
|
-
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
224
|
-
const { getSchemas, getFile, getName, getGroup } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
225
|
-
const schemaManager = (0, _kubb_plugin_oas_hooks.useSchemaManager)();
|
|
226
|
-
const name = getName(operation, {
|
|
227
|
-
type: "type",
|
|
228
|
-
pluginName: pluginTsName
|
|
229
|
-
});
|
|
230
|
-
const file = getFile(operation);
|
|
231
|
-
const schemas = getSchemas(operation);
|
|
232
|
-
const schemaGenerator = new _kubb_plugin_oas.SchemaGenerator(options, {
|
|
233
|
-
fabric: generator.context.fabric,
|
|
234
|
-
oas,
|
|
235
|
-
events: generator.context.events,
|
|
236
|
-
plugin,
|
|
237
|
-
driver,
|
|
238
|
-
mode,
|
|
239
|
-
override: options.override
|
|
240
|
-
});
|
|
241
|
-
const operationSchemas = [
|
|
242
|
-
schemas.pathParams,
|
|
243
|
-
schemas.queryParams,
|
|
244
|
-
schemas.headerParams,
|
|
245
|
-
schemas.statusCodes,
|
|
246
|
-
schemas.request,
|
|
247
|
-
schemas.response
|
|
248
|
-
].flat().filter(Boolean);
|
|
249
|
-
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }) => {
|
|
250
|
-
const transformedSchema = paramsCasing && (0, _kubb_plugin_oas_utils.isParameterSchema)(name) ? (0, _kubb_plugin_oas_utils.applyParamsCasing)(schema, paramsCasing) : schema;
|
|
251
|
-
const tree = schemaGenerator.parse({
|
|
252
|
-
schema: transformedSchema,
|
|
253
|
-
name,
|
|
254
|
-
parentName: null
|
|
255
|
-
});
|
|
256
|
-
const imports = (0, _kubb_plugin_oas_utils.getImports)(tree);
|
|
257
|
-
const group = options.operation ? getGroup(options.operation) : void 0;
|
|
258
|
-
const type = {
|
|
259
|
-
name: schemaManager.getName(name, { type: "type" }),
|
|
260
|
-
typedName: schemaManager.getName(name, { type: "type" }),
|
|
261
|
-
file: schemaManager.getFile(options.operationName || name, { group })
|
|
262
|
-
};
|
|
263
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
264
|
-
root: file.path,
|
|
265
|
-
path: imp.path,
|
|
266
|
-
name: imp.name,
|
|
267
|
-
isTypeOnly: true
|
|
268
|
-
}, [
|
|
269
|
-
name,
|
|
270
|
-
imp.name,
|
|
271
|
-
imp.path,
|
|
272
|
-
imp.isTypeOnly
|
|
273
|
-
].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Type, {
|
|
274
|
-
name: type.name,
|
|
275
|
-
typedName: type.typedName,
|
|
276
|
-
description,
|
|
277
|
-
tree,
|
|
278
|
-
schema: transformedSchema,
|
|
279
|
-
enumType,
|
|
280
|
-
enumKeyCasing,
|
|
281
|
-
optionalType,
|
|
282
|
-
arrayType,
|
|
283
|
-
keysToOmit,
|
|
284
|
-
syntaxType
|
|
285
|
-
})] });
|
|
286
|
-
};
|
|
287
|
-
const responseName = schemaManager.getName(schemas.response.name, { type: "type" });
|
|
288
|
-
const combinedSchemaName = operation.method === "get" ? `${name}Query` : `${name}Mutation`;
|
|
289
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
290
|
-
baseName: file.baseName,
|
|
291
|
-
path: file.path,
|
|
292
|
-
meta: file.meta,
|
|
293
|
-
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
294
|
-
oas,
|
|
295
|
-
output: plugin.options.output,
|
|
296
|
-
config: driver.config
|
|
297
|
-
}),
|
|
298
|
-
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
299
|
-
oas,
|
|
300
|
-
output: plugin.options.output
|
|
301
|
-
}),
|
|
302
|
-
children: [operationSchemas.map(mapOperationSchema), generator.context.UNSTABLE_NAMING ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
303
|
-
name: `${name}Request`,
|
|
304
|
-
isExportable: true,
|
|
305
|
-
isIndexable: true,
|
|
306
|
-
isTypeOnly: true,
|
|
307
|
-
children: printRequestSchema({
|
|
308
|
-
baseName: name,
|
|
309
|
-
operation,
|
|
310
|
-
schemas,
|
|
311
|
-
driver
|
|
312
|
-
})
|
|
313
|
-
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
314
|
-
name: responseName,
|
|
315
|
-
isExportable: true,
|
|
316
|
-
isIndexable: true,
|
|
317
|
-
isTypeOnly: true,
|
|
318
|
-
children: printResponseSchema({
|
|
319
|
-
baseName: name,
|
|
320
|
-
schemas,
|
|
321
|
-
driver,
|
|
322
|
-
unknownType
|
|
323
|
-
})
|
|
324
|
-
})] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
325
|
-
name: combinedSchemaName,
|
|
326
|
-
isExportable: true,
|
|
327
|
-
isIndexable: true,
|
|
328
|
-
isTypeOnly: true,
|
|
329
|
-
children: printCombinedSchema({
|
|
330
|
-
name: combinedSchemaName,
|
|
331
|
-
schemas,
|
|
332
|
-
driver
|
|
333
|
-
})
|
|
334
|
-
})]
|
|
335
|
-
});
|
|
336
|
-
},
|
|
337
|
-
Schema({ schema, plugin }) {
|
|
338
|
-
const { options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, output } } = plugin;
|
|
339
|
-
const mode = (0, _kubb_core_hooks.useMode)();
|
|
340
|
-
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
341
|
-
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
342
|
-
const { getName, getFile } = (0, _kubb_plugin_oas_hooks.useSchemaManager)();
|
|
343
|
-
const imports = (0, _kubb_plugin_oas_utils.getImports)(schema.tree);
|
|
344
|
-
const schemaFromTree = schema.tree.find((item) => item.keyword === _kubb_plugin_oas.schemaKeywords.schema);
|
|
345
|
-
let typedName = getName(schema.name, { type: "type" });
|
|
346
|
-
if (["asConst", "asPascalConst"].includes(enumType) && schemaFromTree && (0, _kubb_plugin_oas.isKeyword)(schemaFromTree, _kubb_plugin_oas.schemaKeywords.enum)) typedName = typedName += "Key";
|
|
347
|
-
const type = {
|
|
348
|
-
name: getName(schema.name, { type: "function" }),
|
|
349
|
-
typedName,
|
|
350
|
-
file: getFile(schema.name)
|
|
351
|
-
};
|
|
352
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
353
|
-
baseName: type.file.baseName,
|
|
354
|
-
path: type.file.path,
|
|
355
|
-
meta: type.file.meta,
|
|
356
|
-
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
357
|
-
oas,
|
|
358
|
-
output,
|
|
359
|
-
config: driver.config
|
|
360
|
-
}),
|
|
361
|
-
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
362
|
-
oas,
|
|
363
|
-
output
|
|
364
|
-
}),
|
|
365
|
-
children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
366
|
-
root: type.file.path,
|
|
367
|
-
path: imp.path,
|
|
368
|
-
name: imp.name,
|
|
369
|
-
isTypeOnly: true
|
|
370
|
-
}, [
|
|
371
|
-
schema.name,
|
|
372
|
-
imp.path,
|
|
373
|
-
imp.isTypeOnly
|
|
374
|
-
].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Type, {
|
|
375
|
-
name: type.name,
|
|
376
|
-
typedName: type.typedName,
|
|
377
|
-
description: schema.value.description,
|
|
378
|
-
tree: schema.tree,
|
|
379
|
-
schema: schema.value,
|
|
380
|
-
enumType,
|
|
381
|
-
enumKeyCasing,
|
|
382
|
-
optionalType,
|
|
383
|
-
arrayType,
|
|
384
|
-
syntaxType
|
|
385
|
-
})]
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
//#endregion
|
|
390
|
-
//#region src/constants.ts
|
|
391
|
-
/**
|
|
392
|
-
* `optionalType` values that cause a property's type to include `| undefined`.
|
|
393
|
-
*/
|
|
394
|
-
const OPTIONAL_ADDS_UNDEFINED = new Set(["undefined", "questionTokenAndUndefined"]);
|
|
395
|
-
/**
|
|
396
|
-
* `optionalType` values that render the property key with a `?` token.
|
|
397
|
-
*/
|
|
398
|
-
const OPTIONAL_ADDS_QUESTION_TOKEN = new Set(["questionToken", "questionTokenAndUndefined"]);
|
|
399
|
-
/**
|
|
400
|
-
* `enumType` values that append a `Key` suffix to the generated enum type alias.
|
|
401
|
-
*/
|
|
402
|
-
const ENUM_TYPES_WITH_KEY_SUFFIX = new Set(["asConst", "asPascalConst"]);
|
|
403
|
-
/**
|
|
404
|
-
* `enumType` values that require a runtime value declaration (object, enum, or literal).
|
|
405
|
-
*/
|
|
406
|
-
const ENUM_TYPES_WITH_RUNTIME_VALUE = new Set([
|
|
407
|
-
"enum",
|
|
408
|
-
"asConst",
|
|
409
|
-
"asPascalConst",
|
|
410
|
-
"constEnum",
|
|
411
|
-
"literal",
|
|
412
|
-
void 0
|
|
413
|
-
]);
|
|
414
|
-
/**
|
|
415
|
-
* `enumType` values whose type declaration is type-only (no runtime value emitted for the type alias).
|
|
416
|
-
*/
|
|
417
|
-
const ENUM_TYPES_WITH_TYPE_ONLY = new Set([
|
|
418
|
-
"asConst",
|
|
419
|
-
"asPascalConst",
|
|
420
|
-
"literal",
|
|
421
|
-
void 0
|
|
422
|
-
]);
|
|
423
|
-
//#endregion
|
|
424
|
-
//#region src/printer.ts
|
|
425
|
-
/**
|
|
426
|
-
* Converts a primitive const value to a TypeScript literal type node.
|
|
427
|
-
* Handles negative numbers via a prefix unary expression.
|
|
428
|
-
*/
|
|
429
|
-
function constToTypeNode(value, format) {
|
|
430
|
-
if (format === "boolean") return require_components.createLiteralTypeNode(value === true ? require_components.createTrue() : require_components.createFalse());
|
|
431
|
-
if (format === "number" && typeof value === "number") {
|
|
432
|
-
if (value < 0) return require_components.createLiteralTypeNode(require_components.createPrefixUnaryExpression(require_components.SyntaxKind.MinusToken, require_components.createNumericLiteral(Math.abs(value))));
|
|
433
|
-
return require_components.createLiteralTypeNode(require_components.createNumericLiteral(value));
|
|
434
|
-
}
|
|
435
|
-
return require_components.createLiteralTypeNode(require_components.createStringLiteral(String(value)));
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Returns a `Date` reference type node when `representation` is `'date'`, otherwise falls back to `string`.
|
|
439
|
-
*/
|
|
440
|
-
function dateOrStringNode(node) {
|
|
441
|
-
return node.representation === "date" ? require_components.createTypeReferenceNode(require_components.createIdentifier("Date")) : require_components.keywordTypeNodes.string;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Maps an array of `SchemaNode`s through the printer, filtering out `null` and `undefined` results.
|
|
445
|
-
*/
|
|
446
|
-
function buildMemberNodes(members, print) {
|
|
447
|
-
return (members ?? []).map(print).filter(Boolean);
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Builds a TypeScript tuple type node from an array schema's `items`,
|
|
451
|
-
* applying min/max slice and optional/rest element rules.
|
|
452
|
-
*/
|
|
453
|
-
function buildTupleNode(node, print) {
|
|
454
|
-
let items = (node.items ?? []).map(print).filter(Boolean);
|
|
455
|
-
const restNode = node.rest ? print(node.rest) ?? void 0 : void 0;
|
|
456
|
-
const { min, max } = node;
|
|
457
|
-
if (max !== void 0) {
|
|
458
|
-
items = items.slice(0, max);
|
|
459
|
-
if (items.length < max && restNode) items = [...items, ...Array(max - items.length).fill(restNode)];
|
|
460
|
-
}
|
|
461
|
-
if (min !== void 0) items = items.map((item, i) => i >= min ? require_components.createOptionalTypeNode(item) : item);
|
|
462
|
-
if (max === void 0 && restNode) items.push(require_components.createRestTypeNode(require_components.createArrayTypeNode(restNode)));
|
|
463
|
-
return require_components.createTupleTypeNode(items);
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Applies `nullable` and optional/nullish `| undefined` union modifiers to a property's resolved base type.
|
|
467
|
-
*/
|
|
468
|
-
function buildPropertyType(schema, baseType, optionalType) {
|
|
469
|
-
const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
|
|
470
|
-
let type = baseType;
|
|
471
|
-
if (schema.nullable) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.null] });
|
|
472
|
-
if ((schema.nullish || schema.optional) && addsUndefined) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.undefined] });
|
|
473
|
-
return type;
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Collects JSDoc annotation strings (description, deprecated, min/max, pattern, default, example, type) for a schema node.
|
|
477
|
-
*/
|
|
478
|
-
function buildPropertyJSDocComments(schema) {
|
|
479
|
-
return [
|
|
480
|
-
"description" in schema && schema.description ? `@description ${require_components.jsStringEscape(schema.description)}` : void 0,
|
|
481
|
-
"deprecated" in schema && schema.deprecated ? "@deprecated" : void 0,
|
|
482
|
-
"min" in schema && schema.min !== void 0 ? `@minLength ${schema.min}` : void 0,
|
|
483
|
-
"max" in schema && schema.max !== void 0 ? `@maxLength ${schema.max}` : void 0,
|
|
484
|
-
"pattern" in schema && schema.pattern ? `@pattern ${schema.pattern}` : void 0,
|
|
485
|
-
"default" in schema && schema.default !== void 0 ? `@default ${"primitive" in schema && schema.primitive === "string" ? stringify(schema.default) : schema.default}` : void 0,
|
|
486
|
-
"example" in schema && schema.example !== void 0 ? `@example ${schema.example}` : void 0,
|
|
487
|
-
"primitive" in schema && schema.primitive ? [`@type ${schema.primitive || "unknown"}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
|
|
488
|
-
];
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Creates TypeScript index signatures for `additionalProperties` and `patternProperties` on an object schema node.
|
|
492
|
-
*/
|
|
493
|
-
function buildIndexSignatures(node, propertyCount, print) {
|
|
494
|
-
const elements = [];
|
|
495
|
-
if (node.additionalProperties && node.additionalProperties !== true) {
|
|
496
|
-
const additionalType = print(node.additionalProperties) ?? require_components.keywordTypeNodes.unknown;
|
|
497
|
-
elements.push(require_components.createIndexSignature(propertyCount > 0 ? require_components.keywordTypeNodes.unknown : additionalType));
|
|
498
|
-
} else if (node.additionalProperties === true) elements.push(require_components.createIndexSignature(require_components.keywordTypeNodes.unknown));
|
|
499
|
-
if (node.patternProperties) {
|
|
500
|
-
const first = Object.values(node.patternProperties)[0];
|
|
501
|
-
if (first) {
|
|
502
|
-
let patternType = print(first) ?? require_components.keywordTypeNodes.unknown;
|
|
503
|
-
if (first.nullable) patternType = require_components.createUnionDeclaration({ nodes: [patternType, require_components.keywordTypeNodes.null] });
|
|
504
|
-
elements.push(require_components.createIndexSignature(patternType));
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
return elements;
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* TypeScript type printer built with `definePrinter`.
|
|
511
|
-
*
|
|
512
|
-
* Converts a `SchemaNode` AST node into a TypeScript AST node:
|
|
513
|
-
* - **`printer.print(node)`** — when `options.typeName` is set, returns a full
|
|
514
|
-
* `type Name = …` or `interface Name { … }` declaration (`ts.Node`).
|
|
515
|
-
* Without `typeName`, returns the raw `ts.TypeNode` for the schema.
|
|
516
|
-
*
|
|
517
|
-
* Dispatches on `node.type` to the appropriate handler in `nodes`. Options are closed
|
|
518
|
-
* over per printer instance, so each call to `printerTs(options)` produces an independent printer.
|
|
519
|
-
*
|
|
520
|
-
* @example Raw type node (no `typeName`)
|
|
521
|
-
* ```ts
|
|
522
|
-
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral' })
|
|
523
|
-
* const typeNode = printer.print(schemaNode) // ts.TypeNode
|
|
524
|
-
* ```
|
|
525
|
-
*
|
|
526
|
-
* @example Full declaration (with `typeName`)
|
|
527
|
-
* ```ts
|
|
528
|
-
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral', typeName: 'MyType' })
|
|
529
|
-
* const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
|
|
530
|
-
* ```
|
|
531
|
-
*/
|
|
532
|
-
const printerTs = (0, _kubb_core.definePrinter)((options) => {
|
|
533
|
-
const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(options.optionalType);
|
|
534
|
-
return {
|
|
535
|
-
name: "typescript",
|
|
536
|
-
options,
|
|
537
|
-
nodes: {
|
|
538
|
-
any: () => require_components.keywordTypeNodes.any,
|
|
539
|
-
unknown: () => require_components.keywordTypeNodes.unknown,
|
|
540
|
-
void: () => require_components.keywordTypeNodes.void,
|
|
541
|
-
never: () => require_components.keywordTypeNodes.never,
|
|
542
|
-
boolean: () => require_components.keywordTypeNodes.boolean,
|
|
543
|
-
null: () => require_components.keywordTypeNodes.null,
|
|
544
|
-
blob: () => require_components.createTypeReferenceNode("Blob", []),
|
|
545
|
-
string: () => require_components.keywordTypeNodes.string,
|
|
546
|
-
uuid: () => require_components.keywordTypeNodes.string,
|
|
547
|
-
email: () => require_components.keywordTypeNodes.string,
|
|
548
|
-
url: (node) => {
|
|
549
|
-
if (node.path) return require_components.createUrlTemplateType(node.path);
|
|
550
|
-
return require_components.keywordTypeNodes.string;
|
|
551
|
-
},
|
|
552
|
-
datetime: () => require_components.keywordTypeNodes.string,
|
|
553
|
-
number: () => require_components.keywordTypeNodes.number,
|
|
554
|
-
integer: () => require_components.keywordTypeNodes.number,
|
|
555
|
-
bigint: () => require_components.keywordTypeNodes.bigint,
|
|
556
|
-
date: dateOrStringNode,
|
|
557
|
-
time: dateOrStringNode,
|
|
558
|
-
ref(node) {
|
|
559
|
-
if (!node.name) return;
|
|
560
|
-
return require_components.createTypeReferenceNode(node.name, void 0);
|
|
561
|
-
},
|
|
562
|
-
enum(node) {
|
|
563
|
-
const values = node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? [];
|
|
564
|
-
if (this.options.enumType === "inlineLiteral" || !node.name) {
|
|
565
|
-
const literalNodes = values.filter((v) => v !== null).map((value) => constToTypeNode(value, typeof value)).filter(Boolean);
|
|
566
|
-
return require_components.createUnionDeclaration({
|
|
567
|
-
withParentheses: true,
|
|
568
|
-
nodes: literalNodes
|
|
569
|
-
}) ?? void 0;
|
|
570
|
-
}
|
|
571
|
-
const resolvedName = require_components.pascalCase(node.name);
|
|
572
|
-
const typeName = ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) ? `${resolvedName}Key` : resolvedName;
|
|
573
|
-
return require_components.createTypeReferenceNode(typeName, void 0);
|
|
574
|
-
},
|
|
575
|
-
union(node) {
|
|
576
|
-
const members = node.members ?? [];
|
|
577
|
-
const hasStringLiteral = members.some((m) => m.type === "enum" && (m.enumType === "string" || m.primitive === "string"));
|
|
578
|
-
const hasPlainString = members.some((m) => (0, _kubb_ast.isPlainStringType)(m));
|
|
579
|
-
if (hasStringLiteral && hasPlainString) {
|
|
580
|
-
const memberNodes = members.map((m) => {
|
|
581
|
-
if ((0, _kubb_ast.isPlainStringType)(m)) return require_components.createIntersectionDeclaration({
|
|
582
|
-
nodes: [require_components.keywordTypeNodes.string, require_components.createTypeLiteralNode([])],
|
|
583
|
-
withParentheses: true
|
|
584
|
-
});
|
|
585
|
-
return this.print(m);
|
|
586
|
-
}).filter(Boolean);
|
|
587
|
-
return require_components.createUnionDeclaration({
|
|
588
|
-
withParentheses: true,
|
|
589
|
-
nodes: memberNodes
|
|
590
|
-
}) ?? void 0;
|
|
591
|
-
}
|
|
592
|
-
return require_components.createUnionDeclaration({
|
|
593
|
-
withParentheses: true,
|
|
594
|
-
nodes: buildMemberNodes(members, this.print)
|
|
595
|
-
}) ?? void 0;
|
|
596
|
-
},
|
|
597
|
-
intersection(node) {
|
|
598
|
-
return require_components.createIntersectionDeclaration({
|
|
599
|
-
withParentheses: true,
|
|
600
|
-
nodes: buildMemberNodes(node.members, this.print)
|
|
601
|
-
}) ?? void 0;
|
|
602
|
-
},
|
|
603
|
-
array(node) {
|
|
604
|
-
const itemNodes = (node.items ?? []).map((item) => this.print(item)).filter(Boolean);
|
|
605
|
-
return require_components.createArrayDeclaration({
|
|
606
|
-
nodes: itemNodes,
|
|
607
|
-
arrayType: this.options.arrayType
|
|
608
|
-
}) ?? void 0;
|
|
609
|
-
},
|
|
610
|
-
tuple(node) {
|
|
611
|
-
return buildTupleNode(node, this.print);
|
|
612
|
-
},
|
|
613
|
-
object(node) {
|
|
614
|
-
const { print, options } = this;
|
|
615
|
-
const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options.optionalType);
|
|
616
|
-
const propertyNodes = node.properties.map((prop) => {
|
|
617
|
-
const baseType = print(prop.schema) ?? require_components.keywordTypeNodes.unknown;
|
|
618
|
-
const type = buildPropertyType(prop.schema, baseType, options.optionalType);
|
|
619
|
-
const propertyNode = require_components.createPropertySignature({
|
|
620
|
-
questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
|
|
621
|
-
name: prop.name,
|
|
622
|
-
type,
|
|
623
|
-
readOnly: prop.schema.readOnly
|
|
624
|
-
});
|
|
625
|
-
return require_components.appendJSDocToNode({
|
|
626
|
-
node: propertyNode,
|
|
627
|
-
comments: buildPropertyJSDocComments(prop.schema)
|
|
628
|
-
});
|
|
629
|
-
});
|
|
630
|
-
const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
|
|
631
|
-
if (!allElements.length) return require_components.keywordTypeNodes.object;
|
|
632
|
-
return require_components.createTypeLiteralNode(allElements);
|
|
633
|
-
}
|
|
634
|
-
},
|
|
635
|
-
print(node) {
|
|
636
|
-
let type = this.print(node);
|
|
637
|
-
if (!type) return;
|
|
638
|
-
if (node.nullable) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.null] });
|
|
639
|
-
if ((node.nullish || node.optional) && addsUndefined) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.undefined] });
|
|
640
|
-
const { typeName, syntaxType = "type", description, keysToOmit } = this.options;
|
|
641
|
-
if (!typeName) return type;
|
|
642
|
-
const useTypeGeneration = syntaxType === "type" || type.kind === require_components.syntaxKind.union || !!keysToOmit?.length;
|
|
643
|
-
return require_components.createTypeDeclaration({
|
|
644
|
-
name: typeName,
|
|
645
|
-
isExportable: true,
|
|
646
|
-
type: keysToOmit?.length ? require_components.createOmitDeclaration({
|
|
647
|
-
keys: keysToOmit,
|
|
648
|
-
type,
|
|
649
|
-
nonNullable: true
|
|
650
|
-
}) : type,
|
|
651
|
-
syntax: useTypeGeneration ? "type" : "interface",
|
|
652
|
-
comments: [
|
|
653
|
-
node?.title ? require_components.jsStringEscape(node.title) : void 0,
|
|
654
|
-
description ? `@description ${require_components.jsStringEscape(description)}` : void 0,
|
|
655
|
-
node?.deprecated ? "@deprecated" : void 0,
|
|
656
|
-
node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
|
|
657
|
-
node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
|
|
658
|
-
node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
|
|
659
|
-
node?.default ? `@default ${node.default}` : void 0,
|
|
660
|
-
node?.example ? `@example ${node.example}` : void 0
|
|
661
|
-
]
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
});
|
|
666
|
-
//#endregion
|
|
667
|
-
//#region src/components/v2/Enum.tsx
|
|
668
|
-
/**
|
|
669
|
-
* Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
|
|
670
|
-
*
|
|
671
|
-
* The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
|
|
672
|
-
* valid TypeScript identifier. `pascalCase` normalizes it unconditionally; for inline enum
|
|
673
|
-
* properties the adapter already emits a PascalCase+suffix name so `pascalCase` is a no-op.
|
|
674
|
-
*/
|
|
675
|
-
function getEnumNames(node, enumType) {
|
|
676
|
-
const resolved = require_components.pascalCase(node.name);
|
|
677
|
-
return {
|
|
678
|
-
enumName: enumType === "asPascalConst" ? resolved : require_components.camelCase(node.name),
|
|
679
|
-
typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Renders the enum declaration(s) for a single named `EnumSchemaNode`.
|
|
684
|
-
*
|
|
685
|
-
* Depending on `enumType` this may emit:
|
|
686
|
-
* - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
|
|
687
|
-
* - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
|
|
688
|
-
* - A union literal type alias (`literal`)
|
|
689
|
-
*
|
|
690
|
-
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
691
|
-
* index picks up the correct export identifiers.
|
|
692
|
-
*/
|
|
693
|
-
function Enum({ node, enumType, enumKeyCasing }) {
|
|
694
|
-
const { enumName, typeName } = getEnumNames(node, enumType);
|
|
695
|
-
const [nameNode, typeNode] = require_components.createEnumDeclaration({
|
|
696
|
-
name: enumName,
|
|
697
|
-
typeName,
|
|
698
|
-
enums: node.namedEnumValues?.map((v) => [require_components.trimQuotes(v.name.toString()), v.value]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [require_components.trimQuotes(v.toString()), v]) ?? [],
|
|
699
|
-
type: enumType,
|
|
700
|
-
enumKeyCasing
|
|
701
|
-
});
|
|
702
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [nameNode && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
703
|
-
name: enumName,
|
|
704
|
-
isExportable: true,
|
|
705
|
-
isIndexable: true,
|
|
706
|
-
isTypeOnly: false,
|
|
707
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(nameNode)
|
|
708
|
-
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
709
|
-
name: typeName,
|
|
710
|
-
isIndexable: true,
|
|
711
|
-
isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
|
|
712
|
-
isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
|
|
713
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
714
|
-
})] });
|
|
715
|
-
}
|
|
716
|
-
//#endregion
|
|
717
|
-
//#region src/components/v2/Type.tsx
|
|
718
|
-
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description }) {
|
|
719
|
-
const resolvedDescription = description || node?.description;
|
|
720
|
-
const enumSchemaNodes = (0, _kubb_ast.collect)(node, { schema(n) {
|
|
721
|
-
if (n.type === "enum" && n.name) return n;
|
|
722
|
-
} });
|
|
723
|
-
const typeNode = printerTs({
|
|
724
|
-
optionalType,
|
|
725
|
-
arrayType,
|
|
726
|
-
enumType,
|
|
727
|
-
typeName: name,
|
|
728
|
-
syntaxType,
|
|
729
|
-
description: resolvedDescription,
|
|
730
|
-
keysToOmit
|
|
731
|
-
}).print(node);
|
|
732
|
-
if (!typeNode) return;
|
|
733
|
-
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
734
|
-
return {
|
|
735
|
-
node,
|
|
736
|
-
...getEnumNames(node, enumType)
|
|
737
|
-
};
|
|
738
|
-
});
|
|
739
|
-
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
740
|
-
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
741
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Enum, {
|
|
742
|
-
node,
|
|
743
|
-
enumType,
|
|
744
|
-
enumKeyCasing
|
|
745
|
-
})), shouldExportType && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
746
|
-
name: typedName,
|
|
747
|
-
isTypeOnly: true,
|
|
748
|
-
isExportable: true,
|
|
749
|
-
isIndexable: true,
|
|
750
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
751
|
-
})] });
|
|
752
|
-
}
|
|
753
|
-
//#endregion
|
|
754
|
-
//#region src/resolverTs.ts
|
|
755
|
-
/**
|
|
756
|
-
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
757
|
-
* helpers used by the plugin. Import this in other plugins to resolve the exact names and
|
|
758
|
-
* paths that `plugin-ts` generates without hardcoding the conventions.
|
|
759
|
-
*
|
|
760
|
-
* The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
|
|
761
|
-
* for identifiers/files and `pascalCase` for type names.
|
|
762
|
-
*
|
|
763
|
-
* @example
|
|
764
|
-
* ```ts
|
|
765
|
-
* import { resolver } from '@kubb/plugin-ts'
|
|
766
|
-
*
|
|
767
|
-
* resolver.default('list pets', 'type') // → 'ListPets'
|
|
768
|
-
* resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
|
|
769
|
-
* resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
|
|
770
|
-
* resolver.resolvePathName('list pets', 'file') // → 'listPets'
|
|
771
|
-
* ```
|
|
772
|
-
*/
|
|
773
|
-
const resolverTs = (0, _kubb_core.defineResolver)(() => {
|
|
774
|
-
return {
|
|
775
|
-
default(name, type) {
|
|
776
|
-
return require_components.pascalCase(name, { isFile: type === "file" });
|
|
777
|
-
},
|
|
778
|
-
resolveName(name) {
|
|
779
|
-
return this.default(name, "function");
|
|
780
|
-
},
|
|
781
|
-
resolveTypedName(name) {
|
|
782
|
-
return this.default(name, "type");
|
|
783
|
-
},
|
|
784
|
-
resolvePathName(name, type) {
|
|
785
|
-
return this.default(name, type);
|
|
786
|
-
},
|
|
787
|
-
resolveParamName(node, param) {
|
|
788
|
-
return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
|
|
789
|
-
},
|
|
790
|
-
resolveParamTypedName(node, param) {
|
|
791
|
-
return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
|
|
792
|
-
},
|
|
793
|
-
resolveResponseStatusName(node, statusCode) {
|
|
794
|
-
return this.resolveName(`${node.operationId} Status ${statusCode}`);
|
|
795
|
-
},
|
|
796
|
-
resolveResponseStatusTypedName(node, statusCode) {
|
|
797
|
-
return this.resolveTypedName(`${node.operationId} Status ${statusCode}`);
|
|
798
|
-
},
|
|
799
|
-
resolveDataName(node) {
|
|
800
|
-
return this.resolveName(`${node.operationId} Data`);
|
|
801
|
-
},
|
|
802
|
-
resolveDataTypedName(node) {
|
|
803
|
-
return this.resolveTypedName(`${node.operationId} Data`);
|
|
804
|
-
},
|
|
805
|
-
resolveRequestConfigName(node) {
|
|
806
|
-
return this.resolveName(`${node.operationId} RequestConfig`);
|
|
807
|
-
},
|
|
808
|
-
resolveRequestConfigTypedName(node) {
|
|
809
|
-
return this.resolveTypedName(`${node.operationId} RequestConfig`);
|
|
810
|
-
},
|
|
811
|
-
resolveResponsesName(node) {
|
|
812
|
-
return this.resolveName(`${node.operationId} Responses`);
|
|
813
|
-
},
|
|
814
|
-
resolveResponsesTypedName(node) {
|
|
815
|
-
return this.resolveTypedName(`${node.operationId} Responses`);
|
|
816
|
-
},
|
|
817
|
-
resolveResponseName(node) {
|
|
818
|
-
return this.resolveName(`${node.operationId} Response`);
|
|
819
|
-
},
|
|
820
|
-
resolveResponseTypedName(node) {
|
|
821
|
-
return this.resolveTypedName(`${node.operationId} Response`);
|
|
822
|
-
},
|
|
823
|
-
resolveEnumKeyTypedName(node) {
|
|
824
|
-
return `${this.resolveTypedName(node.name ?? "")}Key`;
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
});
|
|
828
|
-
//#endregion
|
|
829
|
-
//#region src/generators/v2/utils.ts
|
|
830
|
-
/**
|
|
831
|
-
* Builds an `ObjectSchemaNode` for a group of parameters (path/query/header).
|
|
832
|
-
* Each property is a `ref` schema pointing to the individually-resolved parameter type.
|
|
833
|
-
* The ref name includes the parameter location so generated type names follow
|
|
834
|
-
* the `<OperationId><Location><ParamName>` convention.
|
|
835
|
-
*/
|
|
836
|
-
function buildParamsSchema({ params, operationId, resolveName }) {
|
|
837
|
-
return (0, _kubb_ast.createSchema)({
|
|
838
|
-
type: "object",
|
|
839
|
-
properties: params.map((param) => (0, _kubb_ast.createProperty)({
|
|
840
|
-
name: param.name,
|
|
841
|
-
schema: (0, _kubb_ast.createSchema)({
|
|
842
|
-
type: "ref",
|
|
843
|
-
name: resolveName({
|
|
844
|
-
name: `${operationId} ${require_components.pascalCase(param.in)} ${param.name}`,
|
|
845
|
-
type: "function"
|
|
846
|
-
}),
|
|
847
|
-
optional: !param.required
|
|
848
|
-
})
|
|
849
|
-
}))
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
/**
|
|
853
|
-
* Builds an `ObjectSchemaNode` representing the `<OperationId>RequestConfig` type:
|
|
854
|
-
* - `data` → request body ref (optional) or `never`
|
|
855
|
-
* - `pathParams` → inline object of path param refs, or `never`
|
|
856
|
-
* - `queryParams` → inline object of query param refs (optional), or `never`
|
|
857
|
-
* - `headerParams` → inline object of header param refs (optional), or `never`
|
|
858
|
-
* - `url` → Express-style template literal (plugin-ts extension, handled by printer)
|
|
859
|
-
*/
|
|
860
|
-
function buildDataSchemaNode({ node, resolveName }) {
|
|
861
|
-
const pathParams = node.parameters.filter((p) => p.in === "path");
|
|
862
|
-
const queryParams = node.parameters.filter((p) => p.in === "query");
|
|
863
|
-
const headerParams = node.parameters.filter((p) => p.in === "header");
|
|
864
|
-
return (0, _kubb_ast.createSchema)({
|
|
865
|
-
type: "object",
|
|
866
|
-
deprecated: node.deprecated,
|
|
867
|
-
properties: [
|
|
868
|
-
(0, _kubb_ast.createProperty)({
|
|
869
|
-
name: "data",
|
|
870
|
-
schema: node.requestBody ? (0, _kubb_ast.createSchema)({
|
|
871
|
-
type: "ref",
|
|
872
|
-
name: resolveName({
|
|
873
|
-
name: `${node.operationId} Data`,
|
|
874
|
-
type: "function"
|
|
875
|
-
}),
|
|
876
|
-
optional: true
|
|
877
|
-
}) : (0, _kubb_ast.createSchema)({
|
|
878
|
-
type: "never",
|
|
879
|
-
optional: true
|
|
880
|
-
})
|
|
881
|
-
}),
|
|
882
|
-
(0, _kubb_ast.createProperty)({
|
|
883
|
-
name: "pathParams",
|
|
884
|
-
schema: pathParams.length > 0 ? buildParamsSchema({
|
|
885
|
-
params: pathParams,
|
|
886
|
-
operationId: node.operationId,
|
|
887
|
-
resolveName
|
|
888
|
-
}) : (0, _kubb_ast.createSchema)({
|
|
889
|
-
type: "never",
|
|
890
|
-
optional: true
|
|
891
|
-
})
|
|
892
|
-
}),
|
|
893
|
-
(0, _kubb_ast.createProperty)({
|
|
894
|
-
name: "queryParams",
|
|
895
|
-
schema: queryParams.length > 0 ? (0, _kubb_ast.createSchema)({
|
|
896
|
-
...buildParamsSchema({
|
|
897
|
-
params: queryParams,
|
|
898
|
-
operationId: node.operationId,
|
|
899
|
-
resolveName
|
|
900
|
-
}),
|
|
901
|
-
optional: true
|
|
902
|
-
}) : (0, _kubb_ast.createSchema)({
|
|
903
|
-
type: "never",
|
|
904
|
-
optional: true
|
|
905
|
-
})
|
|
906
|
-
}),
|
|
907
|
-
(0, _kubb_ast.createProperty)({
|
|
908
|
-
name: "headerParams",
|
|
909
|
-
schema: headerParams.length > 0 ? (0, _kubb_ast.createSchema)({
|
|
910
|
-
...buildParamsSchema({
|
|
911
|
-
params: headerParams,
|
|
912
|
-
operationId: node.operationId,
|
|
913
|
-
resolveName
|
|
914
|
-
}),
|
|
915
|
-
optional: true
|
|
916
|
-
}) : (0, _kubb_ast.createSchema)({
|
|
917
|
-
type: "never",
|
|
918
|
-
optional: true
|
|
919
|
-
})
|
|
920
|
-
}),
|
|
921
|
-
(0, _kubb_ast.createProperty)({
|
|
922
|
-
name: "url",
|
|
923
|
-
schema: (0, _kubb_ast.createSchema)({
|
|
924
|
-
type: "url",
|
|
925
|
-
path: node.path
|
|
926
|
-
})
|
|
927
|
-
})
|
|
928
|
-
]
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
/**
|
|
932
|
-
* Builds an `ObjectSchemaNode` representing `<OperationId>Responses` — keyed by HTTP status code.
|
|
933
|
-
* Numeric status codes produce unquoted numeric keys (e.g. `200:`).
|
|
934
|
-
* All responses are included; those without a schema are represented as a ref to a `never` type.
|
|
935
|
-
*/
|
|
936
|
-
function buildResponsesSchemaNode({ node, resolveName }) {
|
|
937
|
-
if (node.responses.length === 0) return null;
|
|
938
|
-
return (0, _kubb_ast.createSchema)({
|
|
939
|
-
type: "object",
|
|
940
|
-
properties: node.responses.map((res) => (0, _kubb_ast.createProperty)({
|
|
941
|
-
name: String(res.statusCode),
|
|
942
|
-
schema: (0, _kubb_ast.createSchema)({
|
|
943
|
-
type: "ref",
|
|
944
|
-
name: resolveName({
|
|
945
|
-
name: `${node.operationId} Status ${res.statusCode}`,
|
|
946
|
-
type: "function"
|
|
947
|
-
})
|
|
948
|
-
})
|
|
949
|
-
}))
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* Builds a `UnionSchemaNode` representing `<OperationId>Response` — all response types in union format.
|
|
954
|
-
* Returns `null` when the operation has no responses with schemas.
|
|
955
|
-
*/
|
|
956
|
-
function buildResponseUnionSchemaNode({ node, resolveName }) {
|
|
957
|
-
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
958
|
-
if (responsesWithSchema.length === 0) return null;
|
|
959
|
-
return (0, _kubb_ast.createSchema)({
|
|
960
|
-
type: "union",
|
|
961
|
-
members: responsesWithSchema.map((res) => (0, _kubb_ast.createSchema)({
|
|
962
|
-
type: "ref",
|
|
963
|
-
name: resolveName({
|
|
964
|
-
name: `${node.operationId} Status ${res.statusCode}`,
|
|
965
|
-
type: "function"
|
|
966
|
-
})
|
|
967
|
-
}))
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
//#endregion
|
|
971
|
-
//#region src/generators/v2/typeGenerator.tsx
|
|
972
|
-
const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
973
|
-
name: "typescript",
|
|
974
|
-
type: "react",
|
|
975
|
-
Operation({ node, adapter, options }) {
|
|
976
|
-
const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group } = options;
|
|
977
|
-
const { mode, getFile, resolveName, resolveBanner, resolveFooter } = (0, _kubb_core_hooks.useKubb)();
|
|
978
|
-
const file = getFile({
|
|
979
|
-
name: node.operationId,
|
|
980
|
-
extname: ".ts",
|
|
981
|
-
mode,
|
|
982
|
-
options: { group: group ? group.type === "tag" ? { tag: node.tags[0] } : { path: node.path } : void 0 }
|
|
983
|
-
});
|
|
984
|
-
const params = (0, _kubb_ast.applyParamsCasing)(node.parameters, paramsCasing);
|
|
985
|
-
function renderSchemaType({ node: schemaNode, name, typedName, description }) {
|
|
986
|
-
if (!schemaNode) return null;
|
|
987
|
-
const imports = adapter.getImports(schemaNode, (schemaName) => ({
|
|
988
|
-
name: resolveName({
|
|
989
|
-
name: schemaName,
|
|
990
|
-
type: "type"
|
|
991
|
-
}),
|
|
992
|
-
path: getFile({
|
|
993
|
-
name: schemaName,
|
|
994
|
-
extname: ".ts",
|
|
995
|
-
mode
|
|
996
|
-
}).path
|
|
997
|
-
}));
|
|
998
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
999
|
-
root: file.path,
|
|
1000
|
-
path: imp.path,
|
|
1001
|
-
name: imp.name,
|
|
1002
|
-
isTypeOnly: true
|
|
1003
|
-
}, [
|
|
1004
|
-
name,
|
|
1005
|
-
imp.path,
|
|
1006
|
-
imp.isTypeOnly
|
|
1007
|
-
].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Type, {
|
|
1008
|
-
name,
|
|
1009
|
-
typedName,
|
|
1010
|
-
node: schemaNode,
|
|
1011
|
-
description,
|
|
1012
|
-
enumType,
|
|
1013
|
-
enumKeyCasing,
|
|
1014
|
-
optionalType,
|
|
1015
|
-
arrayType,
|
|
1016
|
-
syntaxType
|
|
1017
|
-
})] });
|
|
1018
|
-
}
|
|
1019
|
-
const paramTypes = params.map((param) => renderSchemaType({
|
|
1020
|
-
node: param.schema,
|
|
1021
|
-
name: resolverTs.resolveParamName(node, param),
|
|
1022
|
-
typedName: resolverTs.resolveParamTypedName(node, param)
|
|
1023
|
-
}));
|
|
1024
|
-
const responseTypes = node.responses.map((res) => renderSchemaType({
|
|
1025
|
-
node: res.schema,
|
|
1026
|
-
name: resolverTs.resolveResponseStatusName(node, res.statusCode),
|
|
1027
|
-
typedName: resolverTs.resolveResponseStatusTypedName(node, res.statusCode),
|
|
1028
|
-
description: res.description
|
|
1029
|
-
}));
|
|
1030
|
-
const requestType = node.requestBody ? renderSchemaType({
|
|
1031
|
-
node: node.requestBody,
|
|
1032
|
-
name: resolverTs.resolveDataName(node),
|
|
1033
|
-
typedName: resolverTs.resolveDataTypedName(node),
|
|
1034
|
-
description: node.requestBody.description
|
|
1035
|
-
}) : null;
|
|
1036
|
-
const dataType = renderSchemaType({
|
|
1037
|
-
node: buildDataSchemaNode({
|
|
1038
|
-
node: {
|
|
1039
|
-
...node,
|
|
1040
|
-
parameters: params
|
|
1041
|
-
},
|
|
1042
|
-
resolveName
|
|
1043
|
-
}),
|
|
1044
|
-
name: resolverTs.resolveRequestConfigName(node),
|
|
1045
|
-
typedName: resolverTs.resolveRequestConfigTypedName(node)
|
|
1046
|
-
});
|
|
1047
|
-
const responsesType = renderSchemaType({
|
|
1048
|
-
node: buildResponsesSchemaNode({
|
|
1049
|
-
node,
|
|
1050
|
-
resolveName
|
|
1051
|
-
}),
|
|
1052
|
-
name: resolverTs.resolveResponsesName(node),
|
|
1053
|
-
typedName: resolverTs.resolveResponsesTypedName(node)
|
|
1054
|
-
});
|
|
1055
|
-
const responseType = renderSchemaType({
|
|
1056
|
-
node: buildResponseUnionSchemaNode({
|
|
1057
|
-
node,
|
|
1058
|
-
resolveName
|
|
1059
|
-
}),
|
|
1060
|
-
name: resolverTs.resolveResponseName(node),
|
|
1061
|
-
typedName: resolverTs.resolveResponseTypedName(node),
|
|
1062
|
-
description: "Union of all possible responses"
|
|
1063
|
-
});
|
|
1064
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
1065
|
-
baseName: file.baseName,
|
|
1066
|
-
path: file.path,
|
|
1067
|
-
meta: file.meta,
|
|
1068
|
-
banner: resolveBanner(),
|
|
1069
|
-
footer: resolveFooter(),
|
|
1070
|
-
children: [
|
|
1071
|
-
paramTypes,
|
|
1072
|
-
responseTypes,
|
|
1073
|
-
requestType,
|
|
1074
|
-
dataType,
|
|
1075
|
-
responsesType,
|
|
1076
|
-
responseType
|
|
1077
|
-
]
|
|
1078
|
-
});
|
|
1079
|
-
},
|
|
1080
|
-
Schema({ node, adapter, options }) {
|
|
1081
|
-
const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType } = options;
|
|
1082
|
-
const { mode, resolveName, getFile, resolveBanner, resolveFooter } = (0, _kubb_core_hooks.useKubb)();
|
|
1083
|
-
if (!node.name) return;
|
|
1084
|
-
const imports = adapter.getImports(node, (schemaName) => ({
|
|
1085
|
-
name: resolveName({
|
|
1086
|
-
name: schemaName,
|
|
1087
|
-
type: "type"
|
|
1088
|
-
}),
|
|
1089
|
-
path: getFile({
|
|
1090
|
-
name: schemaName,
|
|
1091
|
-
extname: ".ts",
|
|
1092
|
-
mode
|
|
1093
|
-
}).path
|
|
1094
|
-
}));
|
|
1095
|
-
const isEnumSchema = node.type === "enum";
|
|
1096
|
-
const typedName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolverTs.resolveEnumKeyTypedName(node) : resolverTs.resolveTypedName(node.name);
|
|
1097
|
-
const type = {
|
|
1098
|
-
name: resolverTs.resolveName(node.name),
|
|
1099
|
-
typedName,
|
|
1100
|
-
file: getFile({
|
|
1101
|
-
name: node.name,
|
|
1102
|
-
extname: ".ts",
|
|
1103
|
-
mode
|
|
1104
|
-
})
|
|
1105
|
-
};
|
|
1106
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
1107
|
-
baseName: type.file.baseName,
|
|
1108
|
-
path: type.file.path,
|
|
1109
|
-
meta: type.file.meta,
|
|
1110
|
-
banner: resolveBanner(),
|
|
1111
|
-
footer: resolveFooter(),
|
|
1112
|
-
children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
1113
|
-
root: type.file.path,
|
|
1114
|
-
path: imp.path,
|
|
1115
|
-
name: imp.name,
|
|
1116
|
-
isTypeOnly: true
|
|
1117
|
-
}, [
|
|
1118
|
-
node.name,
|
|
1119
|
-
imp.path,
|
|
1120
|
-
imp.isTypeOnly
|
|
1121
|
-
].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Type, {
|
|
1122
|
-
name: type.name,
|
|
1123
|
-
typedName: type.typedName,
|
|
1124
|
-
node,
|
|
1125
|
-
enumType,
|
|
1126
|
-
enumKeyCasing,
|
|
1127
|
-
optionalType,
|
|
1128
|
-
arrayType,
|
|
1129
|
-
syntaxType
|
|
1130
|
-
})]
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
|
-
});
|
|
1134
|
-
//#endregion
|
|
1135
|
-
//#region src/plugin.ts
|
|
1136
|
-
const pluginTsName = "plugin-ts";
|
|
1137
|
-
const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
1138
|
-
const { output = {
|
|
1139
|
-
path: "types",
|
|
1140
|
-
barrelType: "named"
|
|
1141
|
-
}, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", enumSuffix = "enum", dateType = "string", integerType = "number", unknownType = "any", optionalType = "questionToken", arrayType = "array", emptySchemaType = unknownType, syntaxType = "type", transformers = {}, paramsCasing, generators = [typeGenerator$1, typeGenerator].filter(Boolean), contentType, UNSTABLE_NAMING } = options;
|
|
1142
|
-
return {
|
|
1143
|
-
name: pluginTsName,
|
|
1144
|
-
options: {
|
|
1145
|
-
output,
|
|
1146
|
-
transformers,
|
|
1147
|
-
dateType,
|
|
1148
|
-
integerType,
|
|
1149
|
-
optionalType,
|
|
1150
|
-
arrayType,
|
|
1151
|
-
enumType,
|
|
1152
|
-
enumKeyCasing,
|
|
1153
|
-
enumSuffix,
|
|
1154
|
-
unknownType,
|
|
1155
|
-
emptySchemaType,
|
|
1156
|
-
syntaxType,
|
|
1157
|
-
group,
|
|
1158
|
-
override,
|
|
1159
|
-
paramsCasing,
|
|
1160
|
-
usedEnumNames: {}
|
|
1161
|
-
},
|
|
1162
|
-
pre: [_kubb_plugin_oas.pluginOasName],
|
|
1163
|
-
resolvePath(baseName, pathMode, options) {
|
|
1164
|
-
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
1165
|
-
if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
|
|
1166
|
-
/**
|
|
1167
|
-
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
1168
|
-
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
1169
|
-
*/
|
|
1170
|
-
return node_path.default.resolve(root, output.path);
|
|
1171
|
-
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
1172
|
-
const groupName = group?.name ? group.name : (ctx) => {
|
|
1173
|
-
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
1174
|
-
return `${require_components.camelCase(ctx.group)}Controller`;
|
|
1175
|
-
};
|
|
1176
|
-
return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
|
|
1177
|
-
}
|
|
1178
|
-
return node_path.default.resolve(root, output.path, baseName);
|
|
1179
|
-
},
|
|
1180
|
-
resolveName(name, type) {
|
|
1181
|
-
const resolvedName = resolverTs.default(name, type);
|
|
1182
|
-
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
1183
|
-
return resolvedName;
|
|
1184
|
-
},
|
|
1185
|
-
async install() {
|
|
1186
|
-
const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this;
|
|
1187
|
-
const root = node_path.default.resolve(config.root, config.output.path);
|
|
1188
|
-
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
1189
|
-
if (adapter) {
|
|
1190
|
-
await openInStudio({ ast: true });
|
|
1191
|
-
await (0, _kubb_ast.walk)(rootNode, {
|
|
1192
|
-
async schema(schemaNode) {
|
|
1193
|
-
const writeTasks = generators.map(async (generator) => {
|
|
1194
|
-
if (generator.type === "react" && generator.version === "2") {
|
|
1195
|
-
const options = resolverTs.resolveOptions(schemaNode, {
|
|
1196
|
-
options: plugin.options,
|
|
1197
|
-
exclude,
|
|
1198
|
-
include,
|
|
1199
|
-
override
|
|
1200
|
-
});
|
|
1201
|
-
if (options === null) return;
|
|
1202
|
-
await (0, _kubb_core.renderSchema)(schemaNode, {
|
|
1203
|
-
options,
|
|
1204
|
-
adapter,
|
|
1205
|
-
config,
|
|
1206
|
-
fabric,
|
|
1207
|
-
Component: generator.Schema,
|
|
1208
|
-
plugin,
|
|
1209
|
-
driver,
|
|
1210
|
-
mode
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
});
|
|
1214
|
-
await Promise.all(writeTasks);
|
|
1215
|
-
},
|
|
1216
|
-
async operation(operationNode) {
|
|
1217
|
-
const writeTasks = generators.map(async (generator) => {
|
|
1218
|
-
if (generator.type === "react" && generator.version === "2") {
|
|
1219
|
-
const options = resolverTs.resolveOptions(operationNode, {
|
|
1220
|
-
options: plugin.options,
|
|
1221
|
-
exclude,
|
|
1222
|
-
include,
|
|
1223
|
-
override
|
|
1224
|
-
});
|
|
1225
|
-
if (options === null) return;
|
|
1226
|
-
await (0, _kubb_core.renderOperation)(operationNode, {
|
|
1227
|
-
options,
|
|
1228
|
-
adapter,
|
|
1229
|
-
config,
|
|
1230
|
-
fabric,
|
|
1231
|
-
Component: generator.Operation,
|
|
1232
|
-
plugin,
|
|
1233
|
-
driver,
|
|
1234
|
-
mode
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
});
|
|
1238
|
-
await Promise.all(writeTasks);
|
|
1239
|
-
}
|
|
1240
|
-
}, { depth: "shallow" });
|
|
1241
|
-
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
1242
|
-
type: output.barrelType ?? "named",
|
|
1243
|
-
root,
|
|
1244
|
-
output,
|
|
1245
|
-
meta: { pluginName: this.plugin.name }
|
|
1246
|
-
});
|
|
1247
|
-
await this.upsertFile(...barrelFiles);
|
|
1248
|
-
return;
|
|
1249
|
-
}
|
|
1250
|
-
const oas = await this.getOas();
|
|
1251
|
-
const schemaFiles = await new _kubb_plugin_oas.SchemaGenerator(this.plugin.options, {
|
|
1252
|
-
fabric: this.fabric,
|
|
1253
|
-
oas,
|
|
1254
|
-
driver: this.driver,
|
|
1255
|
-
events: this.events,
|
|
1256
|
-
plugin: this.plugin,
|
|
1257
|
-
contentType,
|
|
1258
|
-
include: void 0,
|
|
1259
|
-
override,
|
|
1260
|
-
mode,
|
|
1261
|
-
output: output.path
|
|
1262
|
-
}).build(...generators);
|
|
1263
|
-
await this.upsertFile(...schemaFiles);
|
|
1264
|
-
const operationFiles = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
1265
|
-
fabric: this.fabric,
|
|
1266
|
-
oas,
|
|
1267
|
-
driver: this.driver,
|
|
1268
|
-
events: this.events,
|
|
1269
|
-
plugin: this.plugin,
|
|
1270
|
-
contentType,
|
|
1271
|
-
exclude,
|
|
1272
|
-
include,
|
|
1273
|
-
override,
|
|
1274
|
-
mode,
|
|
1275
|
-
UNSTABLE_NAMING
|
|
1276
|
-
}).build(...generators);
|
|
1277
|
-
await this.upsertFile(...operationFiles);
|
|
1278
|
-
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
1279
|
-
type: output.barrelType ?? "named",
|
|
1280
|
-
root,
|
|
1281
|
-
output,
|
|
1282
|
-
meta: { pluginName: this.plugin.name }
|
|
1283
|
-
});
|
|
1284
|
-
await this.upsertFile(...barrelFiles);
|
|
1285
|
-
}
|
|
1286
|
-
};
|
|
1287
|
-
});
|
|
1288
|
-
//#endregion
|
|
1289
|
-
Object.defineProperty(exports, "pluginTs", {
|
|
1290
|
-
enumerable: true,
|
|
1291
|
-
get: function() {
|
|
1292
|
-
return pluginTs;
|
|
1293
|
-
}
|
|
1294
|
-
});
|
|
1295
|
-
Object.defineProperty(exports, "pluginTsName", {
|
|
1296
|
-
enumerable: true,
|
|
1297
|
-
get: function() {
|
|
1298
|
-
return pluginTsName;
|
|
1299
|
-
}
|
|
1300
|
-
});
|
|
1301
|
-
Object.defineProperty(exports, "resolverTs", {
|
|
1302
|
-
enumerable: true,
|
|
1303
|
-
get: function() {
|
|
1304
|
-
return resolverTs;
|
|
1305
|
-
}
|
|
1306
|
-
});
|
|
1307
|
-
Object.defineProperty(exports, "typeGenerator", {
|
|
1308
|
-
enumerable: true,
|
|
1309
|
-
get: function() {
|
|
1310
|
-
return typeGenerator;
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
Object.defineProperty(exports, "typeGenerator$1", {
|
|
1314
|
-
enumerable: true,
|
|
1315
|
-
get: function() {
|
|
1316
|
-
return typeGenerator$1;
|
|
1317
|
-
}
|
|
1318
|
-
});
|
|
1319
|
-
|
|
1320
|
-
//# sourceMappingURL=plugin-CJ29AwE2.cjs.map
|