@kubb/plugin-ts 5.0.0-beta.87 → 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.cjs
CHANGED
|
@@ -374,7 +374,6 @@ const PARAM_RANK = {
|
|
|
374
374
|
//#endregion
|
|
375
375
|
//#region src/factory.ts
|
|
376
376
|
var factory_exports = /* @__PURE__ */ __exportAll({
|
|
377
|
-
SyntaxKind: () => SyntaxKind,
|
|
378
377
|
appendJSDocToNode: () => appendJSDocToNode,
|
|
379
378
|
buildIndexSignatures: () => buildIndexSignatures,
|
|
380
379
|
buildMemberNodes: () => buildMemberNodes,
|
|
@@ -382,29 +381,15 @@ var factory_exports = /* @__PURE__ */ __exportAll({
|
|
|
382
381
|
buildTupleNode: () => buildTupleNode,
|
|
383
382
|
constToTypeNode: () => constToTypeNode,
|
|
384
383
|
createArrayDeclaration: () => createArrayDeclaration,
|
|
385
|
-
createArrayTypeNode: () => createArrayTypeNode,
|
|
386
384
|
createEnumDeclaration: () => createEnumDeclaration,
|
|
387
385
|
createExportDeclaration: () => createExportDeclaration,
|
|
388
|
-
createFalse: () => createFalse,
|
|
389
|
-
createIdentifier: () => createIdentifier,
|
|
390
386
|
createImportDeclaration: () => createImportDeclaration,
|
|
391
|
-
createIndexSignature: () => createIndexSignature,
|
|
392
|
-
createInterfaceDeclaration: () => createInterfaceDeclaration,
|
|
393
387
|
createIntersectionDeclaration: () => createIntersectionDeclaration,
|
|
394
388
|
createJSDoc: () => createJSDoc,
|
|
395
|
-
createLiteralTypeNode: () => createLiteralTypeNode,
|
|
396
|
-
createNumericLiteral: () => createNumericLiteral,
|
|
397
389
|
createOmitDeclaration: () => createOmitDeclaration,
|
|
398
|
-
createOptionalTypeNode: () => createOptionalTypeNode,
|
|
399
390
|
createParameterSignature: () => createParameterSignature,
|
|
400
|
-
createPrefixUnaryExpression: () => createPrefixUnaryExpression,
|
|
401
391
|
createPropertySignature: () => createPropertySignature,
|
|
402
392
|
createQuestionToken: () => createQuestionToken,
|
|
403
|
-
createRestTypeNode: () => createRestTypeNode,
|
|
404
|
-
createStringLiteral: () => createStringLiteral,
|
|
405
|
-
createTrue: () => createTrue,
|
|
406
|
-
createTupleTypeNode: () => createTupleTypeNode,
|
|
407
|
-
createTypeAliasDeclaration: () => createTypeAliasDeclaration,
|
|
408
393
|
createTypeDeclaration: () => createTypeDeclaration,
|
|
409
394
|
createTypeLiteralNode: () => createTypeLiteralNode,
|
|
410
395
|
createTypeReferenceNode: () => createTypeReferenceNode,
|
|
@@ -1062,22 +1047,93 @@ function getOperationParameters(node, options = {}) {
|
|
|
1062
1047
|
};
|
|
1063
1048
|
}
|
|
1064
1049
|
//#endregion
|
|
1065
|
-
//#region ../../internals/shared/src/
|
|
1050
|
+
//#region ../../internals/shared/src/resolver.ts
|
|
1066
1051
|
/**
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1052
|
+
* Resolves a single operation parameter name with the
|
|
1053
|
+
* `<operationId> <in> <name>` template.
|
|
1069
1054
|
*
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* `operationParamName.call(resolver, node, param) // → 'DeletePetPathPetId'`
|
|
1057
|
+
*/
|
|
1058
|
+
function operationParamName(node, param) {
|
|
1059
|
+
return this.name(`${node.operationId} ${param.in} ${param.name}`);
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Builds the shared `param` namespace. Spread the result into `createResolver`
|
|
1063
|
+
* and override individual methods next to it when a plugin deviates.
|
|
1064
|
+
*
|
|
1065
|
+
* @example
|
|
1066
|
+
* ```ts
|
|
1067
|
+
* createResolver<PluginTs>({ param: createOperationParamResolver(), ... })
|
|
1068
|
+
* ```
|
|
1069
|
+
*/
|
|
1070
|
+
function createOperationParamResolver() {
|
|
1071
|
+
return {
|
|
1072
|
+
name: operationParamName,
|
|
1073
|
+
path(node) {
|
|
1074
|
+
return this.name(`${node.operationId} Path`);
|
|
1075
|
+
},
|
|
1076
|
+
query(node) {
|
|
1077
|
+
return this.name(`${node.operationId} Query`);
|
|
1078
|
+
},
|
|
1079
|
+
headers(node) {
|
|
1080
|
+
return this.name(`${node.operationId} Headers`);
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Builds the shared `response` namespace. Spread the result into
|
|
1086
|
+
* `createResolver` and add plugin-specific methods (`options`, `error`) next
|
|
1087
|
+
* to it.
|
|
1072
1088
|
*
|
|
1073
1089
|
* @example
|
|
1074
1090
|
* ```ts
|
|
1075
|
-
*
|
|
1091
|
+
* createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })
|
|
1076
1092
|
* ```
|
|
1077
1093
|
*/
|
|
1078
|
-
function
|
|
1079
|
-
|
|
1080
|
-
|
|
1094
|
+
function createOperationResponseResolver() {
|
|
1095
|
+
return {
|
|
1096
|
+
status(node, statusCode) {
|
|
1097
|
+
return this.name(`${node.operationId} Status ${statusCode}`);
|
|
1098
|
+
},
|
|
1099
|
+
body(node) {
|
|
1100
|
+
return this.name(`${node.operationId} Body`);
|
|
1101
|
+
},
|
|
1102
|
+
responses(node) {
|
|
1103
|
+
return this.name(`${node.operationId} Responses`);
|
|
1104
|
+
},
|
|
1105
|
+
response(node) {
|
|
1106
|
+
return this.name(`${node.operationId} Response`);
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Builds a resolver `file` override whose base name runs every path segment
|
|
1112
|
+
* through `toFilePath`, casing the final segment with `caseLast`.
|
|
1113
|
+
*
|
|
1114
|
+
* @example
|
|
1115
|
+
* ```ts
|
|
1116
|
+
* createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })
|
|
1117
|
+
* ```
|
|
1118
|
+
*/
|
|
1119
|
+
function createCasedFile(caseLast) {
|
|
1120
|
+
return { baseName({ name, extname }) {
|
|
1121
|
+
return `${toFilePath(name, caseLast)}${extname}`;
|
|
1122
|
+
} };
|
|
1123
|
+
}
|
|
1124
|
+
//#endregion
|
|
1125
|
+
//#region ../../internals/shared/src/refs.ts
|
|
1126
|
+
/**
|
|
1127
|
+
* Collects the resolved target name of every pointer-carrying ref in a schema tree, in
|
|
1128
|
+
* first-occurrence order. Use this for name-only checks (e.g. redeclaration detection) where
|
|
1129
|
+
* `resolver.imports` would resolve file paths that are then discarded.
|
|
1130
|
+
*/
|
|
1131
|
+
function collectRefNames(schema) {
|
|
1132
|
+
return kubb_kit.ast.collect(schema, { schema: (node) => {
|
|
1133
|
+
const refNode = kubb_kit.ast.narrowSchema(node, "ref");
|
|
1134
|
+
if (!refNode?.ref) return null;
|
|
1135
|
+
return kubb_kit.ast.resolveRefName(refNode);
|
|
1136
|
+
} });
|
|
1081
1137
|
}
|
|
1082
1138
|
//#endregion
|
|
1083
1139
|
//#region ../../internals/shared/src/group.ts
|
|
@@ -1379,7 +1435,8 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1379
1435
|
time: dateOrStringNode,
|
|
1380
1436
|
ref(node) {
|
|
1381
1437
|
if (!node.name) return null;
|
|
1382
|
-
const refName =
|
|
1438
|
+
const refName = kubb_kit.ast.resolveRefName(node);
|
|
1439
|
+
if (!refName) return null;
|
|
1383
1440
|
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);
|
|
1384
1441
|
},
|
|
1385
1442
|
enum(node) {
|
|
@@ -1505,24 +1562,22 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1505
1562
|
renderer: kubb_jsx.jsxRenderer,
|
|
1506
1563
|
schema(node, ctx) {
|
|
1507
1564
|
const { enum: enumOptions, syntaxType, optionalType, arrayType, output, group, printer } = ctx.options;
|
|
1508
|
-
const {
|
|
1565
|
+
const { config, resolver, root } = ctx;
|
|
1509
1566
|
if (!node.name) return;
|
|
1510
1567
|
const enumSchemaNames = new Set(ctx.meta.enumNames);
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
}).path
|
|
1525
|
-
}));
|
|
1568
|
+
const importName = (schemaName) => resolveImportName({
|
|
1569
|
+
schemaName,
|
|
1570
|
+
enumOptions,
|
|
1571
|
+
enumSchemaNames,
|
|
1572
|
+
resolver
|
|
1573
|
+
});
|
|
1574
|
+
const imports = resolver.imports({
|
|
1575
|
+
node,
|
|
1576
|
+
root,
|
|
1577
|
+
output,
|
|
1578
|
+
group: group ?? void 0,
|
|
1579
|
+
name: importName
|
|
1580
|
+
});
|
|
1526
1581
|
const enumNode = kubb_kit.ast.narrowSchema(node, kubb_kit.ast.schemaTypes.enum);
|
|
1527
1582
|
const isEnumSchema = !!enumNode && !isInlineConstEnum(enumNode, enumSchemaNames);
|
|
1528
1583
|
const meta = {
|
|
@@ -1544,7 +1599,6 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1544
1599
|
description: node.description,
|
|
1545
1600
|
resolver,
|
|
1546
1601
|
enumSchemaNames,
|
|
1547
|
-
nameMapping: getOasAdapter(adapter).options.nameMapping,
|
|
1548
1602
|
nodes: printer?.nodes
|
|
1549
1603
|
});
|
|
1550
1604
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
@@ -1587,7 +1641,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1587
1641
|
},
|
|
1588
1642
|
operation(node, ctx) {
|
|
1589
1643
|
const { enum: enumOptions, optionalType, arrayType, syntaxType, group, output, printer } = ctx.options;
|
|
1590
|
-
const {
|
|
1644
|
+
const { config, resolver, root } = ctx;
|
|
1591
1645
|
const params = caseParams(node.parameters, "camelcase");
|
|
1592
1646
|
const meta = { file: resolver.file({
|
|
1593
1647
|
name: node.operationId,
|
|
@@ -1599,23 +1653,21 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1599
1653
|
group: group ?? void 0
|
|
1600
1654
|
}) };
|
|
1601
1655
|
const enumSchemaNames = new Set(ctx.meta.enumNames);
|
|
1656
|
+
const importName = (schemaName) => resolveImportName({
|
|
1657
|
+
schemaName,
|
|
1658
|
+
enumOptions,
|
|
1659
|
+
enumSchemaNames,
|
|
1660
|
+
resolver
|
|
1661
|
+
});
|
|
1602
1662
|
function renderSchemaType({ schema, name, keysToOmit }) {
|
|
1603
1663
|
if (!schema) return null;
|
|
1604
|
-
const imports =
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
path: resolver.file({
|
|
1612
|
-
name: schemaName,
|
|
1613
|
-
extname: ".ts",
|
|
1614
|
-
root,
|
|
1615
|
-
output,
|
|
1616
|
-
group: group ?? void 0
|
|
1617
|
-
}).path
|
|
1618
|
-
}));
|
|
1664
|
+
const imports = resolver.imports({
|
|
1665
|
+
node: schema,
|
|
1666
|
+
root,
|
|
1667
|
+
output,
|
|
1668
|
+
group: group ?? void 0,
|
|
1669
|
+
name: importName
|
|
1670
|
+
});
|
|
1619
1671
|
const schemaPrinter = printerTs({
|
|
1620
1672
|
optionalType,
|
|
1621
1673
|
arrayType,
|
|
@@ -1626,7 +1678,6 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1626
1678
|
keysToOmit,
|
|
1627
1679
|
resolver,
|
|
1628
1680
|
enumSchemaNames,
|
|
1629
|
-
nameMapping: getOasAdapter(adapter).options.nameMapping,
|
|
1630
1681
|
nodes: printer?.nodes
|
|
1631
1682
|
});
|
|
1632
1683
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [imports.map((imp) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
@@ -1735,15 +1786,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1735
1786
|
if (!node.responses.some(hasSchema)) return null;
|
|
1736
1787
|
const responseName = resolver.response.response(node);
|
|
1737
1788
|
const responsesWithSchema = node.responses.filter(hasSchema);
|
|
1738
|
-
if (new Set(responsesWithSchema.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ?
|
|
1739
|
-
name: resolveImportName({
|
|
1740
|
-
schemaName,
|
|
1741
|
-
enumOptions,
|
|
1742
|
-
enumSchemaNames,
|
|
1743
|
-
resolver
|
|
1744
|
-
}),
|
|
1745
|
-
path: ""
|
|
1746
|
-
})).flatMap((imp) => Array.isArray(imp.name) ? imp.name : [imp.name]) : []))).has(responseName)) return null;
|
|
1789
|
+
if (new Set(responsesWithSchema.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ? collectRefNames(entry.schema).map(importName) : []))).has(responseName)) return null;
|
|
1747
1790
|
return renderSchemaType({
|
|
1748
1791
|
schema: {
|
|
1749
1792
|
...buildResponseUnion(node, { resolver }),
|
|
@@ -1810,38 +1853,12 @@ const resolverTs = (0, kubb_kit.createResolver)({
|
|
|
1810
1853
|
name(name) {
|
|
1811
1854
|
return ensureValidVarName(pascalCase(name));
|
|
1812
1855
|
},
|
|
1813
|
-
file:
|
|
1814
|
-
|
|
1815
|
-
} },
|
|
1816
|
-
param: {
|
|
1817
|
-
name(node, param) {
|
|
1818
|
-
return this.name(`${node.operationId} ${param.in} ${param.name}`);
|
|
1819
|
-
},
|
|
1820
|
-
path(node) {
|
|
1821
|
-
return this.name(`${node.operationId} Path`);
|
|
1822
|
-
},
|
|
1823
|
-
query(node) {
|
|
1824
|
-
return this.name(`${node.operationId} Query`);
|
|
1825
|
-
},
|
|
1826
|
-
headers(node) {
|
|
1827
|
-
return this.name(`${node.operationId} Headers`);
|
|
1828
|
-
}
|
|
1829
|
-
},
|
|
1856
|
+
file: createCasedFile(pascalCase),
|
|
1857
|
+
param: createOperationParamResolver(),
|
|
1830
1858
|
response: {
|
|
1831
|
-
|
|
1832
|
-
return this.name(`${node.operationId} Status ${statusCode}`);
|
|
1833
|
-
},
|
|
1859
|
+
...createOperationResponseResolver(),
|
|
1834
1860
|
options(node) {
|
|
1835
1861
|
return this.name(`${node.operationId} Options`);
|
|
1836
|
-
},
|
|
1837
|
-
responses(node) {
|
|
1838
|
-
return this.name(`${node.operationId} Responses`);
|
|
1839
|
-
},
|
|
1840
|
-
response(node) {
|
|
1841
|
-
return this.name(`${node.operationId} Response`);
|
|
1842
|
-
},
|
|
1843
|
-
body(node) {
|
|
1844
|
-
return this.name(`${node.operationId} Body`);
|
|
1845
1862
|
}
|
|
1846
1863
|
},
|
|
1847
1864
|
enum: { keyName(node, enumTypeSuffix = "key") {
|