@kubb/plugin-ts 5.0.0-beta.94 → 5.0.0-beta.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +114 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.js +114 -97
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -77,11 +77,6 @@ type PrinterTsOptions = {
|
|
|
77
77
|
* Schema names that represent enums for suffixed key references.
|
|
78
78
|
*/
|
|
79
79
|
enumSchemaNames?: Set<string>;
|
|
80
|
-
/**
|
|
81
|
-
* Maps a component `$ref` path to its collision-resolved name, so a reference to a renamed
|
|
82
|
-
* component (e.g. `#/components/schemas/Order` → `OrderSchema`) emits the renamed name.
|
|
83
|
-
*/
|
|
84
|
-
nameMapping?: ReadonlyMap<string, string>;
|
|
85
80
|
/**
|
|
86
81
|
* Custom handler map for node type overrides.
|
|
87
82
|
*/
|
package/dist/index.js
CHANGED
|
@@ -335,7 +335,6 @@ const PARAM_RANK = {
|
|
|
335
335
|
//#endregion
|
|
336
336
|
//#region src/factory.ts
|
|
337
337
|
var factory_exports = /* @__PURE__ */ __exportAll({
|
|
338
|
-
SyntaxKind: () => SyntaxKind,
|
|
339
338
|
appendJSDocToNode: () => appendJSDocToNode,
|
|
340
339
|
buildIndexSignatures: () => buildIndexSignatures,
|
|
341
340
|
buildMemberNodes: () => buildMemberNodes,
|
|
@@ -343,29 +342,15 @@ var factory_exports = /* @__PURE__ */ __exportAll({
|
|
|
343
342
|
buildTupleNode: () => buildTupleNode,
|
|
344
343
|
constToTypeNode: () => constToTypeNode,
|
|
345
344
|
createArrayDeclaration: () => createArrayDeclaration,
|
|
346
|
-
createArrayTypeNode: () => createArrayTypeNode,
|
|
347
345
|
createEnumDeclaration: () => createEnumDeclaration,
|
|
348
346
|
createExportDeclaration: () => createExportDeclaration,
|
|
349
|
-
createFalse: () => createFalse,
|
|
350
|
-
createIdentifier: () => createIdentifier,
|
|
351
347
|
createImportDeclaration: () => createImportDeclaration,
|
|
352
|
-
createIndexSignature: () => createIndexSignature,
|
|
353
|
-
createInterfaceDeclaration: () => createInterfaceDeclaration,
|
|
354
348
|
createIntersectionDeclaration: () => createIntersectionDeclaration,
|
|
355
349
|
createJSDoc: () => createJSDoc,
|
|
356
|
-
createLiteralTypeNode: () => createLiteralTypeNode,
|
|
357
|
-
createNumericLiteral: () => createNumericLiteral,
|
|
358
350
|
createOmitDeclaration: () => createOmitDeclaration,
|
|
359
|
-
createOptionalTypeNode: () => createOptionalTypeNode,
|
|
360
351
|
createParameterSignature: () => createParameterSignature,
|
|
361
|
-
createPrefixUnaryExpression: () => createPrefixUnaryExpression,
|
|
362
352
|
createPropertySignature: () => createPropertySignature,
|
|
363
353
|
createQuestionToken: () => createQuestionToken,
|
|
364
|
-
createRestTypeNode: () => createRestTypeNode,
|
|
365
|
-
createStringLiteral: () => createStringLiteral,
|
|
366
|
-
createTrue: () => createTrue,
|
|
367
|
-
createTupleTypeNode: () => createTupleTypeNode,
|
|
368
|
-
createTypeAliasDeclaration: () => createTypeAliasDeclaration,
|
|
369
354
|
createTypeDeclaration: () => createTypeDeclaration,
|
|
370
355
|
createTypeLiteralNode: () => createTypeLiteralNode,
|
|
371
356
|
createTypeReferenceNode: () => createTypeReferenceNode,
|
|
@@ -1023,22 +1008,93 @@ function getOperationParameters(node, options = {}) {
|
|
|
1023
1008
|
};
|
|
1024
1009
|
}
|
|
1025
1010
|
//#endregion
|
|
1026
|
-
//#region ../../internals/shared/src/
|
|
1011
|
+
//#region ../../internals/shared/src/resolver.ts
|
|
1027
1012
|
/**
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1013
|
+
* Resolves a single operation parameter name with the
|
|
1014
|
+
* `<operationId> <in> <name>` template.
|
|
1030
1015
|
*
|
|
1031
|
-
*
|
|
1032
|
-
*
|
|
1016
|
+
* @example
|
|
1017
|
+
* `operationParamName.call(resolver, node, param) // → 'DeletePetPathPetId'`
|
|
1018
|
+
*/
|
|
1019
|
+
function operationParamName(node, param) {
|
|
1020
|
+
return this.name(`${node.operationId} ${param.in} ${param.name}`);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Builds the shared `param` namespace. Spread the result into `createResolver`
|
|
1024
|
+
* and override individual methods next to it when a plugin deviates.
|
|
1025
|
+
*
|
|
1026
|
+
* @example
|
|
1027
|
+
* ```ts
|
|
1028
|
+
* createResolver<PluginTs>({ param: createOperationParamResolver(), ... })
|
|
1029
|
+
* ```
|
|
1030
|
+
*/
|
|
1031
|
+
function createOperationParamResolver() {
|
|
1032
|
+
return {
|
|
1033
|
+
name: operationParamName,
|
|
1034
|
+
path(node) {
|
|
1035
|
+
return this.name(`${node.operationId} Path`);
|
|
1036
|
+
},
|
|
1037
|
+
query(node) {
|
|
1038
|
+
return this.name(`${node.operationId} Query`);
|
|
1039
|
+
},
|
|
1040
|
+
headers(node) {
|
|
1041
|
+
return this.name(`${node.operationId} Headers`);
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Builds the shared `response` namespace. Spread the result into
|
|
1047
|
+
* `createResolver` and add plugin-specific methods (`options`, `error`) next
|
|
1048
|
+
* to it.
|
|
1033
1049
|
*
|
|
1034
1050
|
* @example
|
|
1035
1051
|
* ```ts
|
|
1036
|
-
*
|
|
1052
|
+
* createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })
|
|
1037
1053
|
* ```
|
|
1038
1054
|
*/
|
|
1039
|
-
function
|
|
1040
|
-
|
|
1041
|
-
|
|
1055
|
+
function createOperationResponseResolver() {
|
|
1056
|
+
return {
|
|
1057
|
+
status(node, statusCode) {
|
|
1058
|
+
return this.name(`${node.operationId} Status ${statusCode}`);
|
|
1059
|
+
},
|
|
1060
|
+
body(node) {
|
|
1061
|
+
return this.name(`${node.operationId} Body`);
|
|
1062
|
+
},
|
|
1063
|
+
responses(node) {
|
|
1064
|
+
return this.name(`${node.operationId} Responses`);
|
|
1065
|
+
},
|
|
1066
|
+
response(node) {
|
|
1067
|
+
return this.name(`${node.operationId} Response`);
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Builds a resolver `file` override whose base name runs every path segment
|
|
1073
|
+
* through `toFilePath`, casing the final segment with `caseLast`.
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* ```ts
|
|
1077
|
+
* createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })
|
|
1078
|
+
* ```
|
|
1079
|
+
*/
|
|
1080
|
+
function createCasedFile(caseLast) {
|
|
1081
|
+
return { baseName({ name, extname }) {
|
|
1082
|
+
return `${toFilePath(name, caseLast)}${extname}`;
|
|
1083
|
+
} };
|
|
1084
|
+
}
|
|
1085
|
+
//#endregion
|
|
1086
|
+
//#region ../../internals/shared/src/refs.ts
|
|
1087
|
+
/**
|
|
1088
|
+
* Collects the resolved target name of every pointer-carrying ref in a schema tree, in
|
|
1089
|
+
* first-occurrence order. Use this for name-only checks (e.g. redeclaration detection) where
|
|
1090
|
+
* `resolver.imports` would resolve file paths that are then discarded.
|
|
1091
|
+
*/
|
|
1092
|
+
function collectRefNames(schema) {
|
|
1093
|
+
return ast.collect(schema, { schema: (node) => {
|
|
1094
|
+
const refNode = ast.narrowSchema(node, "ref");
|
|
1095
|
+
if (!refNode?.ref) return null;
|
|
1096
|
+
return ast.resolveRefName(refNode);
|
|
1097
|
+
} });
|
|
1042
1098
|
}
|
|
1043
1099
|
//#endregion
|
|
1044
1100
|
//#region ../../internals/shared/src/group.ts
|
|
@@ -1340,7 +1396,8 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1340
1396
|
time: dateOrStringNode,
|
|
1341
1397
|
ref(node) {
|
|
1342
1398
|
if (!node.name) return null;
|
|
1343
|
-
const refName =
|
|
1399
|
+
const refName = ast.resolveRefName(node);
|
|
1400
|
+
if (!refName) return null;
|
|
1344
1401
|
return createTypeReferenceNode(node.ref && ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enum.type) && this.options.enum.typeSuffix && this.options.enumSchemaNames?.has(refName) ? this.options.resolver.enum.keyName({ name: refName }, this.options.enum.typeSuffix) : node.ref ? this.options.resolver.name(refName) : refName, void 0);
|
|
1345
1402
|
},
|
|
1346
1403
|
enum(node) {
|
|
@@ -1466,24 +1523,22 @@ const typeGenerator = defineGenerator({
|
|
|
1466
1523
|
renderer: jsxRenderer,
|
|
1467
1524
|
schema(node, ctx) {
|
|
1468
1525
|
const { enum: enumOptions, syntaxType, optionalType, arrayType, output, group, printer } = ctx.options;
|
|
1469
|
-
const {
|
|
1526
|
+
const { config, resolver, root } = ctx;
|
|
1470
1527
|
if (!node.name) return;
|
|
1471
1528
|
const enumSchemaNames = new Set(ctx.meta.enumNames);
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
}).path
|
|
1486
|
-
}));
|
|
1529
|
+
const importName = (schemaName) => resolveImportName({
|
|
1530
|
+
schemaName,
|
|
1531
|
+
enumOptions,
|
|
1532
|
+
enumSchemaNames,
|
|
1533
|
+
resolver
|
|
1534
|
+
});
|
|
1535
|
+
const imports = resolver.imports({
|
|
1536
|
+
node,
|
|
1537
|
+
root,
|
|
1538
|
+
output,
|
|
1539
|
+
group: group ?? void 0,
|
|
1540
|
+
name: importName
|
|
1541
|
+
});
|
|
1487
1542
|
const enumNode = ast.narrowSchema(node, ast.schemaTypes.enum);
|
|
1488
1543
|
const isEnumSchema = !!enumNode && !isInlineConstEnum(enumNode, enumSchemaNames);
|
|
1489
1544
|
const meta = {
|
|
@@ -1505,7 +1560,6 @@ const typeGenerator = defineGenerator({
|
|
|
1505
1560
|
description: node.description,
|
|
1506
1561
|
resolver,
|
|
1507
1562
|
enumSchemaNames,
|
|
1508
|
-
nameMapping: getOasAdapter(adapter).options.nameMapping,
|
|
1509
1563
|
nodes: printer?.nodes
|
|
1510
1564
|
});
|
|
1511
1565
|
return /* @__PURE__ */ jsxs(File, {
|
|
@@ -1548,7 +1602,7 @@ const typeGenerator = defineGenerator({
|
|
|
1548
1602
|
},
|
|
1549
1603
|
operation(node, ctx) {
|
|
1550
1604
|
const { enum: enumOptions, optionalType, arrayType, syntaxType, group, output, printer } = ctx.options;
|
|
1551
|
-
const {
|
|
1605
|
+
const { config, resolver, root } = ctx;
|
|
1552
1606
|
const params = caseParams(node.parameters, "camelcase");
|
|
1553
1607
|
const meta = { file: resolver.file({
|
|
1554
1608
|
name: node.operationId,
|
|
@@ -1560,23 +1614,21 @@ const typeGenerator = defineGenerator({
|
|
|
1560
1614
|
group: group ?? void 0
|
|
1561
1615
|
}) };
|
|
1562
1616
|
const enumSchemaNames = new Set(ctx.meta.enumNames);
|
|
1617
|
+
const importName = (schemaName) => resolveImportName({
|
|
1618
|
+
schemaName,
|
|
1619
|
+
enumOptions,
|
|
1620
|
+
enumSchemaNames,
|
|
1621
|
+
resolver
|
|
1622
|
+
});
|
|
1563
1623
|
function renderSchemaType({ schema, name, keysToOmit }) {
|
|
1564
1624
|
if (!schema) return null;
|
|
1565
|
-
const imports =
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
path: resolver.file({
|
|
1573
|
-
name: schemaName,
|
|
1574
|
-
extname: ".ts",
|
|
1575
|
-
root,
|
|
1576
|
-
output,
|
|
1577
|
-
group: group ?? void 0
|
|
1578
|
-
}).path
|
|
1579
|
-
}));
|
|
1625
|
+
const imports = resolver.imports({
|
|
1626
|
+
node: schema,
|
|
1627
|
+
root,
|
|
1628
|
+
output,
|
|
1629
|
+
group: group ?? void 0,
|
|
1630
|
+
name: importName
|
|
1631
|
+
});
|
|
1580
1632
|
const schemaPrinter = printerTs({
|
|
1581
1633
|
optionalType,
|
|
1582
1634
|
arrayType,
|
|
@@ -1587,7 +1639,6 @@ const typeGenerator = defineGenerator({
|
|
|
1587
1639
|
keysToOmit,
|
|
1588
1640
|
resolver,
|
|
1589
1641
|
enumSchemaNames,
|
|
1590
|
-
nameMapping: getOasAdapter(adapter).options.nameMapping,
|
|
1591
1642
|
nodes: printer?.nodes
|
|
1592
1643
|
});
|
|
1593
1644
|
return /* @__PURE__ */ jsxs(Fragment, { children: [imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
@@ -1696,15 +1747,7 @@ const typeGenerator = defineGenerator({
|
|
|
1696
1747
|
if (!node.responses.some(hasSchema)) return null;
|
|
1697
1748
|
const responseName = resolver.response.response(node);
|
|
1698
1749
|
const responsesWithSchema = node.responses.filter(hasSchema);
|
|
1699
|
-
if (new Set(responsesWithSchema.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ?
|
|
1700
|
-
name: resolveImportName({
|
|
1701
|
-
schemaName,
|
|
1702
|
-
enumOptions,
|
|
1703
|
-
enumSchemaNames,
|
|
1704
|
-
resolver
|
|
1705
|
-
}),
|
|
1706
|
-
path: ""
|
|
1707
|
-
})).flatMap((imp) => Array.isArray(imp.name) ? imp.name : [imp.name]) : []))).has(responseName)) return null;
|
|
1750
|
+
if (new Set(responsesWithSchema.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ? collectRefNames(entry.schema).map(importName) : []))).has(responseName)) return null;
|
|
1708
1751
|
return renderSchemaType({
|
|
1709
1752
|
schema: {
|
|
1710
1753
|
...buildResponseUnion(node, { resolver }),
|
|
@@ -1771,38 +1814,12 @@ const resolverTs = createResolver({
|
|
|
1771
1814
|
name(name) {
|
|
1772
1815
|
return ensureValidVarName(pascalCase(name));
|
|
1773
1816
|
},
|
|
1774
|
-
file:
|
|
1775
|
-
|
|
1776
|
-
} },
|
|
1777
|
-
param: {
|
|
1778
|
-
name(node, param) {
|
|
1779
|
-
return this.name(`${node.operationId} ${param.in} ${param.name}`);
|
|
1780
|
-
},
|
|
1781
|
-
path(node) {
|
|
1782
|
-
return this.name(`${node.operationId} Path`);
|
|
1783
|
-
},
|
|
1784
|
-
query(node) {
|
|
1785
|
-
return this.name(`${node.operationId} Query`);
|
|
1786
|
-
},
|
|
1787
|
-
headers(node) {
|
|
1788
|
-
return this.name(`${node.operationId} Headers`);
|
|
1789
|
-
}
|
|
1790
|
-
},
|
|
1817
|
+
file: createCasedFile(pascalCase),
|
|
1818
|
+
param: createOperationParamResolver(),
|
|
1791
1819
|
response: {
|
|
1792
|
-
|
|
1793
|
-
return this.name(`${node.operationId} Status ${statusCode}`);
|
|
1794
|
-
},
|
|
1820
|
+
...createOperationResponseResolver(),
|
|
1795
1821
|
options(node) {
|
|
1796
1822
|
return this.name(`${node.operationId} Options`);
|
|
1797
|
-
},
|
|
1798
|
-
responses(node) {
|
|
1799
|
-
return this.name(`${node.operationId} Responses`);
|
|
1800
|
-
},
|
|
1801
|
-
response(node) {
|
|
1802
|
-
return this.name(`${node.operationId} Response`);
|
|
1803
|
-
},
|
|
1804
|
-
body(node) {
|
|
1805
|
-
return this.name(`${node.operationId} Body`);
|
|
1806
1823
|
}
|
|
1807
1824
|
},
|
|
1808
1825
|
enum: { keyName(node, enumTypeSuffix = "key") {
|