@kubb/plugin-ts 5.0.0-alpha.4 → 5.0.0-alpha.6
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-CRjwjdyE.js → components-CRu8IKY3.js} +12 -8
- package/dist/components-CRu8IKY3.js.map +1 -0
- package/dist/{components-DI0aTIBg.cjs → components-DeNDKlzf.cjs} +12 -8
- 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 +2 -3
- 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-Bgm8TNUt.js → plugin-BcK4SBA0.js} +510 -243
- package/dist/plugin-BcK4SBA0.js.map +1 -0
- package/dist/{plugin-DvK-Uhvv.cjs → plugin-BrQcApyO.cjs} +510 -244
- package/dist/plugin-BrQcApyO.cjs.map +1 -0
- package/dist/{types-aotMcdUB.d.ts → types-CsvB6X5Y.d.ts} +11 -14
- package/package.json +8 -8
- package/src/components/Type.tsx +0 -3
- package/src/components/v2/Enum.tsx +67 -0
- package/src/components/v2/Type.tsx +22 -117
- package/src/constants.ts +29 -0
- package/src/factory.ts +12 -16
- package/src/generators/typeGenerator.tsx +2 -4
- package/src/generators/v2/typeGenerator.tsx +78 -103
- package/src/generators/v2/utils.ts +140 -0
- package/src/parser.ts +1 -8
- package/src/plugin.ts +11 -2
- package/src/printer.ts +235 -111
- package/src/types.ts +10 -13
- package/dist/components-CRjwjdyE.js.map +0 -1
- package/dist/components-DI0aTIBg.cjs.map +0 -1
- package/dist/plugin-Bgm8TNUt.js.map +0 -1
- package/dist/plugin-DvK-Uhvv.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");
|
|
@@ -217,7 +217,7 @@ 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
222
|
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
|
|
223
223
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
@@ -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,
|
|
@@ -336,7 +335,7 @@ const typeGenerator$1 = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
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
341
|
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
|
|
@@ -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,234 +507,414 @@ 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
|
-
|
|
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
|
+
}
|
|
489
592
|
return require_components.createUnionDeclaration({
|
|
490
593
|
withParentheses: true,
|
|
491
|
-
nodes:
|
|
594
|
+
nodes: buildMemberNodes(members, this.print)
|
|
492
595
|
}) ?? void 0;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
},
|
|
497
|
-
union(node) {
|
|
498
|
-
const members = node.members ?? [];
|
|
499
|
-
const hasStringLiteral = members.some((m) => m.type === "enum" && m.enumType === "string");
|
|
500
|
-
const hasPlainString = members.some((m) => (0, _kubb_ast.isPlainStringType)(m));
|
|
501
|
-
if (hasStringLiteral && hasPlainString) {
|
|
502
|
-
const nodes = members.map((m) => {
|
|
503
|
-
if ((0, _kubb_ast.isPlainStringType)(m)) return require_components.createIntersectionDeclaration({
|
|
504
|
-
nodes: [require_components.keywordTypeNodes.string, require_components.createTypeLiteralNode([])],
|
|
505
|
-
withParentheses: true
|
|
506
|
-
});
|
|
507
|
-
return this.print(m);
|
|
508
|
-
}).filter(Boolean);
|
|
509
|
-
return require_components.createUnionDeclaration({
|
|
596
|
+
},
|
|
597
|
+
intersection(node) {
|
|
598
|
+
return require_components.createIntersectionDeclaration({
|
|
510
599
|
withParentheses: true,
|
|
511
|
-
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
|
|
512
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);
|
|
513
633
|
}
|
|
514
|
-
return require_components.createUnionDeclaration({
|
|
515
|
-
withParentheses: true,
|
|
516
|
-
nodes: buildMemberNodes(members, this.print)
|
|
517
|
-
}) ?? void 0;
|
|
518
|
-
},
|
|
519
|
-
intersection(node) {
|
|
520
|
-
return require_components.createIntersectionDeclaration({
|
|
521
|
-
withParentheses: true,
|
|
522
|
-
nodes: buildMemberNodes(node.members, this.print)
|
|
523
|
-
}) ?? void 0;
|
|
524
634
|
},
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
return
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
const propertyNodes = node.properties.map((prop) => {
|
|
539
|
-
const baseType = print(prop.schema) ?? require_components.keywordTypeNodes.unknown;
|
|
540
|
-
const type = buildPropertyType(prop.schema, baseType, this.options.optionalType);
|
|
541
|
-
const propertyNode = require_components.createPropertySignature({
|
|
542
|
-
questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
|
|
543
|
-
name: prop.name,
|
|
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,
|
|
544
648
|
type,
|
|
545
|
-
|
|
546
|
-
})
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
+
]
|
|
551
662
|
});
|
|
552
|
-
const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
|
|
553
|
-
if (!allElements.length) return require_components.keywordTypeNodes.object;
|
|
554
|
-
return require_components.createTypeLiteralNode(allElements);
|
|
555
663
|
}
|
|
556
|
-
}
|
|
557
|
-
})
|
|
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
|
+
}
|
|
558
716
|
//#endregion
|
|
559
717
|
//#region src/components/v2/Type.tsx
|
|
560
|
-
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing,
|
|
561
|
-
const
|
|
562
|
-
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;
|
|
563
720
|
const enumSchemaNodes = (0, _kubb_ast.collect)(node, { schema(n) {
|
|
564
721
|
if (n.type === "enum" && n.name) return n;
|
|
565
722
|
} });
|
|
566
|
-
|
|
723
|
+
const typeNode = printerTs({
|
|
567
724
|
optionalType,
|
|
568
725
|
arrayType,
|
|
569
|
-
enumType
|
|
726
|
+
enumType,
|
|
727
|
+
typeName: name,
|
|
728
|
+
syntaxType,
|
|
729
|
+
description: resolvedDescription,
|
|
730
|
+
keysToOmit
|
|
570
731
|
}).print(node);
|
|
571
|
-
if (!
|
|
572
|
-
|
|
573
|
-
const isDirectEnum = node.type === "array" && node.items !== void 0;
|
|
574
|
-
const isEnumOnly = "enum" in node && node.enum;
|
|
575
|
-
if (isDirectEnum || isEnumOnly) {
|
|
576
|
-
const typeNameWithKey = `${enumSchemaNodes[0].name}Key`;
|
|
577
|
-
type = require_components.createTypeReferenceNode(typeNameWithKey);
|
|
578
|
-
if (isDirectEnum) if (arrayType === "generic") type = require_components.createTypeReferenceNode(require_components.createIdentifier("Array"), [type]);
|
|
579
|
-
else type = require_components.createArrayTypeNode(type);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
if (node) {
|
|
583
|
-
if (node.nullable) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.null] });
|
|
584
|
-
if (node.nullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.undefined] });
|
|
585
|
-
if (node.optional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = require_components.createUnionDeclaration({ nodes: [type, require_components.keywordTypeNodes.undefined] });
|
|
586
|
-
}
|
|
587
|
-
const useTypeGeneration = syntaxType === "type" || [require_components.syntaxKind.union].includes(type.kind) || !!keysToOmit?.length;
|
|
588
|
-
typeNodes.push(require_components.createTypeDeclaration({
|
|
589
|
-
name,
|
|
590
|
-
isExportable: true,
|
|
591
|
-
type: keysToOmit?.length ? require_components.createOmitDeclaration({
|
|
592
|
-
keys: keysToOmit,
|
|
593
|
-
type,
|
|
594
|
-
nonNullable: true
|
|
595
|
-
}) : type,
|
|
596
|
-
syntax: useTypeGeneration ? "type" : "interface",
|
|
597
|
-
comments: [
|
|
598
|
-
node?.title ? `${require_components.jsStringEscape(node.title)}` : void 0,
|
|
599
|
-
description ? `@description ${require_components.jsStringEscape(description)}` : void 0,
|
|
600
|
-
node?.deprecated ? "@deprecated" : void 0,
|
|
601
|
-
node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
|
|
602
|
-
node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
|
|
603
|
-
node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
|
|
604
|
-
node?.default ? `@default ${node.default}` : void 0,
|
|
605
|
-
node?.example ? `@example ${node.example}` : void 0
|
|
606
|
-
]
|
|
607
|
-
}));
|
|
608
|
-
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((enumSchemaNode) => {
|
|
609
|
-
const enumName = enumType === "asPascalConst" ? require_components.pascalCase(enumSchemaNode.name) : require_components.camelCase(enumSchemaNode.name);
|
|
610
|
-
const typeName = ["asConst", "asPascalConst"].includes(enumType) ? `${enumSchemaNode.name}Key` : enumSchemaNode.name;
|
|
611
|
-
const [nameNode, typeNode] = require_components.createEnumDeclaration({
|
|
612
|
-
name: enumName,
|
|
613
|
-
typeName,
|
|
614
|
-
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]) ?? [],
|
|
615
|
-
type: enumType,
|
|
616
|
-
enumKeyCasing
|
|
617
|
-
});
|
|
732
|
+
if (!typeNode) return;
|
|
733
|
+
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
618
734
|
return {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
name: enumName,
|
|
622
|
-
typeName
|
|
735
|
+
node,
|
|
736
|
+
...getEnumNames(node, enumType)
|
|
623
737
|
};
|
|
624
738
|
});
|
|
625
739
|
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
626
740
|
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
627
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(nameNode)
|
|
633
|
-
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
634
|
-
name: typeName,
|
|
635
|
-
isIndexable: true,
|
|
636
|
-
isExportable: [
|
|
637
|
-
"enum",
|
|
638
|
-
"asConst",
|
|
639
|
-
"asPascalConst",
|
|
640
|
-
"constEnum",
|
|
641
|
-
"literal",
|
|
642
|
-
void 0
|
|
643
|
-
].includes(enumType),
|
|
644
|
-
isTypeOnly: [
|
|
645
|
-
"asConst",
|
|
646
|
-
"asPascalConst",
|
|
647
|
-
"literal",
|
|
648
|
-
void 0
|
|
649
|
-
].includes(enumType),
|
|
650
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
651
|
-
})] })), 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, {
|
|
652
746
|
name: typedName,
|
|
653
747
|
isTypeOnly: true,
|
|
654
748
|
isExportable: true,
|
|
655
749
|
isIndexable: true,
|
|
656
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(
|
|
750
|
+
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
657
751
|
})] });
|
|
658
752
|
}
|
|
659
753
|
//#endregion
|
|
754
|
+
//#region src/generators/v2/utils.ts
|
|
755
|
+
/**
|
|
756
|
+
* Builds an `ObjectSchemaNode` for a group of parameters (path/query/header).
|
|
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.
|
|
760
|
+
*/
|
|
761
|
+
function buildParamsSchema({ params, operationId, resolveName }) {
|
|
762
|
+
return (0, _kubb_ast.createSchema)({
|
|
763
|
+
type: "object",
|
|
764
|
+
properties: params.map((param) => (0, _kubb_ast.createProperty)({
|
|
765
|
+
name: param.name,
|
|
766
|
+
schema: (0, _kubb_ast.createSchema)({
|
|
767
|
+
type: "ref",
|
|
768
|
+
name: resolveName({
|
|
769
|
+
name: `${operationId} ${require_components.pascalCase(param.in)} ${param.name}`,
|
|
770
|
+
type: "function"
|
|
771
|
+
}),
|
|
772
|
+
optional: !param.required
|
|
773
|
+
})
|
|
774
|
+
}))
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Builds an `ObjectSchemaNode` representing the `<OperationId>RequestConfig` type:
|
|
779
|
+
* - `data` → request body ref (optional) or `never`
|
|
780
|
+
* - `pathParams` → inline object of path param refs, or `never`
|
|
781
|
+
* - `queryParams` → inline object of query param refs (optional), or `never`
|
|
782
|
+
* - `headerParams` → inline object of header param refs (optional), or `never`
|
|
783
|
+
* - `url` → Express-style template literal (plugin-ts extension, handled by printer)
|
|
784
|
+
*/
|
|
785
|
+
function buildDataSchemaNode({ node, resolveName }) {
|
|
786
|
+
const pathParams = node.parameters.filter((p) => p.in === "path");
|
|
787
|
+
const queryParams = node.parameters.filter((p) => p.in === "query");
|
|
788
|
+
const headerParams = node.parameters.filter((p) => p.in === "header");
|
|
789
|
+
return (0, _kubb_ast.createSchema)({
|
|
790
|
+
type: "object",
|
|
791
|
+
properties: [
|
|
792
|
+
(0, _kubb_ast.createProperty)({
|
|
793
|
+
name: "data",
|
|
794
|
+
schema: node.requestBody ? (0, _kubb_ast.createSchema)({
|
|
795
|
+
type: "ref",
|
|
796
|
+
name: resolveName({
|
|
797
|
+
name: `${node.operationId} Data`,
|
|
798
|
+
type: "function"
|
|
799
|
+
}),
|
|
800
|
+
optional: true
|
|
801
|
+
}) : (0, _kubb_ast.createSchema)({
|
|
802
|
+
type: "never",
|
|
803
|
+
optional: true
|
|
804
|
+
})
|
|
805
|
+
}),
|
|
806
|
+
(0, _kubb_ast.createProperty)({
|
|
807
|
+
name: "pathParams",
|
|
808
|
+
schema: pathParams.length > 0 ? buildParamsSchema({
|
|
809
|
+
params: pathParams,
|
|
810
|
+
operationId: node.operationId,
|
|
811
|
+
resolveName
|
|
812
|
+
}) : (0, _kubb_ast.createSchema)({
|
|
813
|
+
type: "never",
|
|
814
|
+
optional: true
|
|
815
|
+
})
|
|
816
|
+
}),
|
|
817
|
+
(0, _kubb_ast.createProperty)({
|
|
818
|
+
name: "queryParams",
|
|
819
|
+
schema: queryParams.length > 0 ? (0, _kubb_ast.createSchema)({
|
|
820
|
+
...buildParamsSchema({
|
|
821
|
+
params: queryParams,
|
|
822
|
+
operationId: node.operationId,
|
|
823
|
+
resolveName
|
|
824
|
+
}),
|
|
825
|
+
optional: true
|
|
826
|
+
}) : (0, _kubb_ast.createSchema)({
|
|
827
|
+
type: "never",
|
|
828
|
+
optional: true
|
|
829
|
+
})
|
|
830
|
+
}),
|
|
831
|
+
(0, _kubb_ast.createProperty)({
|
|
832
|
+
name: "headerParams",
|
|
833
|
+
schema: headerParams.length > 0 ? (0, _kubb_ast.createSchema)({
|
|
834
|
+
...buildParamsSchema({
|
|
835
|
+
params: headerParams,
|
|
836
|
+
operationId: node.operationId,
|
|
837
|
+
resolveName
|
|
838
|
+
}),
|
|
839
|
+
optional: true
|
|
840
|
+
}) : (0, _kubb_ast.createSchema)({
|
|
841
|
+
type: "never",
|
|
842
|
+
optional: true
|
|
843
|
+
})
|
|
844
|
+
}),
|
|
845
|
+
(0, _kubb_ast.createProperty)({
|
|
846
|
+
name: "url",
|
|
847
|
+
schema: (0, _kubb_ast.createSchema)({
|
|
848
|
+
type: "url",
|
|
849
|
+
path: node.path
|
|
850
|
+
})
|
|
851
|
+
})
|
|
852
|
+
]
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Builds an `ObjectSchemaNode` representing `<OperationId>Responses` — keyed by HTTP status code.
|
|
857
|
+
* Numeric status codes produce unquoted numeric keys (e.g. `200:`).
|
|
858
|
+
*/
|
|
859
|
+
function buildResponsesSchemaNode({ node, resolveName }) {
|
|
860
|
+
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
861
|
+
if (responsesWithSchema.length === 0) return null;
|
|
862
|
+
return (0, _kubb_ast.createSchema)({
|
|
863
|
+
type: "object",
|
|
864
|
+
properties: responsesWithSchema.map((res) => (0, _kubb_ast.createProperty)({
|
|
865
|
+
name: String(res.statusCode),
|
|
866
|
+
schema: (0, _kubb_ast.createSchema)({
|
|
867
|
+
type: "ref",
|
|
868
|
+
name: resolveName({
|
|
869
|
+
name: `${node.operationId} Status ${res.statusCode}`,
|
|
870
|
+
type: "function"
|
|
871
|
+
})
|
|
872
|
+
})
|
|
873
|
+
}))
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Builds a `UnionSchemaNode` representing `<OperationId>Response` — all response types in union format.
|
|
878
|
+
* Returns `null` when the operation has no responses with schemas.
|
|
879
|
+
*/
|
|
880
|
+
function buildResponseUnionSchemaNode({ node, resolveName }) {
|
|
881
|
+
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
882
|
+
if (responsesWithSchema.length === 0) return null;
|
|
883
|
+
return (0, _kubb_ast.createSchema)({
|
|
884
|
+
type: "union",
|
|
885
|
+
members: responsesWithSchema.map((res) => (0, _kubb_ast.createSchema)({
|
|
886
|
+
type: "ref",
|
|
887
|
+
name: resolveName({
|
|
888
|
+
name: `${node.operationId} Status ${res.statusCode}`,
|
|
889
|
+
type: "function"
|
|
890
|
+
})
|
|
891
|
+
}))
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
//#endregion
|
|
660
895
|
//#region src/generators/v2/typeGenerator.tsx
|
|
661
896
|
const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
662
897
|
name: "typescript",
|
|
663
898
|
type: "react",
|
|
664
899
|
Operation({ node, adapter, options }) {
|
|
665
|
-
const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType } = options;
|
|
666
|
-
const {
|
|
900
|
+
const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group } = options;
|
|
901
|
+
const { mode, getFile, resolveName } = (0, _kubb_core_hooks.useKubb)();
|
|
667
902
|
const file = getFile({
|
|
668
903
|
name: node.operationId,
|
|
669
|
-
pluginName: plugin.name,
|
|
670
904
|
extname: ".ts",
|
|
671
|
-
mode
|
|
905
|
+
mode,
|
|
906
|
+
options: { group: group ? group.type === "tag" ? { tag: node.tags[0] } : { path: node.path } : void 0 }
|
|
672
907
|
});
|
|
908
|
+
const params = (0, _kubb_ast.applyParamsCasing)(node.parameters, paramsCasing);
|
|
673
909
|
function renderSchemaType({ node: schemaNode, name, typedName, description }) {
|
|
910
|
+
if (!schemaNode) return null;
|
|
674
911
|
const imports = adapter.getImports(schemaNode, (schemaName) => ({
|
|
675
912
|
name: resolveName({
|
|
676
913
|
name: schemaName,
|
|
677
|
-
pluginName: plugin.name,
|
|
678
914
|
type: "type"
|
|
679
915
|
}),
|
|
680
916
|
path: getFile({
|
|
681
917
|
name: schemaName,
|
|
682
|
-
pluginName: plugin.name,
|
|
683
918
|
extname: ".ts",
|
|
684
919
|
mode
|
|
685
920
|
}).path
|
|
@@ -705,60 +940,87 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
705
940
|
syntaxType
|
|
706
941
|
})] });
|
|
707
942
|
}
|
|
708
|
-
const paramTypes =
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
943
|
+
const paramTypes = params.map((param) => renderSchemaType({
|
|
944
|
+
node: param.schema,
|
|
945
|
+
name: resolveName({
|
|
946
|
+
name: `${node.operationId} ${require_components.pascalCase(param.in)} ${param.name}`,
|
|
712
947
|
type: "function"
|
|
713
|
-
})
|
|
714
|
-
|
|
715
|
-
name: `${node.operationId} ${param.name}`,
|
|
716
|
-
pluginName: plugin.name,
|
|
948
|
+
}),
|
|
949
|
+
typedName: resolveName({
|
|
950
|
+
name: `${node.operationId} ${require_components.pascalCase(param.in)} ${param.name}`,
|
|
717
951
|
type: "type"
|
|
718
|
-
})
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
952
|
+
})
|
|
953
|
+
}));
|
|
954
|
+
const responseTypes = node.responses.filter((res) => res.schema).map((res) => renderSchemaType({
|
|
955
|
+
node: res.schema,
|
|
956
|
+
name: resolveName({
|
|
957
|
+
name: `${node.operationId} Status ${res.statusCode}`,
|
|
958
|
+
type: "function"
|
|
959
|
+
}),
|
|
960
|
+
typedName: resolveName({
|
|
961
|
+
name: `${node.operationId} Status ${res.statusCode}`,
|
|
962
|
+
type: "type"
|
|
963
|
+
}),
|
|
964
|
+
description: res.description
|
|
965
|
+
}));
|
|
966
|
+
const requestType = node.requestBody ? renderSchemaType({
|
|
967
|
+
node: node.requestBody,
|
|
968
|
+
name: resolveName({
|
|
969
|
+
name: `${node.operationId} Data`,
|
|
970
|
+
type: "function"
|
|
971
|
+
}),
|
|
972
|
+
typedName: resolveName({
|
|
973
|
+
name: `${node.operationId} Data`,
|
|
974
|
+
type: "type"
|
|
975
|
+
}),
|
|
976
|
+
description: node.requestBody.description
|
|
977
|
+
}) : null;
|
|
978
|
+
const dataType = renderSchemaType({
|
|
979
|
+
node: buildDataSchemaNode({
|
|
980
|
+
node: {
|
|
981
|
+
...node,
|
|
982
|
+
parameters: params
|
|
983
|
+
},
|
|
984
|
+
resolveName
|
|
985
|
+
}),
|
|
986
|
+
name: resolveName({
|
|
987
|
+
name: `${node.operationId} RequestConfig`,
|
|
988
|
+
type: "function"
|
|
989
|
+
}),
|
|
990
|
+
typedName: resolveName({
|
|
991
|
+
name: `${node.operationId} RequestConfig`,
|
|
992
|
+
type: "type"
|
|
993
|
+
})
|
|
724
994
|
});
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
type: "type"
|
|
739
|
-
}),
|
|
740
|
-
description: res.description
|
|
741
|
-
});
|
|
995
|
+
const responsesType = renderSchemaType({
|
|
996
|
+
node: buildResponsesSchemaNode({
|
|
997
|
+
node,
|
|
998
|
+
resolveName
|
|
999
|
+
}),
|
|
1000
|
+
name: resolveName({
|
|
1001
|
+
name: `${node.operationId} Responses`,
|
|
1002
|
+
type: "function"
|
|
1003
|
+
}),
|
|
1004
|
+
typedName: resolveName({
|
|
1005
|
+
name: `${node.operationId} Responses`,
|
|
1006
|
+
type: "type"
|
|
1007
|
+
})
|
|
742
1008
|
});
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
1009
|
+
const responseType = renderSchemaType({
|
|
1010
|
+
node: buildResponseUnionSchemaNode({
|
|
1011
|
+
node,
|
|
1012
|
+
resolveName
|
|
1013
|
+
}),
|
|
1014
|
+
name: resolveName({
|
|
1015
|
+
name: `${node.operationId} Response`,
|
|
748
1016
|
type: "function"
|
|
749
|
-
})
|
|
750
|
-
|
|
751
|
-
name:
|
|
752
|
-
pluginName: plugin.name,
|
|
1017
|
+
}),
|
|
1018
|
+
typedName: resolveName({
|
|
1019
|
+
name: `${node.operationId} Response`,
|
|
753
1020
|
type: "type"
|
|
754
|
-
})
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
name: resolvedName,
|
|
758
|
-
typedName,
|
|
759
|
-
description: node.requestBody.description
|
|
760
|
-
});
|
|
761
|
-
})() : null;
|
|
1021
|
+
}),
|
|
1022
|
+
description: "Union of all possible responses"
|
|
1023
|
+
});
|
|
762
1024
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
763
1025
|
baseName: file.baseName,
|
|
764
1026
|
path: file.path,
|
|
@@ -766,23 +1028,24 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
766
1028
|
children: [
|
|
767
1029
|
paramTypes,
|
|
768
1030
|
responseTypes,
|
|
769
|
-
requestType
|
|
1031
|
+
requestType,
|
|
1032
|
+
dataType,
|
|
1033
|
+
responsesType,
|
|
1034
|
+
responseType
|
|
770
1035
|
]
|
|
771
1036
|
});
|
|
772
1037
|
},
|
|
773
1038
|
Schema({ node, adapter, options }) {
|
|
774
1039
|
const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType } = options;
|
|
775
|
-
const {
|
|
1040
|
+
const { mode, resolveName, getFile } = (0, _kubb_core_hooks.useKubb)();
|
|
776
1041
|
if (!node.name) return;
|
|
777
1042
|
const imports = adapter.getImports(node, (schemaName) => ({
|
|
778
1043
|
name: resolveName({
|
|
779
1044
|
name: schemaName,
|
|
780
|
-
pluginName: plugin.name,
|
|
781
1045
|
type: "type"
|
|
782
1046
|
}),
|
|
783
1047
|
path: getFile({
|
|
784
1048
|
name: schemaName,
|
|
785
|
-
pluginName: plugin.name,
|
|
786
1049
|
extname: ".ts",
|
|
787
1050
|
mode
|
|
788
1051
|
}).path
|
|
@@ -790,20 +1053,17 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
790
1053
|
const isEnumSchema = node.type === "enum";
|
|
791
1054
|
let typedName = resolveName({
|
|
792
1055
|
name: node.name,
|
|
793
|
-
pluginName: plugin.name,
|
|
794
1056
|
type: "type"
|
|
795
1057
|
});
|
|
796
|
-
if (
|
|
1058
|
+
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema) typedName += "Key";
|
|
797
1059
|
const type = {
|
|
798
1060
|
name: resolveName({
|
|
799
1061
|
name: node.name,
|
|
800
|
-
pluginName: plugin.name,
|
|
801
1062
|
type: "function"
|
|
802
1063
|
}),
|
|
803
1064
|
typedName,
|
|
804
1065
|
file: getFile({
|
|
805
1066
|
name: node.name,
|
|
806
|
-
pluginName: plugin.name,
|
|
807
1067
|
extname: ".ts",
|
|
808
1068
|
mode
|
|
809
1069
|
})
|
|
@@ -841,7 +1101,7 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
841
1101
|
const { output = {
|
|
842
1102
|
path: "types",
|
|
843
1103
|
barrelType: "named"
|
|
844
|
-
}, 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;
|
|
845
1105
|
return {
|
|
846
1106
|
name: pluginTsName,
|
|
847
1107
|
options: {
|
|
@@ -859,7 +1119,6 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
859
1119
|
syntaxType,
|
|
860
1120
|
group,
|
|
861
1121
|
override,
|
|
862
|
-
mapper,
|
|
863
1122
|
paramsCasing,
|
|
864
1123
|
usedEnumNames: {}
|
|
865
1124
|
},
|
|
@@ -944,6 +1203,13 @@ const pluginTs = (0, _kubb_core.definePlugin)((options) => {
|
|
|
944
1203
|
await Promise.all(writeTasks);
|
|
945
1204
|
}
|
|
946
1205
|
}, { depth: "shallow" });
|
|
1206
|
+
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
1207
|
+
type: output.barrelType ?? "named",
|
|
1208
|
+
root,
|
|
1209
|
+
output,
|
|
1210
|
+
meta: { pluginName: this.plugin.name }
|
|
1211
|
+
});
|
|
1212
|
+
await this.upsertFile(...barrelFiles);
|
|
947
1213
|
return;
|
|
948
1214
|
}
|
|
949
1215
|
const oas = await this.getOas();
|
|
@@ -1010,4 +1276,4 @@ Object.defineProperty(exports, "typeGenerator$1", {
|
|
|
1010
1276
|
}
|
|
1011
1277
|
});
|
|
1012
1278
|
|
|
1013
|
-
//# sourceMappingURL=plugin-
|
|
1279
|
+
//# sourceMappingURL=plugin-BrQcApyO.cjs.map
|