@kubb/plugin-ts 5.0.0-alpha.5 → 5.0.0-alpha.7
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-Cwn1rflQ.js → components-CRu8IKY3.js} +4 -6
- package/dist/{components-Cwn1rflQ.js.map → components-CRu8IKY3.js.map} +1 -1
- package/dist/{components-CxTvawXI.cjs → components-DeNDKlzf.cjs} +4 -6
- package/dist/components-DeNDKlzf.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -3
- package/dist/components.js +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +4 -4
- package/dist/generators.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{plugin-meWNDVe7.cjs → plugin-Cn85VLXR.cjs} +329 -248
- package/dist/plugin-Cn85VLXR.cjs.map +1 -0
- package/dist/{plugin-kdQ5D2cW.js → plugin-DVhVzwDg.js} +327 -245
- package/dist/plugin-DVhVzwDg.js.map +1 -0
- package/dist/{types-eWhVEVgF.d.ts → types-CsvB6X5Y.d.ts} +1 -14
- package/package.json +5 -5
- package/src/components/Type.tsx +0 -3
- package/src/components/v2/Enum.tsx +67 -0
- package/src/components/v2/Type.tsx +11 -130
- package/src/constants.ts +29 -0
- package/src/generators/typeGenerator.tsx +30 -32
- package/src/generators/v2/typeGenerator.tsx +22 -14
- package/src/generators/v2/utils.ts +10 -15
- package/src/parser.ts +1 -8
- package/src/plugin.ts +5 -7
- package/src/printer.ts +229 -119
- package/src/types.ts +0 -13
- package/dist/components-CxTvawXI.cjs.map +0 -1
- package/dist/plugin-kdQ5D2cW.js.map +0 -1
- package/dist/plugin-meWNDVe7.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_components = require("./components-
|
|
1
|
+
const require_components = require("./components-DeNDKlzf.cjs");
|
|
2
2
|
let node_path = require("node:path");
|
|
3
3
|
node_path = require_components.__toESM(node_path);
|
|
4
4
|
let _kubb_ast = require("@kubb/ast");
|
|
@@ -27,10 +27,10 @@ function stringify(value) {
|
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/generators/typeGenerator.tsx
|
|
30
|
-
function printCombinedSchema({ name, schemas,
|
|
30
|
+
function printCombinedSchema({ name, schemas, driver }) {
|
|
31
31
|
const properties = {};
|
|
32
32
|
if (schemas.response) properties["response"] = require_components.createUnionDeclaration({ nodes: schemas.responses.map((res) => {
|
|
33
|
-
const identifier =
|
|
33
|
+
const identifier = driver.resolveName({
|
|
34
34
|
name: res.name,
|
|
35
35
|
pluginName: pluginTsName,
|
|
36
36
|
type: "function"
|
|
@@ -38,7 +38,7 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
|
|
|
38
38
|
return require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
39
39
|
}) });
|
|
40
40
|
if (schemas.request) {
|
|
41
|
-
const identifier =
|
|
41
|
+
const identifier = driver.resolveName({
|
|
42
42
|
name: schemas.request.name,
|
|
43
43
|
pluginName: pluginTsName,
|
|
44
44
|
type: "function"
|
|
@@ -46,7 +46,7 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
|
|
|
46
46
|
properties["request"] = require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
47
47
|
}
|
|
48
48
|
if (schemas.pathParams) {
|
|
49
|
-
const identifier =
|
|
49
|
+
const identifier = driver.resolveName({
|
|
50
50
|
name: schemas.pathParams.name,
|
|
51
51
|
pluginName: pluginTsName,
|
|
52
52
|
type: "function"
|
|
@@ -54,7 +54,7 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
|
|
|
54
54
|
properties["pathParams"] = require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
55
55
|
}
|
|
56
56
|
if (schemas.queryParams) {
|
|
57
|
-
const identifier =
|
|
57
|
+
const identifier = driver.resolveName({
|
|
58
58
|
name: schemas.queryParams.name,
|
|
59
59
|
pluginName: pluginTsName,
|
|
60
60
|
type: "function"
|
|
@@ -62,7 +62,7 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
|
|
|
62
62
|
properties["queryParams"] = require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
63
63
|
}
|
|
64
64
|
if (schemas.headerParams) {
|
|
65
|
-
const identifier =
|
|
65
|
+
const identifier = driver.resolveName({
|
|
66
66
|
name: schemas.headerParams.name,
|
|
67
67
|
pluginName: pluginTsName,
|
|
68
68
|
type: "function"
|
|
@@ -70,7 +70,7 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
|
|
|
70
70
|
properties["headerParams"] = require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
|
|
71
71
|
}
|
|
72
72
|
if (schemas.errors) properties["errors"] = require_components.createUnionDeclaration({ nodes: schemas.errors.map((error) => {
|
|
73
|
-
const identifier =
|
|
73
|
+
const identifier = driver.resolveName({
|
|
74
74
|
name: error.name,
|
|
75
75
|
pluginName: pluginTsName,
|
|
76
76
|
type: "function"
|
|
@@ -90,8 +90,8 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
|
|
|
90
90
|
modifiers: [require_components.modifiers.export]
|
|
91
91
|
}));
|
|
92
92
|
}
|
|
93
|
-
function printRequestSchema({ baseName, operation, schemas,
|
|
94
|
-
const name =
|
|
93
|
+
function printRequestSchema({ baseName, operation, schemas, driver }) {
|
|
94
|
+
const name = driver.resolveName({
|
|
95
95
|
name: `${baseName} Request`,
|
|
96
96
|
pluginName: pluginTsName,
|
|
97
97
|
type: "type"
|
|
@@ -99,7 +99,7 @@ function printRequestSchema({ baseName, operation, schemas, pluginManager }) {
|
|
|
99
99
|
const results = [];
|
|
100
100
|
const dataRequestProperties = [];
|
|
101
101
|
if (schemas.request) {
|
|
102
|
-
const identifier =
|
|
102
|
+
const identifier = driver.resolveName({
|
|
103
103
|
name: schemas.request.name,
|
|
104
104
|
pluginName: pluginTsName,
|
|
105
105
|
type: "type"
|
|
@@ -115,7 +115,7 @@ function printRequestSchema({ baseName, operation, schemas, pluginManager }) {
|
|
|
115
115
|
type: require_components.keywordTypeNodes.never
|
|
116
116
|
}));
|
|
117
117
|
if (schemas.pathParams) {
|
|
118
|
-
const identifier =
|
|
118
|
+
const identifier = driver.resolveName({
|
|
119
119
|
name: schemas.pathParams.name,
|
|
120
120
|
pluginName: pluginTsName,
|
|
121
121
|
type: "type"
|
|
@@ -130,7 +130,7 @@ function printRequestSchema({ baseName, operation, schemas, pluginManager }) {
|
|
|
130
130
|
type: require_components.keywordTypeNodes.never
|
|
131
131
|
}));
|
|
132
132
|
if (schemas.queryParams) {
|
|
133
|
-
const identifier =
|
|
133
|
+
const identifier = driver.resolveName({
|
|
134
134
|
name: schemas.queryParams.name,
|
|
135
135
|
pluginName: pluginTsName,
|
|
136
136
|
type: "type"
|
|
@@ -146,7 +146,7 @@ function printRequestSchema({ baseName, operation, schemas, pluginManager }) {
|
|
|
146
146
|
type: require_components.keywordTypeNodes.never
|
|
147
147
|
}));
|
|
148
148
|
if (schemas.headerParams) {
|
|
149
|
-
const identifier =
|
|
149
|
+
const identifier = driver.resolveName({
|
|
150
150
|
name: schemas.headerParams.name,
|
|
151
151
|
pluginName: pluginTsName,
|
|
152
152
|
type: "type"
|
|
@@ -173,16 +173,16 @@ function printRequestSchema({ baseName, operation, schemas, pluginManager }) {
|
|
|
173
173
|
results.push((0, _kubb_fabric_core_parsers_typescript.safePrint)(dataRequestNode));
|
|
174
174
|
return results.join("\n\n");
|
|
175
175
|
}
|
|
176
|
-
function printResponseSchema({ baseName, schemas,
|
|
176
|
+
function printResponseSchema({ baseName, schemas, driver, unknownType }) {
|
|
177
177
|
const results = [];
|
|
178
|
-
const name =
|
|
178
|
+
const name = driver.resolveName({
|
|
179
179
|
name: `${baseName} ResponseData`,
|
|
180
180
|
pluginName: pluginTsName,
|
|
181
181
|
type: "type"
|
|
182
182
|
});
|
|
183
183
|
if (schemas.responses && schemas.responses.length > 0) {
|
|
184
184
|
const responsesProperties = schemas.responses.map((res) => {
|
|
185
|
-
const identifier =
|
|
185
|
+
const identifier = driver.resolveName({
|
|
186
186
|
name: res.name,
|
|
187
187
|
pluginName: pluginTsName,
|
|
188
188
|
type: "type"
|
|
@@ -217,9 +217,9 @@ function printResponseSchema({ baseName, schemas, pluginManager, unknownType })
|
|
|
217
217
|
const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
218
218
|
name: "typescript",
|
|
219
219
|
Operation({ operation, generator, plugin }) {
|
|
220
|
-
const { options, options: {
|
|
220
|
+
const { options, options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, unknownType, paramsCasing } } = plugin;
|
|
221
221
|
const mode = (0, _kubb_core_hooks.useMode)();
|
|
222
|
-
const
|
|
222
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
223
223
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
224
224
|
const { getSchemas, getFile, getName, getGroup } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
225
225
|
const schemaManager = (0, _kubb_plugin_oas_hooks.useSchemaManager)();
|
|
@@ -234,7 +234,7 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
234
234
|
oas,
|
|
235
235
|
events: generator.context.events,
|
|
236
236
|
plugin,
|
|
237
|
-
|
|
237
|
+
driver,
|
|
238
238
|
mode,
|
|
239
239
|
override: options.override
|
|
240
240
|
});
|
|
@@ -276,7 +276,6 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
276
276
|
description,
|
|
277
277
|
tree,
|
|
278
278
|
schema: transformedSchema,
|
|
279
|
-
mapper,
|
|
280
279
|
enumType,
|
|
281
280
|
enumKeyCasing,
|
|
282
281
|
optionalType,
|
|
@@ -294,7 +293,7 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
294
293
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
295
294
|
oas,
|
|
296
295
|
output: plugin.options.output,
|
|
297
|
-
config:
|
|
296
|
+
config: driver.config
|
|
298
297
|
}),
|
|
299
298
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
300
299
|
oas,
|
|
@@ -309,7 +308,7 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
309
308
|
baseName: name,
|
|
310
309
|
operation,
|
|
311
310
|
schemas,
|
|
312
|
-
|
|
311
|
+
driver
|
|
313
312
|
})
|
|
314
313
|
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
315
314
|
name: responseName,
|
|
@@ -319,7 +318,7 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
319
318
|
children: printResponseSchema({
|
|
320
319
|
baseName: name,
|
|
321
320
|
schemas,
|
|
322
|
-
|
|
321
|
+
driver,
|
|
323
322
|
unknownType
|
|
324
323
|
})
|
|
325
324
|
})] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
@@ -330,16 +329,16 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
330
329
|
children: printCombinedSchema({
|
|
331
330
|
name: combinedSchemaName,
|
|
332
331
|
schemas,
|
|
333
|
-
|
|
332
|
+
driver
|
|
334
333
|
})
|
|
335
334
|
})]
|
|
336
335
|
});
|
|
337
336
|
},
|
|
338
337
|
Schema({ schema, plugin }) {
|
|
339
|
-
const { options: {
|
|
338
|
+
const { options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, output } } = plugin;
|
|
340
339
|
const mode = (0, _kubb_core_hooks.useMode)();
|
|
341
340
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
342
|
-
const
|
|
341
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
343
342
|
const { getName, getFile } = (0, _kubb_plugin_oas_hooks.useSchemaManager)();
|
|
344
343
|
const imports = (0, _kubb_plugin_oas_utils.getImports)(schema.tree);
|
|
345
344
|
const schemaFromTree = schema.tree.find((item) => item.keyword === _kubb_plugin_oas.schemaKeywords.schema);
|
|
@@ -357,7 +356,7 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
357
356
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
358
357
|
oas,
|
|
359
358
|
output,
|
|
360
|
-
config:
|
|
359
|
+
config: driver.config
|
|
361
360
|
}),
|
|
362
361
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
363
362
|
oas,
|
|
@@ -378,7 +377,6 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
378
377
|
description: schema.value.description,
|
|
379
378
|
tree: schema.tree,
|
|
380
379
|
schema: schema.value,
|
|
381
|
-
mapper,
|
|
382
380
|
enumType,
|
|
383
381
|
enumKeyCasing,
|
|
384
382
|
optionalType,
|
|
@@ -389,7 +387,45 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
389
387
|
}
|
|
390
388
|
});
|
|
391
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
|
|
392
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
|
+
*/
|
|
393
429
|
function constToTypeNode(value, format) {
|
|
394
430
|
if (format === "boolean") return require_components.createLiteralTypeNode(value === true ? require_components.createTrue() : require_components.createFalse());
|
|
395
431
|
if (format === "number" && typeof value === "number") {
|
|
@@ -398,12 +434,22 @@ function constToTypeNode(value, format) {
|
|
|
398
434
|
}
|
|
399
435
|
return require_components.createLiteralTypeNode(require_components.createStringLiteral(String(value)));
|
|
400
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* Returns a `Date` reference type node when `representation` is `'date'`, otherwise falls back to `string`.
|
|
439
|
+
*/
|
|
401
440
|
function dateOrStringNode(node) {
|
|
402
441
|
return node.representation === "date" ? require_components.createTypeReferenceNode(require_components.createIdentifier("Date")) : require_components.keywordTypeNodes.string;
|
|
403
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* Maps an array of `SchemaNode`s through the printer, filtering out `null` and `undefined` results.
|
|
445
|
+
*/
|
|
404
446
|
function buildMemberNodes(members, print) {
|
|
405
447
|
return (members ?? []).map(print).filter(Boolean);
|
|
406
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
|
+
*/
|
|
407
453
|
function buildTupleNode(node, print) {
|
|
408
454
|
let items = (node.items ?? []).map(print).filter(Boolean);
|
|
409
455
|
const restNode = node.rest ? print(node.rest) ?? void 0 : void 0;
|
|
@@ -416,13 +462,19 @@ function buildTupleNode(node, print) {
|
|
|
416
462
|
if (max === void 0 && restNode) items.push(require_components.createRestTypeNode(require_components.createArrayTypeNode(restNode)));
|
|
417
463
|
return require_components.createTupleTypeNode(items);
|
|
418
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* Applies `nullable` and optional/nullish `| undefined` union modifiers to a property's resolved base type.
|
|
467
|
+
*/
|
|
419
468
|
function buildPropertyType(schema, baseType, optionalType) {
|
|
420
|
-
const addsUndefined =
|
|
469
|
+
const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
|
|
421
470
|
let type = baseType;
|
|
422
471
|
if (schema.nullable) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.null] });
|
|
423
472
|
if ((schema.nullish || schema.optional) && addsUndefined) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.undefined] });
|
|
424
473
|
return type;
|
|
425
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Collects JSDoc annotation strings (description, deprecated, min/max, pattern, default, example, type) for a schema node.
|
|
477
|
+
*/
|
|
426
478
|
function buildPropertyJSDocComments(schema) {
|
|
427
479
|
return [
|
|
428
480
|
"description" in schema && schema.description ? `@description ${require_components.jsStringEscape(schema.description)}` : void 0,
|
|
@@ -435,6 +487,9 @@ function buildPropertyJSDocComments(schema) {
|
|
|
435
487
|
"primitive" in schema && schema.primitive ? [`@type ${schema.primitive || "unknown"}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
|
|
436
488
|
];
|
|
437
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Creates TypeScript index signatures for `additionalProperties` and `patternProperties` on an object schema node.
|
|
492
|
+
*/
|
|
438
493
|
function buildIndexSignatures(node, propertyCount, print) {
|
|
439
494
|
const elements = [];
|
|
440
495
|
if (node.additionalProperties && node.additionalProperties !== true) {
|
|
@@ -452,214 +507,247 @@ function buildIndexSignatures(node, propertyCount, print) {
|
|
|
452
507
|
return elements;
|
|
453
508
|
}
|
|
454
509
|
/**
|
|
455
|
-
*
|
|
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.
|
|
456
516
|
*
|
|
457
|
-
*
|
|
458
|
-
* per printer instance
|
|
459
|
-
*
|
|
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
|
+
* ```
|
|
460
531
|
*/
|
|
461
|
-
const printerTs = (0, _kubb_core.definePrinter)((options) =>
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const
|
|
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");
|
|
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
|
+
}
|
|
493
592
|
return require_components.createUnionDeclaration({
|
|
494
593
|
withParentheses: true,
|
|
495
|
-
nodes:
|
|
594
|
+
nodes: buildMemberNodes(members, this.print)
|
|
496
595
|
}) ?? void 0;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
},
|
|
501
|
-
union(node) {
|
|
502
|
-
const members = node.members ?? [];
|
|
503
|
-
const hasStringLiteral = members.some((m) => m.type === "enum" && m.enumType === "string");
|
|
504
|
-
const hasPlainString = members.some((m) => (0, _kubb_ast.isPlainStringType)(m));
|
|
505
|
-
if (hasStringLiteral && hasPlainString) {
|
|
506
|
-
const nodes = members.map((m) => {
|
|
507
|
-
if ((0, _kubb_ast.isPlainStringType)(m)) return require_components.createIntersectionDeclaration({
|
|
508
|
-
nodes: [require_components.keywordTypeNodes.string, require_components.createTypeLiteralNode([])],
|
|
509
|
-
withParentheses: true
|
|
510
|
-
});
|
|
511
|
-
return this.print(m);
|
|
512
|
-
}).filter(Boolean);
|
|
513
|
-
return require_components.createUnionDeclaration({
|
|
596
|
+
},
|
|
597
|
+
intersection(node) {
|
|
598
|
+
return require_components.createIntersectionDeclaration({
|
|
514
599
|
withParentheses: true,
|
|
515
|
-
nodes
|
|
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
|
|
516
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);
|
|
517
633
|
}
|
|
518
|
-
return require_components.createUnionDeclaration({
|
|
519
|
-
withParentheses: true,
|
|
520
|
-
nodes: buildMemberNodes(members, this.print)
|
|
521
|
-
}) ?? void 0;
|
|
522
|
-
},
|
|
523
|
-
intersection(node) {
|
|
524
|
-
return require_components.createIntersectionDeclaration({
|
|
525
|
-
withParentheses: true,
|
|
526
|
-
nodes: buildMemberNodes(node.members, this.print)
|
|
527
|
-
}) ?? void 0;
|
|
528
|
-
},
|
|
529
|
-
array(node) {
|
|
530
|
-
const itemNodes = (node.items ?? []).map((item) => this.print(item)).filter(Boolean);
|
|
531
|
-
return require_components.createArrayDeclaration({
|
|
532
|
-
nodes: itemNodes,
|
|
533
|
-
arrayType: this.options.arrayType
|
|
534
|
-
}) ?? void 0;
|
|
535
634
|
},
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
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,
|
|
549
648
|
type,
|
|
550
|
-
|
|
551
|
-
})
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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
|
+
]
|
|
556
662
|
});
|
|
557
|
-
const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
|
|
558
|
-
if (!allElements.length) return require_components.keywordTypeNodes.object;
|
|
559
|
-
return require_components.createTypeLiteralNode(allElements);
|
|
560
663
|
}
|
|
561
|
-
}
|
|
562
|
-
})
|
|
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
|
+
}
|
|
563
716
|
//#endregion
|
|
564
717
|
//#region src/components/v2/Type.tsx
|
|
565
|
-
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing,
|
|
566
|
-
const
|
|
567
|
-
const description = rest.description || node?.description;
|
|
718
|
+
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description }) {
|
|
719
|
+
const resolvedDescription = description || node?.description;
|
|
568
720
|
const enumSchemaNodes = (0, _kubb_ast.collect)(node, { schema(n) {
|
|
569
721
|
if (n.type === "enum" && n.name) return n;
|
|
570
722
|
} });
|
|
571
|
-
|
|
723
|
+
const typeNode = printerTs({
|
|
572
724
|
optionalType,
|
|
573
725
|
arrayType,
|
|
574
726
|
enumType,
|
|
575
|
-
|
|
727
|
+
typeName: name,
|
|
728
|
+
syntaxType,
|
|
729
|
+
description: resolvedDescription,
|
|
730
|
+
keysToOmit
|
|
576
731
|
}).print(node);
|
|
577
|
-
if (!
|
|
578
|
-
|
|
579
|
-
const isDirectEnum = node.type === "array" && node.items !== void 0;
|
|
580
|
-
const isEnumOnly = "enum" in node && node.enum;
|
|
581
|
-
if (isDirectEnum || isEnumOnly) {
|
|
582
|
-
const typeNameWithKey = `${enumSchemaNodes[0].name}Key`;
|
|
583
|
-
type = require_components.createTypeReferenceNode(typeNameWithKey);
|
|
584
|
-
if (isDirectEnum) if (arrayType === "generic") type = require_components.createTypeReferenceNode(require_components.createIdentifier("Array"), [type]);
|
|
585
|
-
else type = require_components.createArrayTypeNode(type);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
if (node) {
|
|
589
|
-
if (node.nullable) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.null] });
|
|
590
|
-
if (node.nullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.undefined] });
|
|
591
|
-
if (node.optional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.undefined] });
|
|
592
|
-
}
|
|
593
|
-
const useTypeGeneration = syntaxType === "type" || [require_components.syntaxKind.union].includes(type.kind) || !!keysToOmit?.length;
|
|
594
|
-
typeNodes.push(require_components.createTypeDeclaration({
|
|
595
|
-
name,
|
|
596
|
-
isExportable: true,
|
|
597
|
-
type: keysToOmit?.length ? require_components.createOmitDeclaration({
|
|
598
|
-
keys: keysToOmit,
|
|
599
|
-
type,
|
|
600
|
-
nonNullable: true
|
|
601
|
-
}) : type,
|
|
602
|
-
syntax: useTypeGeneration ? "type" : "interface",
|
|
603
|
-
comments: [
|
|
604
|
-
node?.title ? `${require_components.jsStringEscape(node.title)}` : void 0,
|
|
605
|
-
description ? `@description ${require_components.jsStringEscape(description)}` : void 0,
|
|
606
|
-
node?.deprecated ? "@deprecated" : void 0,
|
|
607
|
-
node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
|
|
608
|
-
node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
|
|
609
|
-
node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
|
|
610
|
-
node?.default ? `@default ${node.default}` : void 0,
|
|
611
|
-
node?.example ? `@example ${node.example}` : void 0
|
|
612
|
-
]
|
|
613
|
-
}));
|
|
614
|
-
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((enumSchemaNode) => {
|
|
615
|
-
const enumName = enumType === "asPascalConst" ? require_components.pascalCase(enumSchemaNode.name) : require_components.camelCase(enumSchemaNode.name);
|
|
616
|
-
const typeName = ["asConst", "asPascalConst"].includes(enumType) ? `${enumSchemaNode.name}Key` : enumSchemaNode.name;
|
|
617
|
-
const [nameNode, typeNode] = require_components.createEnumDeclaration({
|
|
618
|
-
name: enumName,
|
|
619
|
-
typeName,
|
|
620
|
-
enums: enumSchemaNode.namedEnumValues?.map((v) => [require_components.trimQuotes(v.name.toString()), v.value]) ?? enumSchemaNode.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [require_components.trimQuotes(v.toString()), v]) ?? [],
|
|
621
|
-
type: enumType,
|
|
622
|
-
enumKeyCasing
|
|
623
|
-
});
|
|
732
|
+
if (!typeNode) return;
|
|
733
|
+
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
624
734
|
return {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
name: enumName,
|
|
628
|
-
typeName
|
|
735
|
+
node,
|
|
736
|
+
...getEnumNames(node, enumType)
|
|
629
737
|
};
|
|
630
738
|
});
|
|
631
739
|
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
632
740
|
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
633
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(nameNode)
|
|
639
|
-
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
640
|
-
name: typeName,
|
|
641
|
-
isIndexable: true,
|
|
642
|
-
isExportable: [
|
|
643
|
-
"enum",
|
|
644
|
-
"asConst",
|
|
645
|
-
"asPascalConst",
|
|
646
|
-
"constEnum",
|
|
647
|
-
"literal",
|
|
648
|
-
void 0
|
|
649
|
-
].includes(enumType),
|
|
650
|
-
isTypeOnly: [
|
|
651
|
-
"asConst",
|
|
652
|
-
"asPascalConst",
|
|
653
|
-
"literal",
|
|
654
|
-
void 0
|
|
655
|
-
].includes(enumType),
|
|
656
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
657
|
-
})] })), shouldExportType && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
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, {
|
|
658
746
|
name: typedName,
|
|
659
747
|
isTypeOnly: true,
|
|
660
748
|
isExportable: true,
|
|
661
749
|
isIndexable: true,
|
|
662
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(
|
|
750
|
+
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
663
751
|
})] });
|
|
664
752
|
}
|
|
665
753
|
//#endregion
|
|
@@ -667,6 +755,8 @@ function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, synt
|
|
|
667
755
|
/**
|
|
668
756
|
* Builds an `ObjectSchemaNode` for a group of parameters (path/query/header).
|
|
669
757
|
* Each property is a `ref` schema pointing to the individually-resolved parameter type.
|
|
758
|
+
* The ref name includes the parameter location so generated type names follow
|
|
759
|
+
* the `<OperationId><Location><ParamName>` convention.
|
|
670
760
|
*/
|
|
671
761
|
function buildParamsSchema({ params, operationId, resolveName }) {
|
|
672
762
|
return (0, _kubb_ast.createSchema)({
|
|
@@ -676,7 +766,7 @@ function buildParamsSchema({ params, operationId, resolveName }) {
|
|
|
676
766
|
schema: (0, _kubb_ast.createSchema)({
|
|
677
767
|
type: "ref",
|
|
678
768
|
name: resolveName({
|
|
679
|
-
name: `${operationId} ${param.name}`,
|
|
769
|
+
name: `${operationId} ${require_components.pascalCase(param.in)} ${param.name}`,
|
|
680
770
|
type: "function"
|
|
681
771
|
}),
|
|
682
772
|
optional: !param.required
|
|
@@ -685,7 +775,7 @@ function buildParamsSchema({ params, operationId, resolveName }) {
|
|
|
685
775
|
});
|
|
686
776
|
}
|
|
687
777
|
/**
|
|
688
|
-
* Builds an `ObjectSchemaNode` representing the `<OperationId>
|
|
778
|
+
* Builds an `ObjectSchemaNode` representing the `<OperationId>RequestConfig` type:
|
|
689
779
|
* - `data` → request body ref (optional) or `never`
|
|
690
780
|
* - `pathParams` → inline object of path param refs, or `never`
|
|
691
781
|
* - `queryParams` → inline object of query param refs (optional), or `never`
|
|
@@ -704,7 +794,7 @@ function buildDataSchemaNode({ node, resolveName }) {
|
|
|
704
794
|
schema: node.requestBody ? (0, _kubb_ast.createSchema)({
|
|
705
795
|
type: "ref",
|
|
706
796
|
name: resolveName({
|
|
707
|
-
name: `${node.operationId}
|
|
797
|
+
name: `${node.operationId} Data`,
|
|
708
798
|
type: "function"
|
|
709
799
|
}),
|
|
710
800
|
optional: true
|
|
@@ -764,11 +854,7 @@ function buildDataSchemaNode({ node, resolveName }) {
|
|
|
764
854
|
}
|
|
765
855
|
/**
|
|
766
856
|
* Builds an `ObjectSchemaNode` representing `<OperationId>Responses` — keyed by HTTP status code.
|
|
767
|
-
*
|
|
768
|
-
* Example output:
|
|
769
|
-
* ```ts
|
|
770
|
-
* export type PlaceOrderPatchResponses = { 200: PlaceOrderPatch200; 405: PlaceOrderPatch405 }
|
|
771
|
-
* ```
|
|
857
|
+
* Numeric status codes produce unquoted numeric keys (e.g. `200:`).
|
|
772
858
|
*/
|
|
773
859
|
function buildResponsesSchemaNode({ node, resolveName }) {
|
|
774
860
|
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
@@ -780,7 +866,7 @@ function buildResponsesSchemaNode({ node, resolveName }) {
|
|
|
780
866
|
schema: (0, _kubb_ast.createSchema)({
|
|
781
867
|
type: "ref",
|
|
782
868
|
name: resolveName({
|
|
783
|
-
name: `${node.operationId} ${res.statusCode}`,
|
|
869
|
+
name: `${node.operationId} Status ${res.statusCode}`,
|
|
784
870
|
type: "function"
|
|
785
871
|
})
|
|
786
872
|
})
|
|
@@ -789,11 +875,7 @@ function buildResponsesSchemaNode({ node, resolveName }) {
|
|
|
789
875
|
}
|
|
790
876
|
/**
|
|
791
877
|
* Builds a `UnionSchemaNode` representing `<OperationId>Response` — all response types in union format.
|
|
792
|
-
*
|
|
793
|
-
* Example output:
|
|
794
|
-
* ```ts
|
|
795
|
-
* export type PlaceOrderPatchResponse = PlaceOrderPatch200 | PlaceOrderPatch405
|
|
796
|
-
* ```
|
|
878
|
+
* Returns `null` when the operation has no responses with schemas.
|
|
797
879
|
*/
|
|
798
880
|
function buildResponseUnionSchemaNode({ node, resolveName }) {
|
|
799
881
|
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
@@ -803,7 +885,7 @@ function buildResponseUnionSchemaNode({ node, resolveName }) {
|
|
|
803
885
|
members: responsesWithSchema.map((res) => (0, _kubb_ast.createSchema)({
|
|
804
886
|
type: "ref",
|
|
805
887
|
name: resolveName({
|
|
806
|
-
name: `${node.operationId} ${res.statusCode}`,
|
|
888
|
+
name: `${node.operationId} Status ${res.statusCode}`,
|
|
807
889
|
type: "function"
|
|
808
890
|
})
|
|
809
891
|
}))
|
|
@@ -815,12 +897,13 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
815
897
|
name: "typescript",
|
|
816
898
|
type: "react",
|
|
817
899
|
Operation({ node, adapter, options }) {
|
|
818
|
-
const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing,
|
|
900
|
+
const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group } = options;
|
|
819
901
|
const { mode, getFile, resolveName } = (0, _kubb_core_hooks.useKubb)();
|
|
820
902
|
const file = getFile({
|
|
821
903
|
name: node.operationId,
|
|
822
904
|
extname: ".ts",
|
|
823
|
-
mode
|
|
905
|
+
mode,
|
|
906
|
+
options: { group: group ? group.type === "tag" ? { tag: node.tags[0] } : { path: node.path } : void 0 }
|
|
824
907
|
});
|
|
825
908
|
const params = (0, _kubb_ast.applyParamsCasing)(node.parameters, paramsCasing);
|
|
826
909
|
function renderSchemaType({ node: schemaNode, name, typedName, description }) {
|
|
@@ -854,29 +937,28 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
854
937
|
enumKeyCasing,
|
|
855
938
|
optionalType,
|
|
856
939
|
arrayType,
|
|
857
|
-
syntaxType
|
|
858
|
-
mapper
|
|
940
|
+
syntaxType
|
|
859
941
|
})] });
|
|
860
942
|
}
|
|
861
943
|
const paramTypes = params.map((param) => renderSchemaType({
|
|
862
944
|
node: param.schema,
|
|
863
945
|
name: resolveName({
|
|
864
|
-
name: `${node.operationId} ${param.name}`,
|
|
946
|
+
name: `${node.operationId} ${require_components.pascalCase(param.in)} ${param.name}`,
|
|
865
947
|
type: "function"
|
|
866
948
|
}),
|
|
867
949
|
typedName: resolveName({
|
|
868
|
-
name: `${node.operationId} ${param.name}`,
|
|
950
|
+
name: `${node.operationId} ${require_components.pascalCase(param.in)} ${param.name}`,
|
|
869
951
|
type: "type"
|
|
870
952
|
})
|
|
871
953
|
}));
|
|
872
954
|
const responseTypes = node.responses.filter((res) => res.schema).map((res) => renderSchemaType({
|
|
873
955
|
node: res.schema,
|
|
874
956
|
name: resolveName({
|
|
875
|
-
name: `${node.operationId} ${res.statusCode}`,
|
|
957
|
+
name: `${node.operationId} Status ${res.statusCode}`,
|
|
876
958
|
type: "function"
|
|
877
959
|
}),
|
|
878
960
|
typedName: resolveName({
|
|
879
|
-
name: `${node.operationId} ${res.statusCode}`,
|
|
961
|
+
name: `${node.operationId} Status ${res.statusCode}`,
|
|
880
962
|
type: "type"
|
|
881
963
|
}),
|
|
882
964
|
description: res.description
|
|
@@ -884,11 +966,11 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
884
966
|
const requestType = node.requestBody ? renderSchemaType({
|
|
885
967
|
node: node.requestBody,
|
|
886
968
|
name: resolveName({
|
|
887
|
-
name: `${node.operationId}
|
|
969
|
+
name: `${node.operationId} Data`,
|
|
888
970
|
type: "function"
|
|
889
971
|
}),
|
|
890
972
|
typedName: resolveName({
|
|
891
|
-
name: `${node.operationId}
|
|
973
|
+
name: `${node.operationId} Data`,
|
|
892
974
|
type: "type"
|
|
893
975
|
}),
|
|
894
976
|
description: node.requestBody.description
|
|
@@ -902,11 +984,11 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
902
984
|
resolveName
|
|
903
985
|
}),
|
|
904
986
|
name: resolveName({
|
|
905
|
-
name: `${node.operationId}
|
|
987
|
+
name: `${node.operationId} RequestConfig`,
|
|
906
988
|
type: "function"
|
|
907
989
|
}),
|
|
908
990
|
typedName: resolveName({
|
|
909
|
-
name: `${node.operationId}
|
|
991
|
+
name: `${node.operationId} RequestConfig`,
|
|
910
992
|
type: "type"
|
|
911
993
|
})
|
|
912
994
|
});
|
|
@@ -936,7 +1018,8 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
936
1018
|
typedName: resolveName({
|
|
937
1019
|
name: `${node.operationId} Response`,
|
|
938
1020
|
type: "type"
|
|
939
|
-
})
|
|
1021
|
+
}),
|
|
1022
|
+
description: "Union of all possible responses"
|
|
940
1023
|
});
|
|
941
1024
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
942
1025
|
baseName: file.baseName,
|
|
@@ -953,7 +1036,7 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
953
1036
|
});
|
|
954
1037
|
},
|
|
955
1038
|
Schema({ node, adapter, options }) {
|
|
956
|
-
const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType
|
|
1039
|
+
const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType } = options;
|
|
957
1040
|
const { mode, resolveName, getFile } = (0, _kubb_core_hooks.useKubb)();
|
|
958
1041
|
if (!node.name) return;
|
|
959
1042
|
const imports = adapter.getImports(node, (schemaName) => ({
|
|
@@ -972,7 +1055,7 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
972
1055
|
name: node.name,
|
|
973
1056
|
type: "type"
|
|
974
1057
|
});
|
|
975
|
-
if (
|
|
1058
|
+
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema) typedName += "Key";
|
|
976
1059
|
const type = {
|
|
977
1060
|
name: resolveName({
|
|
978
1061
|
name: node.name,
|
|
@@ -1006,8 +1089,7 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1006
1089
|
enumKeyCasing,
|
|
1007
1090
|
optionalType,
|
|
1008
1091
|
arrayType,
|
|
1009
|
-
syntaxType
|
|
1010
|
-
mapper
|
|
1092
|
+
syntaxType
|
|
1011
1093
|
})]
|
|
1012
1094
|
});
|
|
1013
1095
|
}
|
|
@@ -1019,7 +1101,7 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1019
1101
|
const { output = {
|
|
1020
1102
|
path: "types",
|
|
1021
1103
|
barrelType: "named"
|
|
1022
|
-
}, 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 = {},
|
|
1104
|
+
}, 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;
|
|
1023
1105
|
return {
|
|
1024
1106
|
name: pluginTsName,
|
|
1025
1107
|
options: {
|
|
@@ -1037,7 +1119,6 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1037
1119
|
syntaxType,
|
|
1038
1120
|
group,
|
|
1039
1121
|
override,
|
|
1040
|
-
mapper,
|
|
1041
1122
|
paramsCasing,
|
|
1042
1123
|
usedEnumNames: {}
|
|
1043
1124
|
},
|
|
@@ -1065,7 +1146,7 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1065
1146
|
return resolvedName;
|
|
1066
1147
|
},
|
|
1067
1148
|
async install() {
|
|
1068
|
-
const { config, fabric, plugin, adapter, rootNode,
|
|
1149
|
+
const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this;
|
|
1069
1150
|
const root = node_path.default.resolve(config.root, config.output.path);
|
|
1070
1151
|
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
1071
1152
|
if (adapter) {
|
|
@@ -1088,7 +1169,7 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1088
1169
|
fabric,
|
|
1089
1170
|
Component: generator.Schema,
|
|
1090
1171
|
plugin,
|
|
1091
|
-
|
|
1172
|
+
driver,
|
|
1092
1173
|
mode,
|
|
1093
1174
|
version: generator.version
|
|
1094
1175
|
});
|
|
@@ -1113,7 +1194,7 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1113
1194
|
fabric,
|
|
1114
1195
|
Component: generator.Operation,
|
|
1115
1196
|
plugin,
|
|
1116
|
-
|
|
1197
|
+
driver,
|
|
1117
1198
|
mode,
|
|
1118
1199
|
version: generator.version
|
|
1119
1200
|
});
|
|
@@ -1135,7 +1216,7 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1135
1216
|
const schemaFiles = await new _kubb_plugin_oas.SchemaGenerator(this.plugin.options, {
|
|
1136
1217
|
fabric: this.fabric,
|
|
1137
1218
|
oas,
|
|
1138
|
-
|
|
1219
|
+
driver: this.driver,
|
|
1139
1220
|
events: this.events,
|
|
1140
1221
|
plugin: this.plugin,
|
|
1141
1222
|
contentType,
|
|
@@ -1148,7 +1229,7 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1148
1229
|
const operationFiles = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
1149
1230
|
fabric: this.fabric,
|
|
1150
1231
|
oas,
|
|
1151
|
-
|
|
1232
|
+
driver: this.driver,
|
|
1152
1233
|
events: this.events,
|
|
1153
1234
|
plugin: this.plugin,
|
|
1154
1235
|
contentType,
|
|
@@ -1195,4 +1276,4 @@ Object.defineProperty(exports, "typeGenerator$1", {
|
|
|
1195
1276
|
}
|
|
1196
1277
|
});
|
|
1197
1278
|
|
|
1198
|
-
//# sourceMappingURL=plugin-
|
|
1279
|
+
//# sourceMappingURL=plugin-Cn85VLXR.cjs.map
|