@kubb/plugin-ts 5.0.0-beta.86 → 5.0.0-beta.94
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 +34 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +34 -16
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
|
|
|
2
2
|
import { KubbReactNode } from "kubb/jsx";
|
|
3
3
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
4
4
|
import ts from "typescript";
|
|
5
|
-
|
|
6
5
|
//#region src/printers/printerTs.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Partial map of node-type overrides for the TypeScript printer.
|
|
@@ -525,7 +524,7 @@ declare const pluginTsName = "plugin-ts";
|
|
|
525
524
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
526
525
|
*
|
|
527
526
|
* export default defineConfig({
|
|
528
|
-
* input:
|
|
527
|
+
* input: './petStore.yaml',
|
|
529
528
|
* output: { path: './src/gen' },
|
|
530
529
|
* plugins: [
|
|
531
530
|
* pluginTs({
|
package/dist/index.js
CHANGED
|
@@ -542,7 +542,7 @@ function createInterfaceDeclaration({ modifiers, name, typeParameters, members }
|
|
|
542
542
|
* Intelligently selects the syntax based on the type structure and attaches JSDoc comments.
|
|
543
543
|
*/
|
|
544
544
|
function createTypeDeclaration({ syntax, isExportable, comments, name, type }) {
|
|
545
|
-
if (syntax === "interface" &&
|
|
545
|
+
if (syntax === "interface" && ts.isTypeLiteralNode(type)) return appendJSDocToNode({
|
|
546
546
|
node: createInterfaceDeclaration({
|
|
547
547
|
members: [...type.members],
|
|
548
548
|
modifiers: isExportable ? [modifiers.export] : [],
|
|
@@ -641,7 +641,7 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
|
|
|
641
641
|
}).filter((node) => node !== void 0)))];
|
|
642
642
|
if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(ts.SyntaxKind.ConstKeyword) : void 0].filter((modifier) => modifier !== void 0), factory.createIdentifier(typeName), enums.map(([key, value, description]) => {
|
|
643
643
|
let initializer = factory.createStringLiteral(value?.toString());
|
|
644
|
-
if (Number.parseInt(value.toString(), 10) === value && isNumber(
|
|
644
|
+
if (Number.parseInt(value.toString(), 10) === value && isNumber(value)) if (value < 0) initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
645
645
|
else initializer = factory.createNumericLiteral(value);
|
|
646
646
|
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
647
647
|
if (isNumber(Number.parseInt(key.toString(), 10))) {
|
|
@@ -916,13 +916,13 @@ function Enum({ node, enum: enumOptions, resolver }) {
|
|
|
916
916
|
isExportable: true,
|
|
917
917
|
isIndexable: true,
|
|
918
918
|
isTypeOnly: false,
|
|
919
|
-
children: parserTs.print(nameNode)
|
|
919
|
+
children: parserTs().print(nameNode)
|
|
920
920
|
}), /* @__PURE__ */ jsx(File.Source, {
|
|
921
921
|
name: typeName,
|
|
922
922
|
isIndexable: !namesMerge,
|
|
923
923
|
isExportable: !namesMerge && ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumOptions.type),
|
|
924
924
|
isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumOptions.type),
|
|
925
|
-
children: parserTs.print(typeNode)
|
|
925
|
+
children: parserTs().print(typeNode)
|
|
926
926
|
})] });
|
|
927
927
|
}
|
|
928
928
|
//#endregion
|
|
@@ -1023,6 +1023,24 @@ function getOperationParameters(node, options = {}) {
|
|
|
1023
1023
|
};
|
|
1024
1024
|
}
|
|
1025
1025
|
//#endregion
|
|
1026
|
+
//#region ../../internals/shared/src/adapter.ts
|
|
1027
|
+
/**
|
|
1028
|
+
* Narrows the generic `Adapter` from a generator context to the OpenAPI adapter,
|
|
1029
|
+
* so OAS-only options (`dateType`, `nameMapping`) and the parsed `document` are typed.
|
|
1030
|
+
*
|
|
1031
|
+
* Throws when a non-OAS adapter is configured, turning a silently wrong cast into a
|
|
1032
|
+
* clear, actionable error at the point of use.
|
|
1033
|
+
*
|
|
1034
|
+
* @example
|
|
1035
|
+
* ```ts
|
|
1036
|
+
* const { dateType } = getOasAdapter(ctx.adapter).options
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
1039
|
+
function getOasAdapter(adapter) {
|
|
1040
|
+
if (adapter.name !== "oas") throw new Error(`Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}". Configure \`adapter: adapterOas()\` in your Kubb config.`);
|
|
1041
|
+
return adapter;
|
|
1042
|
+
}
|
|
1043
|
+
//#endregion
|
|
1026
1044
|
//#region ../../internals/shared/src/group.ts
|
|
1027
1045
|
/**
|
|
1028
1046
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
@@ -1090,7 +1108,7 @@ function buildPropertyJSDocComments(schema, optional) {
|
|
|
1090
1108
|
!isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
|
|
1091
1109
|
!isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
|
|
1092
1110
|
meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
|
|
1093
|
-
meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" ? stringify(meta.default) : meta.default}` : null,
|
|
1111
|
+
meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : meta.default}` : null,
|
|
1094
1112
|
...exampleValues.map((example) => `@example ${example}`),
|
|
1095
1113
|
meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null
|
|
1096
1114
|
].filter(Boolean);
|
|
@@ -1401,7 +1419,7 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1401
1419
|
if (!name) {
|
|
1402
1420
|
const withNullable = meta.nullable ? createUnionDeclaration({ nodes: [transformed, keywordTypeNodes.null] }) : transformed;
|
|
1403
1421
|
const result = (meta.nullish || meta.optional) && addsUndefined ? createUnionDeclaration({ nodes: [withNullable, keywordTypeNodes.undefined] }) : withNullable;
|
|
1404
|
-
return parserTs.print(result);
|
|
1422
|
+
return parserTs().print(result);
|
|
1405
1423
|
}
|
|
1406
1424
|
const inner = (() => {
|
|
1407
1425
|
const omitted = keysToOmit?.length ? createOmitDeclaration({
|
|
@@ -1422,7 +1440,7 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1422
1440
|
description
|
|
1423
1441
|
})
|
|
1424
1442
|
});
|
|
1425
|
-
return parserTs.print(typeNode);
|
|
1443
|
+
return parserTs().print(typeNode);
|
|
1426
1444
|
}
|
|
1427
1445
|
};
|
|
1428
1446
|
});
|
|
@@ -1487,7 +1505,7 @@ const typeGenerator = defineGenerator({
|
|
|
1487
1505
|
description: node.description,
|
|
1488
1506
|
resolver,
|
|
1489
1507
|
enumSchemaNames,
|
|
1490
|
-
nameMapping: adapter.options.nameMapping,
|
|
1508
|
+
nameMapping: getOasAdapter(adapter).options.nameMapping,
|
|
1491
1509
|
nodes: printer?.nodes
|
|
1492
1510
|
});
|
|
1493
1511
|
return /* @__PURE__ */ jsxs(File, {
|
|
@@ -1569,7 +1587,7 @@ const typeGenerator = defineGenerator({
|
|
|
1569
1587
|
keysToOmit,
|
|
1570
1588
|
resolver,
|
|
1571
1589
|
enumSchemaNames,
|
|
1572
|
-
nameMapping: adapter.options.nameMapping,
|
|
1590
|
+
nameMapping: getOasAdapter(adapter).options.nameMapping,
|
|
1573
1591
|
nodes: printer?.nodes
|
|
1574
1592
|
});
|
|
1575
1593
|
return /* @__PURE__ */ jsxs(Fragment, { children: [imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
@@ -1810,7 +1828,7 @@ const pluginTsName = "plugin-ts";
|
|
|
1810
1828
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1811
1829
|
*
|
|
1812
1830
|
* export default defineConfig({
|
|
1813
|
-
* input:
|
|
1831
|
+
* input: './petStore.yaml',
|
|
1814
1832
|
* output: { path: './src/gen' },
|
|
1815
1833
|
* plugins: [
|
|
1816
1834
|
* pluginTs({
|
|
@@ -2047,14 +2065,14 @@ function renderGroupType(type, sorted, transformType) {
|
|
|
2047
2065
|
}
|
|
2048
2066
|
function printParameter(node, options) {
|
|
2049
2067
|
const { mode, transformName, transformType } = options;
|
|
2050
|
-
const
|
|
2068
|
+
const bindingName = node.name;
|
|
2051
2069
|
if (mode === "call") {
|
|
2052
|
-
if (
|
|
2053
|
-
const name = transformName ? transformName(
|
|
2070
|
+
if (typeof bindingName !== "string") return `{ ${sortedGroupMembers(bindingName, node.type).map((member) => renderBindingMember(member)).join(", ")} }`;
|
|
2071
|
+
const name = transformName ? transformName(bindingName) : bindingName;
|
|
2054
2072
|
return node.rest ? `...${name}` : name;
|
|
2055
2073
|
}
|
|
2056
|
-
if (
|
|
2057
|
-
const sorted = sortedGroupMembers(
|
|
2074
|
+
if (typeof bindingName !== "string") {
|
|
2075
|
+
const sorted = sortedGroupMembers(bindingName, node.type);
|
|
2058
2076
|
const binding = `{ ${sorted.map((member) => renderBindingMember(member, transformName)).join(", ")} }`;
|
|
2059
2077
|
const allOptional = sorted.every((member) => member.optional);
|
|
2060
2078
|
const type = renderGroupType(node.type, sorted, transformType);
|
|
@@ -2064,7 +2082,7 @@ function printParameter(node, options) {
|
|
|
2064
2082
|
}
|
|
2065
2083
|
return node.default ? `${binding} = ${node.default}` : binding;
|
|
2066
2084
|
}
|
|
2067
|
-
const name = transformName ? transformName(
|
|
2085
|
+
const name = transformName ? transformName(bindingName) : bindingName;
|
|
2068
2086
|
const type = node.type ? renderType(node.type, transformType) : void 0;
|
|
2069
2087
|
if (node.rest) return type ? `...${name}: ${type}` : `...${name}`;
|
|
2070
2088
|
if (type) {
|