@kubb/plugin-ts 5.4.0-canary.20261029T093900 → 5.4.0
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 +101 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +25 -6
- package/dist/index.js.map +1 -1
- package/docs/guides/customization.md +1 -1
- package/package.json +10 -6
package/dist/index.cjs
CHANGED
|
@@ -17,11 +17,11 @@ var __exportAll = (all, no_symbols) => {
|
|
|
17
17
|
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
18
|
return target;
|
|
19
19
|
};
|
|
20
|
-
let
|
|
21
|
-
let
|
|
20
|
+
let _kubb_kit = require("@kubb/kit");
|
|
21
|
+
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
22
22
|
let yuku_codegen = require("yuku-codegen");
|
|
23
|
-
let
|
|
24
|
-
let
|
|
23
|
+
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
24
|
+
let node_module = require("node:module");
|
|
25
25
|
// ../../internals/utils/src/casing.ts
|
|
26
26
|
const wordStart = /(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z]{2})(?=[A-Z][a-z]{2})/;
|
|
27
27
|
/**
|
|
@@ -262,9 +262,9 @@ function jsDocEscape(input) {
|
|
|
262
262
|
* @example Suffix applied to the final segment only
|
|
263
263
|
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
264
264
|
*/
|
|
265
|
-
function toFilePath(name, caseLast =
|
|
265
|
+
function toFilePath(name, caseLast = _kubb_kit.camelCase) {
|
|
266
266
|
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
267
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : (0,
|
|
267
|
+
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : (0, _kubb_kit.camelCase)(part)).filter(Boolean).join("/");
|
|
268
268
|
}
|
|
269
269
|
// src/factory.ts
|
|
270
270
|
var factory_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -520,8 +520,8 @@ function applyEnumKeyCasing(key, casing = "none") {
|
|
|
520
520
|
if (casing === "none") return key;
|
|
521
521
|
if (casing === "screamingSnakeCase") return screamingSnakeCase(key);
|
|
522
522
|
if (casing === "snakeCase") return snakeCase(key);
|
|
523
|
-
if (casing === "pascalCase") return (0,
|
|
524
|
-
if (casing === "camelCase") return (0,
|
|
523
|
+
if (casing === "pascalCase") return (0, _kubb_kit.pascalCase)(key);
|
|
524
|
+
if (casing === "camelCase") return (0, _kubb_kit.camelCase)(key);
|
|
525
525
|
return key;
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
@@ -724,7 +724,7 @@ function wrapNullableOptional(type, nullable, addsUndefined) {
|
|
|
724
724
|
*/
|
|
725
725
|
function buildPropertyType(schema, baseType, optionalType, optional) {
|
|
726
726
|
const addsUndefined = optionalType === "undefined" || optionalType === "questionTokenAndUndefined";
|
|
727
|
-
const meta = (0,
|
|
727
|
+
const meta = (0, _kubb_kit.syncSchemaRef)(schema);
|
|
728
728
|
return wrapNullableOptional(baseType, !!meta.nullable, addsUndefined && !!(optional || meta.nullish || meta.optional));
|
|
729
729
|
}
|
|
730
730
|
/**
|
|
@@ -778,7 +778,7 @@ function buildIndexSignatures(node, propertyCount, printNode) {
|
|
|
778
778
|
function getEnumNames$1({ node, enum: enumOptions, resolver }) {
|
|
779
779
|
const resolved = resolver.name(node.name);
|
|
780
780
|
return {
|
|
781
|
-
enumName: enumOptions.constCasing === "pascalCase" ? resolved : ensureValidVarName((0,
|
|
781
|
+
enumName: enumOptions.constCasing === "pascalCase" ? resolved : ensureValidVarName((0, _kubb_kit.camelCase)(node.name)),
|
|
782
782
|
typeName: enumOptions.type === "asConst" ? resolver.enum.keyName(node, enumOptions.typeSuffix) : resolved
|
|
783
783
|
};
|
|
784
784
|
}
|
|
@@ -812,14 +812,14 @@ function Enum({ node, enum: enumOptions, resolver }) {
|
|
|
812
812
|
enumKeyCasing: enumOptions.keyCasing
|
|
813
813
|
});
|
|
814
814
|
const namesMerge = !!nameNode && enumName === typeName;
|
|
815
|
-
return /* @__PURE__ */ (0,
|
|
815
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [nameNode && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
816
816
|
name: enumName,
|
|
817
817
|
pointer: node.pointer,
|
|
818
818
|
isExportable: true,
|
|
819
819
|
isIndexable: true,
|
|
820
820
|
isTypeOnly: false,
|
|
821
821
|
children: nameNode
|
|
822
|
-
}), /* @__PURE__ */ (0,
|
|
822
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
823
823
|
name: typeName,
|
|
824
824
|
pointer: node.pointer,
|
|
825
825
|
isIndexable: !namesMerge,
|
|
@@ -921,7 +921,7 @@ function hasRequestContentTypeChoice(node) {
|
|
|
921
921
|
function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
922
922
|
const { path, query, header } = getOperationParameters(node);
|
|
923
923
|
const hasBody = Boolean(node.requestBody?.content?.[0]?.schema);
|
|
924
|
-
const createNever = () =>
|
|
924
|
+
const createNever = () => _kubb_kit.ast.factory.createSchema({
|
|
925
925
|
type: "never",
|
|
926
926
|
primitive: void 0,
|
|
927
927
|
optional: true
|
|
@@ -943,22 +943,22 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
943
943
|
resolve: resolver.param.headers
|
|
944
944
|
}
|
|
945
945
|
];
|
|
946
|
-
const createOptions = (body, extra = []) =>
|
|
946
|
+
const createOptions = (body, extra = []) => _kubb_kit.ast.factory.createSchema({
|
|
947
947
|
type: "object",
|
|
948
948
|
primitive: "object",
|
|
949
949
|
deprecated: node.deprecated,
|
|
950
950
|
properties: [
|
|
951
|
-
|
|
951
|
+
_kubb_kit.ast.factory.createProperty({
|
|
952
952
|
name: "body",
|
|
953
953
|
required: hasBody,
|
|
954
954
|
schema: body
|
|
955
955
|
}),
|
|
956
956
|
...groups.map(({ name, params, resolve }) => {
|
|
957
957
|
const required = params.some((param) => param.required);
|
|
958
|
-
return
|
|
958
|
+
return _kubb_kit.ast.factory.createProperty({
|
|
959
959
|
name,
|
|
960
960
|
required,
|
|
961
|
-
schema: params.length > 0 ?
|
|
961
|
+
schema: params.length > 0 ? _kubb_kit.ast.factory.createSchema({
|
|
962
962
|
type: "ref",
|
|
963
963
|
name: resolve.call(resolver.param, node, params[0]),
|
|
964
964
|
optional: !required
|
|
@@ -969,25 +969,25 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
969
969
|
]
|
|
970
970
|
});
|
|
971
971
|
const variants = pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : [];
|
|
972
|
-
if (variants.length < 2) return createOptions(hasBody ?
|
|
972
|
+
if (variants.length < 2) return createOptions(hasBody ? _kubb_kit.ast.factory.createSchema({
|
|
973
973
|
type: "ref",
|
|
974
974
|
name: resolver.response.body(node)
|
|
975
975
|
}) : createNever());
|
|
976
|
-
return
|
|
976
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
977
977
|
type: "union",
|
|
978
|
-
members: variants.map((variant, index) => createOptions(
|
|
978
|
+
members: variants.map((variant, index) => createOptions(_kubb_kit.ast.factory.createSchema({
|
|
979
979
|
type: "ref",
|
|
980
980
|
name: variant.name
|
|
981
|
-
}), [
|
|
981
|
+
}), [_kubb_kit.ast.factory.createProperty({
|
|
982
982
|
name: "contentType",
|
|
983
983
|
required: index > 0,
|
|
984
|
-
schema:
|
|
984
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
985
985
|
type: "object",
|
|
986
986
|
primitive: "object",
|
|
987
|
-
properties: [
|
|
987
|
+
properties: [_kubb_kit.ast.factory.createProperty({
|
|
988
988
|
name: "request",
|
|
989
989
|
required: true,
|
|
990
|
-
schema:
|
|
990
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
991
991
|
type: "enum",
|
|
992
992
|
enumValues: [variant.contentType]
|
|
993
993
|
})
|
|
@@ -1005,26 +1005,26 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
1005
1005
|
function buildResponseRecordEntry(node, res, resolver) {
|
|
1006
1006
|
const statusName = resolver.response.status(node, res.statusCode);
|
|
1007
1007
|
const variants = (res.content ?? []).filter((entry) => entry.schema);
|
|
1008
|
-
if (variants.length <= 1) return
|
|
1008
|
+
if (variants.length <= 1) return _kubb_kit.ast.factory.createSchema({
|
|
1009
1009
|
type: "ref",
|
|
1010
1010
|
name: statusName
|
|
1011
1011
|
});
|
|
1012
|
-
return
|
|
1012
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
1013
1013
|
type: "union",
|
|
1014
|
-
members: resolveContentTypeVariants(variants, statusName).map((variant) =>
|
|
1014
|
+
members: resolveContentTypeVariants(variants, statusName).map((variant) => _kubb_kit.ast.factory.createSchema({
|
|
1015
1015
|
type: "object",
|
|
1016
1016
|
primitive: "object",
|
|
1017
|
-
properties: [
|
|
1017
|
+
properties: [_kubb_kit.ast.factory.createProperty({
|
|
1018
1018
|
name: "contentType",
|
|
1019
1019
|
required: true,
|
|
1020
|
-
schema:
|
|
1020
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
1021
1021
|
type: "enum",
|
|
1022
1022
|
enumValues: [variant.contentType]
|
|
1023
1023
|
})
|
|
1024
|
-
}),
|
|
1024
|
+
}), _kubb_kit.ast.factory.createProperty({
|
|
1025
1025
|
name: "data",
|
|
1026
1026
|
required: true,
|
|
1027
|
-
schema:
|
|
1027
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
1028
1028
|
type: "ref",
|
|
1029
1029
|
name: variant.name
|
|
1030
1030
|
})
|
|
@@ -1042,10 +1042,10 @@ function buildResponseRecordEntry(node, res, resolver) {
|
|
|
1042
1042
|
* SDK's `RequestResult<XResponses>`) resolvable instead of pointing at a missing export.
|
|
1043
1043
|
*/
|
|
1044
1044
|
function buildResponses(node, resolver) {
|
|
1045
|
-
return
|
|
1045
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
1046
1046
|
type: "object",
|
|
1047
1047
|
primitive: "object",
|
|
1048
|
-
properties: node.responses.map((res) =>
|
|
1048
|
+
properties: node.responses.map((res) => _kubb_kit.ast.factory.createProperty({
|
|
1049
1049
|
name: String(res.statusCode),
|
|
1050
1050
|
required: true,
|
|
1051
1051
|
schema: buildResponseRecordEntry(node, res, resolver)
|
|
@@ -1205,7 +1205,7 @@ function createGroupConfig(group) {
|
|
|
1205
1205
|
if (!group) return null;
|
|
1206
1206
|
const defaultName = (ctx) => {
|
|
1207
1207
|
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
1208
|
-
return (0,
|
|
1208
|
+
return (0, _kubb_kit.camelCase)(ctx.group);
|
|
1209
1209
|
};
|
|
1210
1210
|
return {
|
|
1211
1211
|
...group,
|
|
@@ -1245,7 +1245,7 @@ function mapSchemaItems(node, transform) {
|
|
|
1245
1245
|
* Renames inline enum declarations and their uses together.
|
|
1246
1246
|
*/
|
|
1247
1247
|
function resolveInlineEnumNames({ node, owner, resolver, enumOptions }) {
|
|
1248
|
-
return
|
|
1248
|
+
return _kubb_kit.ast.transform(node, { schema(child) {
|
|
1249
1249
|
if (child === node || child.type !== "enum" || !child.name) return;
|
|
1250
1250
|
const name = resolver.resolveName({
|
|
1251
1251
|
key: [
|
|
@@ -1302,7 +1302,7 @@ function formatExample(value) {
|
|
|
1302
1302
|
return (JSON.stringify(value) ?? String(value)).replaceAll("*/", "*\\/");
|
|
1303
1303
|
}
|
|
1304
1304
|
function buildPropertyJSDocComments(schema, optional) {
|
|
1305
|
-
const meta = (0,
|
|
1305
|
+
const meta = (0, _kubb_kit.syncSchemaRef)(schema);
|
|
1306
1306
|
const isArray = meta?.primitive === "array";
|
|
1307
1307
|
const isNumeric = meta?.primitive === "number" || meta?.primitive === "integer" || meta?.primitive === "bigint";
|
|
1308
1308
|
const hasDescription = meta && "description" in meta && meta.description;
|
|
@@ -1327,13 +1327,13 @@ function buildPropertyJSDocComments(schema, optional) {
|
|
|
1327
1327
|
* separate per-param type — the group itself is the only type these params get exported as.
|
|
1328
1328
|
*/
|
|
1329
1329
|
function buildParams({ params }) {
|
|
1330
|
-
return
|
|
1330
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
1331
1331
|
type: "object",
|
|
1332
1332
|
pointer: params[0]?.pointer?.replace(/\/\d+$/, ""),
|
|
1333
|
-
properties: params.map((param) =>
|
|
1333
|
+
properties: params.map((param) => _kubb_kit.ast.factory.createProperty({
|
|
1334
1334
|
name: param.name,
|
|
1335
1335
|
required: param.required,
|
|
1336
|
-
schema:
|
|
1336
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
1337
1337
|
...param.schema,
|
|
1338
1338
|
optional: !param.required
|
|
1339
1339
|
})
|
|
@@ -1345,9 +1345,9 @@ function buildResponseUnion(node, { resolver }) {
|
|
|
1345
1345
|
const successWithSchema = allWithSchema.filter((res) => isSuccessStatusCode(res.statusCode));
|
|
1346
1346
|
const responsesWithSchema = successWithSchema.length > 0 ? successWithSchema : allWithSchema;
|
|
1347
1347
|
if (responsesWithSchema.length === 0) return null;
|
|
1348
|
-
return
|
|
1348
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
1349
1349
|
type: "union",
|
|
1350
|
-
members: responsesWithSchema.map((res) =>
|
|
1350
|
+
members: responsesWithSchema.map((res) => _kubb_kit.ast.factory.createSchema({
|
|
1351
1351
|
type: "ref",
|
|
1352
1352
|
name: resolver.response.status(node, res.statusCode)
|
|
1353
1353
|
}))
|
|
@@ -1355,6 +1355,25 @@ function buildResponseUnion(node, { resolver }) {
|
|
|
1355
1355
|
}
|
|
1356
1356
|
// src/printers/printerTs.ts
|
|
1357
1357
|
const { isNonNullable } = factory_exports;
|
|
1358
|
+
const requireModule = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
1359
|
+
/**
|
|
1360
|
+
* Loads `@kubb/parser-ts` on first use. It is an optional peer dependency: only a deprecated `printer.nodes`
|
|
1361
|
+
* handler that returns a TypeScript compiler node needs it. Loads synchronously because node handlers are synchronous.
|
|
1362
|
+
*/
|
|
1363
|
+
function loadParserTs(load = () => requireModule("@kubb/parser-ts")) {
|
|
1364
|
+
try {
|
|
1365
|
+
return load();
|
|
1366
|
+
} catch (error) {
|
|
1367
|
+
if (error.code !== "MODULE_NOT_FOUND" || !error.message.split("\n")[0].includes("@kubb/parser-ts")) throw error;
|
|
1368
|
+
throw new _kubb_kit.Diagnostics.Error({
|
|
1369
|
+
code: _kubb_kit.Diagnostics.code.missingDependency,
|
|
1370
|
+
severity: "error",
|
|
1371
|
+
message: "Missing dependency: @kubb/parser-ts. A `printer.nodes` handler returned a TypeScript compiler node, and printing it needs @kubb/parser-ts.",
|
|
1372
|
+
help: "Run `npm i -D @kubb/parser-ts` in the project, or return a string from the handler.",
|
|
1373
|
+
plugin: "plugin-ts"
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1358
1377
|
/**
|
|
1359
1378
|
* Adapts user overrides, which work in strings, to the node-based printer: `this.transform` hands them printed
|
|
1360
1379
|
* strings and their result is wrapped back into a node. A deprecated compiler node prints through `@kubb/parser-ts`.
|
|
@@ -1370,7 +1389,7 @@ function toNodeHandlers(nodes) {
|
|
|
1370
1389
|
transform
|
|
1371
1390
|
}, node);
|
|
1372
1391
|
if (result === null || result === void 0) return result;
|
|
1373
|
-
return createRaw(typeof result === "string" ? result : (
|
|
1392
|
+
return createRaw(typeof result === "string" ? result : loadParserTs().parserTs().print(result).trimEnd());
|
|
1374
1393
|
}]));
|
|
1375
1394
|
}
|
|
1376
1395
|
/**
|
|
@@ -1396,7 +1415,7 @@ function toNodeHandlers(nodes) {
|
|
|
1396
1415
|
* const declaration = printer.print(schemaNode) // 'export type MyType = …'
|
|
1397
1416
|
* ```
|
|
1398
1417
|
*/
|
|
1399
|
-
const printerTs =
|
|
1418
|
+
const printerTs = _kubb_kit.ast.createPrinter((options) => {
|
|
1400
1419
|
const addsUndefined = options.optionalType === "undefined" || options.optionalType === "questionTokenAndUndefined";
|
|
1401
1420
|
return {
|
|
1402
1421
|
name: "typescript",
|
|
@@ -1426,7 +1445,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1426
1445
|
time: dateOrStringNode,
|
|
1427
1446
|
ref(node) {
|
|
1428
1447
|
if (!node.name) return null;
|
|
1429
|
-
const refName =
|
|
1448
|
+
const refName = _kubb_kit.ast.resolveRefName(node);
|
|
1430
1449
|
if (!refName) return null;
|
|
1431
1450
|
return createTypeReferenceNode(node.ref ? enumTypeName({
|
|
1432
1451
|
resolver: this.options.resolver,
|
|
@@ -1436,7 +1455,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1436
1455
|
}) : refName);
|
|
1437
1456
|
},
|
|
1438
1457
|
enum(node) {
|
|
1439
|
-
const values =
|
|
1458
|
+
const values = _kubb_kit.ast.getSchemaLiteralValues(node);
|
|
1440
1459
|
if (values.some((value) => value !== null && typeof value === "object")) return createUnionDeclaration({ nodes: values.map((value) => constToTypeNode(value)) });
|
|
1441
1460
|
if (this.options.enum.type === "inlineLiteral" || !node.name || isInlineConstEnum(node, this.options.enumSchemaNames)) return createUnionDeclaration({ nodes: values.filter((v) => v !== null && v !== void 0).map((value) => constToTypeNode(value, typeof value)).filter(isNonNullable) });
|
|
1442
1461
|
return createTypeReferenceNode(enumTypeName({
|
|
@@ -1449,11 +1468,11 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1449
1468
|
union(node) {
|
|
1450
1469
|
const members = node.members ?? [];
|
|
1451
1470
|
const hasStringLiteral = members.some((m) => {
|
|
1452
|
-
return
|
|
1471
|
+
return _kubb_kit.ast.narrowSchema(m, _kubb_kit.ast.schemaTypes.enum)?.primitive === "string";
|
|
1453
1472
|
});
|
|
1454
|
-
const hasPlainString = members.some((m) => (0,
|
|
1473
|
+
const hasPlainString = members.some((m) => (0, _kubb_kit.isStringType)(m));
|
|
1455
1474
|
if (hasStringLiteral && hasPlainString) return createUnionDeclaration({ nodes: members.map((m) => {
|
|
1456
|
-
if ((0,
|
|
1475
|
+
if ((0, _kubb_kit.isStringType)(m)) return createIntersectionDeclaration({ nodes: [keywordTypeNodes.string, createTypeLiteralNode([])] });
|
|
1457
1476
|
return this.transform(m);
|
|
1458
1477
|
}).filter(isNonNullable) });
|
|
1459
1478
|
return createUnionDeclaration({ nodes: buildMemberNodes(members, this.transform) });
|
|
@@ -1472,10 +1491,10 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1472
1491
|
},
|
|
1473
1492
|
object(node) {
|
|
1474
1493
|
const { transform, options } = this;
|
|
1475
|
-
const keySchema = node.propertyNames && (0,
|
|
1494
|
+
const keySchema = node.propertyNames && (0, _kubb_kit.syncSchemaRef)(node.propertyNames);
|
|
1476
1495
|
if (!node.properties.length && !Object.keys(node.patternProperties ?? {}).length && node.propertyNames && keySchema?.type === "enum" && node.additionalProperties !== false) {
|
|
1477
1496
|
const keyType = transform(node.propertyNames) ?? keywordTypeNodes.string;
|
|
1478
|
-
const valueSchema = typeof node.additionalProperties === "object" ? node.additionalProperties :
|
|
1497
|
+
const valueSchema = typeof node.additionalProperties === "object" ? node.additionalProperties : _kubb_kit.ast.factory.createSchema({ type: "unknown" });
|
|
1479
1498
|
return createTypeReferenceNode("Partial", [createTypeReferenceNode("Record", [keyType, buildPropertyType(valueSchema, transform(valueSchema) ?? keywordTypeNodes.unknown, options.optionalType, false)])]);
|
|
1480
1499
|
}
|
|
1481
1500
|
const addsQuestionToken = options.optionalType === "questionToken" || options.optionalType === "questionTokenAndUndefined";
|
|
@@ -1483,7 +1502,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1483
1502
|
const baseType = output ?? keywordTypeNodes.unknown;
|
|
1484
1503
|
const optional = !property.required || !!property.schema.optional || !!property.schema.nullish;
|
|
1485
1504
|
const type = buildPropertyType(property.schema, baseType, options.optionalType, optional);
|
|
1486
|
-
const propMeta = (0,
|
|
1505
|
+
const propMeta = (0, _kubb_kit.syncSchemaRef)(property.schema);
|
|
1487
1506
|
return appendJSDocToNode({
|
|
1488
1507
|
node: createPropertySignature({
|
|
1489
1508
|
questionToken: optional ? addsQuestionToken : false,
|
|
@@ -1504,7 +1523,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1504
1523
|
const { name, syntaxType = "type", description, keysToOmit } = this.options;
|
|
1505
1524
|
const transformed = this.transform(node);
|
|
1506
1525
|
if (!transformed) return null;
|
|
1507
|
-
const meta = (0,
|
|
1526
|
+
const meta = (0, _kubb_kit.syncSchemaRef)(node);
|
|
1508
1527
|
if (!name) return print(wrapNullableOptional(keysToOmit?.length ? createOmitDeclaration({
|
|
1509
1528
|
keys: keysToOmit,
|
|
1510
1529
|
type: transformed,
|
|
@@ -1532,7 +1551,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1532
1551
|
// src/components/Type.tsx
|
|
1533
1552
|
function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
1534
1553
|
if (inline) {
|
|
1535
|
-
const withoutEnums =
|
|
1554
|
+
const withoutEnums = _kubb_kit.ast.transform(node, { schema: (n) => n.type === _kubb_kit.ast.schemaTypes.enum && n.name ? {
|
|
1536
1555
|
...n,
|
|
1537
1556
|
name: void 0
|
|
1538
1557
|
} : void 0 });
|
|
@@ -1541,7 +1560,7 @@ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
|
1541
1560
|
name: void 0
|
|
1542
1561
|
}).print(withoutEnums)?.replace(/\/\*\*[\s\S]*?\*\/\s*/g, "");
|
|
1543
1562
|
if (!expression) return;
|
|
1544
|
-
return /* @__PURE__ */ (0,
|
|
1563
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1545
1564
|
name,
|
|
1546
1565
|
isTypeOnly: true,
|
|
1547
1566
|
isExportable: true,
|
|
@@ -1550,8 +1569,8 @@ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
|
1550
1569
|
children: expression
|
|
1551
1570
|
});
|
|
1552
1571
|
}
|
|
1553
|
-
const enumSchemaNodes =
|
|
1554
|
-
const enumNode =
|
|
1572
|
+
const enumSchemaNodes = _kubb_kit.ast.collectSync(node, { schema(n) {
|
|
1573
|
+
const enumNode = _kubb_kit.ast.narrowSchema(n, _kubb_kit.ast.schemaTypes.enum);
|
|
1555
1574
|
if (enumNode?.name && !isInlineConstEnum(enumNode, printer.options.enumSchemaNames)) return enumNode;
|
|
1556
1575
|
} });
|
|
1557
1576
|
const output = printer.print(node);
|
|
@@ -1569,15 +1588,15 @@ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
|
1569
1588
|
});
|
|
1570
1589
|
const shouldExportEnums = enumOptions.type !== "inlineLiteral";
|
|
1571
1590
|
const shouldExportType = enumOptions.type === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
1572
|
-
return /* @__PURE__ */ (0,
|
|
1591
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Enum, {
|
|
1573
1592
|
node,
|
|
1574
1593
|
enum: enumOptions,
|
|
1575
1594
|
resolver
|
|
1576
|
-
}, node.name)), shouldExportType && /* @__PURE__ */ (0,
|
|
1595
|
+
}, node.name)), shouldExportType && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [printerImports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, { ...imp }, [
|
|
1577
1596
|
name,
|
|
1578
1597
|
imp.path,
|
|
1579
1598
|
imp.name
|
|
1580
|
-
].join("-"))), /* @__PURE__ */ (0,
|
|
1599
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1581
1600
|
name,
|
|
1582
1601
|
pointer: node.pointer,
|
|
1583
1602
|
isTypeOnly: true,
|
|
@@ -1593,9 +1612,9 @@ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
|
1593
1612
|
* types. Drop-replace with a custom `Generator<PluginTs>` to change how
|
|
1594
1613
|
* TypeScript output is produced.
|
|
1595
1614
|
*/
|
|
1596
|
-
const typeGenerator = (0,
|
|
1615
|
+
const typeGenerator = (0, _kubb_kit.defineGenerator)({
|
|
1597
1616
|
name: "typescript",
|
|
1598
|
-
renderer:
|
|
1617
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1599
1618
|
schema(node, ctx) {
|
|
1600
1619
|
const { enum: enumOptions, syntaxType, optionalType, arrayType, output, group, printer } = ctx.options;
|
|
1601
1620
|
const { config, resolver, root } = ctx;
|
|
@@ -1620,7 +1639,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1620
1639
|
group: group ?? void 0,
|
|
1621
1640
|
name: importName
|
|
1622
1641
|
});
|
|
1623
|
-
const enumNode =
|
|
1642
|
+
const enumNode = _kubb_kit.ast.narrowSchema(node, _kubb_kit.ast.schemaTypes.enum);
|
|
1624
1643
|
const isEnumSchema = !!enumNode && !isInlineConstEnum(enumNode, enumSchemaNames);
|
|
1625
1644
|
const meta = {
|
|
1626
1645
|
name: enumOptions.type === "asConst" && isEnumSchema ? resolver.enum.keyName(node, enumOptions.typeSuffix) : resolver.name(node.name),
|
|
@@ -1643,7 +1662,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1643
1662
|
enumSchemaNames,
|
|
1644
1663
|
nodes: printer?.nodes
|
|
1645
1664
|
});
|
|
1646
|
-
return /* @__PURE__ */ (0,
|
|
1665
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1647
1666
|
baseName: meta.file.baseName,
|
|
1648
1667
|
path: meta.file.path,
|
|
1649
1668
|
meta: meta.file.meta,
|
|
@@ -1663,7 +1682,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1663
1682
|
baseName: meta.file.baseName
|
|
1664
1683
|
}
|
|
1665
1684
|
}),
|
|
1666
|
-
children: [imports.map((imp) => /* @__PURE__ */ (0,
|
|
1685
|
+
children: [imports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1667
1686
|
root: meta.file.path,
|
|
1668
1687
|
path: imp.path,
|
|
1669
1688
|
name: imp.name,
|
|
@@ -1672,7 +1691,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1672
1691
|
node.name,
|
|
1673
1692
|
imp.path,
|
|
1674
1693
|
imp.isTypeOnly
|
|
1675
|
-
].join("-"))), /* @__PURE__ */ (0,
|
|
1694
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Type, {
|
|
1676
1695
|
name: meta.name,
|
|
1677
1696
|
node,
|
|
1678
1697
|
enum: enumOptions,
|
|
@@ -1737,7 +1756,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1737
1756
|
enumSchemaNames,
|
|
1738
1757
|
nodes: printer?.nodes
|
|
1739
1758
|
});
|
|
1740
|
-
return /* @__PURE__ */ (0,
|
|
1759
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [imports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1741
1760
|
root: meta.file.path,
|
|
1742
1761
|
path: imp.path,
|
|
1743
1762
|
name: imp.name,
|
|
@@ -1746,7 +1765,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1746
1765
|
name,
|
|
1747
1766
|
imp.path,
|
|
1748
1767
|
imp.isTypeOnly
|
|
1749
|
-
].join("-"))), /* @__PURE__ */ (0,
|
|
1768
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Type, {
|
|
1750
1769
|
name,
|
|
1751
1770
|
node: schema,
|
|
1752
1771
|
enum: enumOptions,
|
|
@@ -1765,15 +1784,15 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1765
1784
|
const variants = resolveContentTypeVariants(entries, baseName);
|
|
1766
1785
|
const keys = variants.map((variant) => inlinePrinter ? `${inlinePrinter.print(variant.schema)}:${variant.keysToOmit ?? ""}` : variant.name);
|
|
1767
1786
|
const members = variants.filter((_, index) => keys.indexOf(keys[index]) === index);
|
|
1768
|
-
const unionSchema =
|
|
1787
|
+
const unionSchema = _kubb_kit.ast.factory.createSchema({
|
|
1769
1788
|
type: "union",
|
|
1770
1789
|
pointer,
|
|
1771
|
-
members: members.map((variant) =>
|
|
1790
|
+
members: members.map((variant) => _kubb_kit.ast.factory.createSchema({
|
|
1772
1791
|
type: "ref",
|
|
1773
1792
|
name: variant.name
|
|
1774
1793
|
}))
|
|
1775
1794
|
});
|
|
1776
|
-
return /* @__PURE__ */ (0,
|
|
1795
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [variants.map((variant) => renderSchemaType({
|
|
1777
1796
|
schema: decorate ? decorate(variant.schema) : variant.schema,
|
|
1778
1797
|
name: variant.name,
|
|
1779
1798
|
keysToOmit: variant.keysToOmit
|
|
@@ -1827,7 +1846,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1827
1846
|
schema: primary?.schema ? {
|
|
1828
1847
|
...primary.schema,
|
|
1829
1848
|
pointer: res.pointer ?? primary.schema.pointer
|
|
1830
|
-
} :
|
|
1849
|
+
} : _kubb_kit.ast.factory.createSchema({ type: "unknown" }),
|
|
1831
1850
|
name: resolver.response.status(node, res.statusCode),
|
|
1832
1851
|
keysToOmit: primary?.keysToOmit
|
|
1833
1852
|
});
|
|
@@ -1844,17 +1863,17 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1844
1863
|
const hasSchema = (res) => (res.content ?? []).some((entry) => entry.schema);
|
|
1845
1864
|
const responseName = resolver.response.response(node);
|
|
1846
1865
|
const responsesWithSchema = node.responses.filter(hasSchema);
|
|
1847
|
-
if (new Set(responsesWithSchema.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ?
|
|
1866
|
+
if (new Set(responsesWithSchema.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ? _kubb_kit.ast.collectImportedRefNames(entry.schema).map(importName) : []))).has(responseName)) return null;
|
|
1848
1867
|
return renderSchemaType({
|
|
1849
1868
|
schema: {
|
|
1850
|
-
...buildResponseUnion(node, { resolver }) ??
|
|
1869
|
+
...buildResponseUnion(node, { resolver }) ?? _kubb_kit.ast.factory.createSchema({ type: "unknown" }),
|
|
1851
1870
|
description: "Union of all possible responses"
|
|
1852
1871
|
},
|
|
1853
1872
|
name: responseName
|
|
1854
1873
|
});
|
|
1855
1874
|
}
|
|
1856
1875
|
const responseType = buildResponseType();
|
|
1857
|
-
return /* @__PURE__ */ (0,
|
|
1876
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1858
1877
|
baseName: meta.file.baseName,
|
|
1859
1878
|
path: meta.file.path,
|
|
1860
1879
|
meta: meta.file.meta,
|
|
@@ -1891,7 +1910,7 @@ var compatibility = {
|
|
|
1891
1910
|
"node": ">=22.22"
|
|
1892
1911
|
};
|
|
1893
1912
|
// package.json
|
|
1894
|
-
var version = "5.4.0
|
|
1913
|
+
var version = "5.4.0";
|
|
1895
1914
|
// src/resolvers/resolverTs.ts
|
|
1896
1915
|
/**
|
|
1897
1916
|
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|
|
@@ -1911,12 +1930,12 @@ var version = "5.4.0-canary.20261029T093900";
|
|
|
1911
1930
|
* resolverTs.response.status(node, 200) // 'ListPetsStatus200'
|
|
1912
1931
|
* ```
|
|
1913
1932
|
*/
|
|
1914
|
-
const resolverTs = (0,
|
|
1933
|
+
const resolverTs = (0, _kubb_kit.createResolver)({
|
|
1915
1934
|
pluginName: "plugin-ts",
|
|
1916
1935
|
name(name) {
|
|
1917
|
-
return this.memo(`name:${name}`, () => ensureValidVarName((0,
|
|
1936
|
+
return this.memo(`name:${name}`, () => ensureValidVarName((0, _kubb_kit.pascalCase)(name)));
|
|
1918
1937
|
},
|
|
1919
|
-
file: createCasedFile(
|
|
1938
|
+
file: createCasedFile(_kubb_kit.pascalCase),
|
|
1920
1939
|
param: createOperationParamResolver(),
|
|
1921
1940
|
response: {
|
|
1922
1941
|
...createOperationResponseResolver(),
|
|
@@ -1962,7 +1981,7 @@ const pluginTsName = "plugin-ts";
|
|
|
1962
1981
|
* })
|
|
1963
1982
|
* ```
|
|
1964
1983
|
*/
|
|
1965
|
-
const pluginTs = (0,
|
|
1984
|
+
const pluginTs = (0, _kubb_kit.defineExtension)({
|
|
1966
1985
|
kind: "plugin",
|
|
1967
1986
|
meta: {
|
|
1968
1987
|
name: pluginTsName,
|
|
@@ -1980,9 +1999,9 @@ const pluginTs = (0, kubb_kit.defineExtension)({
|
|
|
1980
1999
|
typeSuffix: enumOptions.typeSuffix ?? "Key",
|
|
1981
2000
|
keyCasing: enumOptions.keyCasing ?? "none"
|
|
1982
2001
|
};
|
|
1983
|
-
(0,
|
|
1984
|
-
if (userMacros?.length) (0,
|
|
1985
|
-
(0,
|
|
2002
|
+
(0, _kubb_kit.setResolver)(userResolver ? _kubb_kit.Resolver.merge(resolverTs, userResolver) : resolverTs);
|
|
2003
|
+
if (userMacros?.length) (0, _kubb_kit.setMacros)(userMacros);
|
|
2004
|
+
(0, _kubb_kit.addGenerator)(typeGenerator);
|
|
1986
2005
|
return {
|
|
1987
2006
|
output,
|
|
1988
2007
|
exclude,
|