@kubb/plugin-ts 5.4.0-canary.20261029T124214 → 5.4.1
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 +123 -87
- 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 +47 -11
- package/dist/index.js.map +1 -1
- package/docs/guides/customization.md +1 -1
- package/kubb-extension.json +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,
|
|
@@ -883,6 +883,22 @@ function resolveContentTypeVariants(entries, baseName) {
|
|
|
883
883
|
}
|
|
884
884
|
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
885
885
|
/**
|
|
886
|
+
* An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
|
|
887
|
+
* per property, typed and serialized like any other.
|
|
888
|
+
* Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
|
|
889
|
+
*/
|
|
890
|
+
function spreadQuerystring(param) {
|
|
891
|
+
const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
|
|
892
|
+
const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
|
|
893
|
+
if (schema?.type !== "object" || !formEncoded) return [param];
|
|
894
|
+
return schema.properties.map((property) => _kubb_kit.ast.factory.createParameter({
|
|
895
|
+
name: property.name,
|
|
896
|
+
in: "query",
|
|
897
|
+
schema: property.schema,
|
|
898
|
+
required: param.required && property.required
|
|
899
|
+
}));
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
886
902
|
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
887
903
|
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
888
904
|
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
@@ -891,17 +907,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
|
891
907
|
function getOperationParameters(node) {
|
|
892
908
|
const cached = operationParameterGroupsByNode.get(node);
|
|
893
909
|
if (cached) return cached;
|
|
894
|
-
const
|
|
910
|
+
const dedupe = (params) => {
|
|
895
911
|
const seen = /* @__PURE__ */ new Set();
|
|
896
|
-
return
|
|
897
|
-
if (
|
|
912
|
+
return params.filter((param) => {
|
|
913
|
+
if (seen.has(param.name)) return false;
|
|
898
914
|
seen.add(param.name);
|
|
899
915
|
return true;
|
|
900
916
|
});
|
|
901
917
|
};
|
|
918
|
+
const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
|
|
902
919
|
const groups = {
|
|
903
920
|
path: group("path"),
|
|
904
|
-
query: group("query"),
|
|
921
|
+
query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
|
|
905
922
|
header: group("header"),
|
|
906
923
|
cookie: group("cookie")
|
|
907
924
|
};
|
|
@@ -921,7 +938,7 @@ function hasRequestContentTypeChoice(node) {
|
|
|
921
938
|
function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
922
939
|
const { path, query, header } = getOperationParameters(node);
|
|
923
940
|
const hasBody = Boolean(node.requestBody?.content?.[0]?.schema);
|
|
924
|
-
const createNever = () =>
|
|
941
|
+
const createNever = () => _kubb_kit.ast.factory.createSchema({
|
|
925
942
|
type: "never",
|
|
926
943
|
primitive: void 0,
|
|
927
944
|
optional: true
|
|
@@ -943,22 +960,22 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
943
960
|
resolve: resolver.param.headers
|
|
944
961
|
}
|
|
945
962
|
];
|
|
946
|
-
const createOptions = (body, extra = []) =>
|
|
963
|
+
const createOptions = (body, extra = []) => _kubb_kit.ast.factory.createSchema({
|
|
947
964
|
type: "object",
|
|
948
965
|
primitive: "object",
|
|
949
966
|
deprecated: node.deprecated,
|
|
950
967
|
properties: [
|
|
951
|
-
|
|
968
|
+
_kubb_kit.ast.factory.createProperty({
|
|
952
969
|
name: "body",
|
|
953
970
|
required: hasBody,
|
|
954
971
|
schema: body
|
|
955
972
|
}),
|
|
956
973
|
...groups.map(({ name, params, resolve }) => {
|
|
957
974
|
const required = params.some((param) => param.required);
|
|
958
|
-
return
|
|
975
|
+
return _kubb_kit.ast.factory.createProperty({
|
|
959
976
|
name,
|
|
960
977
|
required,
|
|
961
|
-
schema: params.length > 0 ?
|
|
978
|
+
schema: params.length > 0 ? _kubb_kit.ast.factory.createSchema({
|
|
962
979
|
type: "ref",
|
|
963
980
|
name: resolve.call(resolver.param, node, params[0]),
|
|
964
981
|
optional: !required
|
|
@@ -969,25 +986,25 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
969
986
|
]
|
|
970
987
|
});
|
|
971
988
|
const variants = pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : [];
|
|
972
|
-
if (variants.length < 2) return createOptions(hasBody ?
|
|
989
|
+
if (variants.length < 2) return createOptions(hasBody ? _kubb_kit.ast.factory.createSchema({
|
|
973
990
|
type: "ref",
|
|
974
991
|
name: resolver.response.body(node)
|
|
975
992
|
}) : createNever());
|
|
976
|
-
return
|
|
993
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
977
994
|
type: "union",
|
|
978
|
-
members: variants.map((variant, index) => createOptions(
|
|
995
|
+
members: variants.map((variant, index) => createOptions(_kubb_kit.ast.factory.createSchema({
|
|
979
996
|
type: "ref",
|
|
980
997
|
name: variant.name
|
|
981
|
-
}), [
|
|
998
|
+
}), [_kubb_kit.ast.factory.createProperty({
|
|
982
999
|
name: "contentType",
|
|
983
1000
|
required: index > 0,
|
|
984
|
-
schema:
|
|
1001
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
985
1002
|
type: "object",
|
|
986
1003
|
primitive: "object",
|
|
987
|
-
properties: [
|
|
1004
|
+
properties: [_kubb_kit.ast.factory.createProperty({
|
|
988
1005
|
name: "request",
|
|
989
1006
|
required: true,
|
|
990
|
-
schema:
|
|
1007
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
991
1008
|
type: "enum",
|
|
992
1009
|
enumValues: [variant.contentType]
|
|
993
1010
|
})
|
|
@@ -1005,26 +1022,26 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
1005
1022
|
function buildResponseRecordEntry(node, res, resolver) {
|
|
1006
1023
|
const statusName = resolver.response.status(node, res.statusCode);
|
|
1007
1024
|
const variants = (res.content ?? []).filter((entry) => entry.schema);
|
|
1008
|
-
if (variants.length <= 1) return
|
|
1025
|
+
if (variants.length <= 1) return _kubb_kit.ast.factory.createSchema({
|
|
1009
1026
|
type: "ref",
|
|
1010
1027
|
name: statusName
|
|
1011
1028
|
});
|
|
1012
|
-
return
|
|
1029
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
1013
1030
|
type: "union",
|
|
1014
|
-
members: resolveContentTypeVariants(variants, statusName).map((variant) =>
|
|
1031
|
+
members: resolveContentTypeVariants(variants, statusName).map((variant) => _kubb_kit.ast.factory.createSchema({
|
|
1015
1032
|
type: "object",
|
|
1016
1033
|
primitive: "object",
|
|
1017
|
-
properties: [
|
|
1034
|
+
properties: [_kubb_kit.ast.factory.createProperty({
|
|
1018
1035
|
name: "contentType",
|
|
1019
1036
|
required: true,
|
|
1020
|
-
schema:
|
|
1037
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
1021
1038
|
type: "enum",
|
|
1022
1039
|
enumValues: [variant.contentType]
|
|
1023
1040
|
})
|
|
1024
|
-
}),
|
|
1041
|
+
}), _kubb_kit.ast.factory.createProperty({
|
|
1025
1042
|
name: "data",
|
|
1026
1043
|
required: true,
|
|
1027
|
-
schema:
|
|
1044
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
1028
1045
|
type: "ref",
|
|
1029
1046
|
name: variant.name
|
|
1030
1047
|
})
|
|
@@ -1042,10 +1059,10 @@ function buildResponseRecordEntry(node, res, resolver) {
|
|
|
1042
1059
|
* SDK's `RequestResult<XResponses>`) resolvable instead of pointing at a missing export.
|
|
1043
1060
|
*/
|
|
1044
1061
|
function buildResponses(node, resolver) {
|
|
1045
|
-
return
|
|
1062
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
1046
1063
|
type: "object",
|
|
1047
1064
|
primitive: "object",
|
|
1048
|
-
properties: node.responses.map((res) =>
|
|
1065
|
+
properties: node.responses.map((res) => _kubb_kit.ast.factory.createProperty({
|
|
1049
1066
|
name: String(res.statusCode),
|
|
1050
1067
|
required: true,
|
|
1051
1068
|
schema: buildResponseRecordEntry(node, res, resolver)
|
|
@@ -1205,7 +1222,7 @@ function createGroupConfig(group) {
|
|
|
1205
1222
|
if (!group) return null;
|
|
1206
1223
|
const defaultName = (ctx) => {
|
|
1207
1224
|
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
1208
|
-
return (0,
|
|
1225
|
+
return (0, _kubb_kit.camelCase)(ctx.group);
|
|
1209
1226
|
};
|
|
1210
1227
|
return {
|
|
1211
1228
|
...group,
|
|
@@ -1245,7 +1262,7 @@ function mapSchemaItems(node, transform) {
|
|
|
1245
1262
|
* Renames inline enum declarations and their uses together.
|
|
1246
1263
|
*/
|
|
1247
1264
|
function resolveInlineEnumNames({ node, owner, resolver, enumOptions }) {
|
|
1248
|
-
return
|
|
1265
|
+
return _kubb_kit.ast.transform(node, { schema(child) {
|
|
1249
1266
|
if (child === node || child.type !== "enum" || !child.name) return;
|
|
1250
1267
|
const name = resolver.resolveName({
|
|
1251
1268
|
key: [
|
|
@@ -1302,7 +1319,7 @@ function formatExample(value) {
|
|
|
1302
1319
|
return (JSON.stringify(value) ?? String(value)).replaceAll("*/", "*\\/");
|
|
1303
1320
|
}
|
|
1304
1321
|
function buildPropertyJSDocComments(schema, optional) {
|
|
1305
|
-
const meta = (0,
|
|
1322
|
+
const meta = (0, _kubb_kit.syncSchemaRef)(schema);
|
|
1306
1323
|
const isArray = meta?.primitive === "array";
|
|
1307
1324
|
const isNumeric = meta?.primitive === "number" || meta?.primitive === "integer" || meta?.primitive === "bigint";
|
|
1308
1325
|
const hasDescription = meta && "description" in meta && meta.description;
|
|
@@ -1327,13 +1344,13 @@ function buildPropertyJSDocComments(schema, optional) {
|
|
|
1327
1344
|
* separate per-param type — the group itself is the only type these params get exported as.
|
|
1328
1345
|
*/
|
|
1329
1346
|
function buildParams({ params }) {
|
|
1330
|
-
return
|
|
1347
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
1331
1348
|
type: "object",
|
|
1332
1349
|
pointer: params[0]?.pointer?.replace(/\/\d+$/, ""),
|
|
1333
|
-
properties: params.map((param) =>
|
|
1350
|
+
properties: params.map((param) => _kubb_kit.ast.factory.createProperty({
|
|
1334
1351
|
name: param.name,
|
|
1335
1352
|
required: param.required,
|
|
1336
|
-
schema:
|
|
1353
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
1337
1354
|
...param.schema,
|
|
1338
1355
|
optional: !param.required
|
|
1339
1356
|
})
|
|
@@ -1345,9 +1362,9 @@ function buildResponseUnion(node, { resolver }) {
|
|
|
1345
1362
|
const successWithSchema = allWithSchema.filter((res) => isSuccessStatusCode(res.statusCode));
|
|
1346
1363
|
const responsesWithSchema = successWithSchema.length > 0 ? successWithSchema : allWithSchema;
|
|
1347
1364
|
if (responsesWithSchema.length === 0) return null;
|
|
1348
|
-
return
|
|
1365
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
1349
1366
|
type: "union",
|
|
1350
|
-
members: responsesWithSchema.map((res) =>
|
|
1367
|
+
members: responsesWithSchema.map((res) => _kubb_kit.ast.factory.createSchema({
|
|
1351
1368
|
type: "ref",
|
|
1352
1369
|
name: resolver.response.status(node, res.statusCode)
|
|
1353
1370
|
}))
|
|
@@ -1355,6 +1372,25 @@ function buildResponseUnion(node, { resolver }) {
|
|
|
1355
1372
|
}
|
|
1356
1373
|
// src/printers/printerTs.ts
|
|
1357
1374
|
const { isNonNullable } = factory_exports;
|
|
1375
|
+
const requireModule = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
1376
|
+
/**
|
|
1377
|
+
* Loads `@kubb/parser-ts` on first use. It is an optional peer dependency: only a deprecated `printer.nodes`
|
|
1378
|
+
* handler that returns a TypeScript compiler node needs it. Loads synchronously because node handlers are synchronous.
|
|
1379
|
+
*/
|
|
1380
|
+
function loadParserTs(load = () => requireModule("@kubb/parser-ts")) {
|
|
1381
|
+
try {
|
|
1382
|
+
return load();
|
|
1383
|
+
} catch (error) {
|
|
1384
|
+
if (error.code !== "MODULE_NOT_FOUND" || !error.message.split("\n")[0].includes("@kubb/parser-ts")) throw error;
|
|
1385
|
+
throw new _kubb_kit.Diagnostics.Error({
|
|
1386
|
+
code: _kubb_kit.Diagnostics.code.missingDependency,
|
|
1387
|
+
severity: "error",
|
|
1388
|
+
message: "Missing dependency: @kubb/parser-ts. A `printer.nodes` handler returned a TypeScript compiler node, and printing it needs @kubb/parser-ts.",
|
|
1389
|
+
help: "Run `npm i -D @kubb/parser-ts` in the project, or return a string from the handler.",
|
|
1390
|
+
plugin: "plugin-ts"
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1358
1394
|
/**
|
|
1359
1395
|
* Adapts user overrides, which work in strings, to the node-based printer: `this.transform` hands them printed
|
|
1360
1396
|
* strings and their result is wrapped back into a node. A deprecated compiler node prints through `@kubb/parser-ts`.
|
|
@@ -1370,7 +1406,7 @@ function toNodeHandlers(nodes) {
|
|
|
1370
1406
|
transform
|
|
1371
1407
|
}, node);
|
|
1372
1408
|
if (result === null || result === void 0) return result;
|
|
1373
|
-
return createRaw(typeof result === "string" ? result : (
|
|
1409
|
+
return createRaw(typeof result === "string" ? result : loadParserTs().parserTs().print(result).trimEnd());
|
|
1374
1410
|
}]));
|
|
1375
1411
|
}
|
|
1376
1412
|
/**
|
|
@@ -1396,7 +1432,7 @@ function toNodeHandlers(nodes) {
|
|
|
1396
1432
|
* const declaration = printer.print(schemaNode) // 'export type MyType = …'
|
|
1397
1433
|
* ```
|
|
1398
1434
|
*/
|
|
1399
|
-
const printerTs =
|
|
1435
|
+
const printerTs = _kubb_kit.ast.createPrinter((options) => {
|
|
1400
1436
|
const addsUndefined = options.optionalType === "undefined" || options.optionalType === "questionTokenAndUndefined";
|
|
1401
1437
|
return {
|
|
1402
1438
|
name: "typescript",
|
|
@@ -1426,7 +1462,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1426
1462
|
time: dateOrStringNode,
|
|
1427
1463
|
ref(node) {
|
|
1428
1464
|
if (!node.name) return null;
|
|
1429
|
-
const refName =
|
|
1465
|
+
const refName = _kubb_kit.ast.resolveRefName(node);
|
|
1430
1466
|
if (!refName) return null;
|
|
1431
1467
|
return createTypeReferenceNode(node.ref ? enumTypeName({
|
|
1432
1468
|
resolver: this.options.resolver,
|
|
@@ -1436,7 +1472,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1436
1472
|
}) : refName);
|
|
1437
1473
|
},
|
|
1438
1474
|
enum(node) {
|
|
1439
|
-
const values =
|
|
1475
|
+
const values = _kubb_kit.ast.getSchemaLiteralValues(node);
|
|
1440
1476
|
if (values.some((value) => value !== null && typeof value === "object")) return createUnionDeclaration({ nodes: values.map((value) => constToTypeNode(value)) });
|
|
1441
1477
|
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
1478
|
return createTypeReferenceNode(enumTypeName({
|
|
@@ -1449,11 +1485,11 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1449
1485
|
union(node) {
|
|
1450
1486
|
const members = node.members ?? [];
|
|
1451
1487
|
const hasStringLiteral = members.some((m) => {
|
|
1452
|
-
return
|
|
1488
|
+
return _kubb_kit.ast.narrowSchema(m, _kubb_kit.ast.schemaTypes.enum)?.primitive === "string";
|
|
1453
1489
|
});
|
|
1454
|
-
const hasPlainString = members.some((m) => (0,
|
|
1490
|
+
const hasPlainString = members.some((m) => (0, _kubb_kit.isStringType)(m));
|
|
1455
1491
|
if (hasStringLiteral && hasPlainString) return createUnionDeclaration({ nodes: members.map((m) => {
|
|
1456
|
-
if ((0,
|
|
1492
|
+
if ((0, _kubb_kit.isStringType)(m)) return createIntersectionDeclaration({ nodes: [keywordTypeNodes.string, createTypeLiteralNode([])] });
|
|
1457
1493
|
return this.transform(m);
|
|
1458
1494
|
}).filter(isNonNullable) });
|
|
1459
1495
|
return createUnionDeclaration({ nodes: buildMemberNodes(members, this.transform) });
|
|
@@ -1472,10 +1508,10 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1472
1508
|
},
|
|
1473
1509
|
object(node) {
|
|
1474
1510
|
const { transform, options } = this;
|
|
1475
|
-
const keySchema = node.propertyNames && (0,
|
|
1511
|
+
const keySchema = node.propertyNames && (0, _kubb_kit.syncSchemaRef)(node.propertyNames);
|
|
1476
1512
|
if (!node.properties.length && !Object.keys(node.patternProperties ?? {}).length && node.propertyNames && keySchema?.type === "enum" && node.additionalProperties !== false) {
|
|
1477
1513
|
const keyType = transform(node.propertyNames) ?? keywordTypeNodes.string;
|
|
1478
|
-
const valueSchema = typeof node.additionalProperties === "object" ? node.additionalProperties :
|
|
1514
|
+
const valueSchema = typeof node.additionalProperties === "object" ? node.additionalProperties : _kubb_kit.ast.factory.createSchema({ type: "unknown" });
|
|
1479
1515
|
return createTypeReferenceNode("Partial", [createTypeReferenceNode("Record", [keyType, buildPropertyType(valueSchema, transform(valueSchema) ?? keywordTypeNodes.unknown, options.optionalType, false)])]);
|
|
1480
1516
|
}
|
|
1481
1517
|
const addsQuestionToken = options.optionalType === "questionToken" || options.optionalType === "questionTokenAndUndefined";
|
|
@@ -1483,7 +1519,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1483
1519
|
const baseType = output ?? keywordTypeNodes.unknown;
|
|
1484
1520
|
const optional = !property.required || !!property.schema.optional || !!property.schema.nullish;
|
|
1485
1521
|
const type = buildPropertyType(property.schema, baseType, options.optionalType, optional);
|
|
1486
|
-
const propMeta = (0,
|
|
1522
|
+
const propMeta = (0, _kubb_kit.syncSchemaRef)(property.schema);
|
|
1487
1523
|
return appendJSDocToNode({
|
|
1488
1524
|
node: createPropertySignature({
|
|
1489
1525
|
questionToken: optional ? addsQuestionToken : false,
|
|
@@ -1504,7 +1540,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1504
1540
|
const { name, syntaxType = "type", description, keysToOmit } = this.options;
|
|
1505
1541
|
const transformed = this.transform(node);
|
|
1506
1542
|
if (!transformed) return null;
|
|
1507
|
-
const meta = (0,
|
|
1543
|
+
const meta = (0, _kubb_kit.syncSchemaRef)(node);
|
|
1508
1544
|
if (!name) return print(wrapNullableOptional(keysToOmit?.length ? createOmitDeclaration({
|
|
1509
1545
|
keys: keysToOmit,
|
|
1510
1546
|
type: transformed,
|
|
@@ -1532,7 +1568,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1532
1568
|
// src/components/Type.tsx
|
|
1533
1569
|
function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
1534
1570
|
if (inline) {
|
|
1535
|
-
const withoutEnums =
|
|
1571
|
+
const withoutEnums = _kubb_kit.ast.transform(node, { schema: (n) => n.type === _kubb_kit.ast.schemaTypes.enum && n.name ? {
|
|
1536
1572
|
...n,
|
|
1537
1573
|
name: void 0
|
|
1538
1574
|
} : void 0 });
|
|
@@ -1541,7 +1577,7 @@ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
|
1541
1577
|
name: void 0
|
|
1542
1578
|
}).print(withoutEnums)?.replace(/\/\*\*[\s\S]*?\*\/\s*/g, "");
|
|
1543
1579
|
if (!expression) return;
|
|
1544
|
-
return /* @__PURE__ */ (0,
|
|
1580
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1545
1581
|
name,
|
|
1546
1582
|
isTypeOnly: true,
|
|
1547
1583
|
isExportable: true,
|
|
@@ -1550,8 +1586,8 @@ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
|
1550
1586
|
children: expression
|
|
1551
1587
|
});
|
|
1552
1588
|
}
|
|
1553
|
-
const enumSchemaNodes =
|
|
1554
|
-
const enumNode =
|
|
1589
|
+
const enumSchemaNodes = _kubb_kit.ast.collectSync(node, { schema(n) {
|
|
1590
|
+
const enumNode = _kubb_kit.ast.narrowSchema(n, _kubb_kit.ast.schemaTypes.enum);
|
|
1555
1591
|
if (enumNode?.name && !isInlineConstEnum(enumNode, printer.options.enumSchemaNames)) return enumNode;
|
|
1556
1592
|
} });
|
|
1557
1593
|
const output = printer.print(node);
|
|
@@ -1569,15 +1605,15 @@ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
|
1569
1605
|
});
|
|
1570
1606
|
const shouldExportEnums = enumOptions.type !== "inlineLiteral";
|
|
1571
1607
|
const shouldExportType = enumOptions.type === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
1572
|
-
return /* @__PURE__ */ (0,
|
|
1608
|
+
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
1609
|
node,
|
|
1574
1610
|
enum: enumOptions,
|
|
1575
1611
|
resolver
|
|
1576
|
-
}, node.name)), shouldExportType && /* @__PURE__ */ (0,
|
|
1612
|
+
}, 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
1613
|
name,
|
|
1578
1614
|
imp.path,
|
|
1579
1615
|
imp.name
|
|
1580
|
-
].join("-"))), /* @__PURE__ */ (0,
|
|
1616
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1581
1617
|
name,
|
|
1582
1618
|
pointer: node.pointer,
|
|
1583
1619
|
isTypeOnly: true,
|
|
@@ -1593,9 +1629,9 @@ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
|
|
|
1593
1629
|
* types. Drop-replace with a custom `Generator<PluginTs>` to change how
|
|
1594
1630
|
* TypeScript output is produced.
|
|
1595
1631
|
*/
|
|
1596
|
-
const typeGenerator = (0,
|
|
1632
|
+
const typeGenerator = (0, _kubb_kit.defineGenerator)({
|
|
1597
1633
|
name: "typescript",
|
|
1598
|
-
renderer:
|
|
1634
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1599
1635
|
schema(node, ctx) {
|
|
1600
1636
|
const { enum: enumOptions, syntaxType, optionalType, arrayType, output, group, printer } = ctx.options;
|
|
1601
1637
|
const { config, resolver, root } = ctx;
|
|
@@ -1620,7 +1656,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1620
1656
|
group: group ?? void 0,
|
|
1621
1657
|
name: importName
|
|
1622
1658
|
});
|
|
1623
|
-
const enumNode =
|
|
1659
|
+
const enumNode = _kubb_kit.ast.narrowSchema(node, _kubb_kit.ast.schemaTypes.enum);
|
|
1624
1660
|
const isEnumSchema = !!enumNode && !isInlineConstEnum(enumNode, enumSchemaNames);
|
|
1625
1661
|
const meta = {
|
|
1626
1662
|
name: enumOptions.type === "asConst" && isEnumSchema ? resolver.enum.keyName(node, enumOptions.typeSuffix) : resolver.name(node.name),
|
|
@@ -1643,7 +1679,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1643
1679
|
enumSchemaNames,
|
|
1644
1680
|
nodes: printer?.nodes
|
|
1645
1681
|
});
|
|
1646
|
-
return /* @__PURE__ */ (0,
|
|
1682
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1647
1683
|
baseName: meta.file.baseName,
|
|
1648
1684
|
path: meta.file.path,
|
|
1649
1685
|
meta: meta.file.meta,
|
|
@@ -1663,7 +1699,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1663
1699
|
baseName: meta.file.baseName
|
|
1664
1700
|
}
|
|
1665
1701
|
}),
|
|
1666
|
-
children: [imports.map((imp) => /* @__PURE__ */ (0,
|
|
1702
|
+
children: [imports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1667
1703
|
root: meta.file.path,
|
|
1668
1704
|
path: imp.path,
|
|
1669
1705
|
name: imp.name,
|
|
@@ -1672,7 +1708,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1672
1708
|
node.name,
|
|
1673
1709
|
imp.path,
|
|
1674
1710
|
imp.isTypeOnly
|
|
1675
|
-
].join("-"))), /* @__PURE__ */ (0,
|
|
1711
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Type, {
|
|
1676
1712
|
name: meta.name,
|
|
1677
1713
|
node,
|
|
1678
1714
|
enum: enumOptions,
|
|
@@ -1737,7 +1773,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1737
1773
|
enumSchemaNames,
|
|
1738
1774
|
nodes: printer?.nodes
|
|
1739
1775
|
});
|
|
1740
|
-
return /* @__PURE__ */ (0,
|
|
1776
|
+
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
1777
|
root: meta.file.path,
|
|
1742
1778
|
path: imp.path,
|
|
1743
1779
|
name: imp.name,
|
|
@@ -1746,7 +1782,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1746
1782
|
name,
|
|
1747
1783
|
imp.path,
|
|
1748
1784
|
imp.isTypeOnly
|
|
1749
|
-
].join("-"))), /* @__PURE__ */ (0,
|
|
1785
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Type, {
|
|
1750
1786
|
name,
|
|
1751
1787
|
node: schema,
|
|
1752
1788
|
enum: enumOptions,
|
|
@@ -1765,15 +1801,15 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1765
1801
|
const variants = resolveContentTypeVariants(entries, baseName);
|
|
1766
1802
|
const keys = variants.map((variant) => inlinePrinter ? `${inlinePrinter.print(variant.schema)}:${variant.keysToOmit ?? ""}` : variant.name);
|
|
1767
1803
|
const members = variants.filter((_, index) => keys.indexOf(keys[index]) === index);
|
|
1768
|
-
const unionSchema =
|
|
1804
|
+
const unionSchema = _kubb_kit.ast.factory.createSchema({
|
|
1769
1805
|
type: "union",
|
|
1770
1806
|
pointer,
|
|
1771
|
-
members: members.map((variant) =>
|
|
1807
|
+
members: members.map((variant) => _kubb_kit.ast.factory.createSchema({
|
|
1772
1808
|
type: "ref",
|
|
1773
1809
|
name: variant.name
|
|
1774
1810
|
}))
|
|
1775
1811
|
});
|
|
1776
|
-
return /* @__PURE__ */ (0,
|
|
1812
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [variants.map((variant) => renderSchemaType({
|
|
1777
1813
|
schema: decorate ? decorate(variant.schema) : variant.schema,
|
|
1778
1814
|
name: variant.name,
|
|
1779
1815
|
keysToOmit: variant.keysToOmit
|
|
@@ -1827,7 +1863,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1827
1863
|
schema: primary?.schema ? {
|
|
1828
1864
|
...primary.schema,
|
|
1829
1865
|
pointer: res.pointer ?? primary.schema.pointer
|
|
1830
|
-
} :
|
|
1866
|
+
} : _kubb_kit.ast.factory.createSchema({ type: "unknown" }),
|
|
1831
1867
|
name: resolver.response.status(node, res.statusCode),
|
|
1832
1868
|
keysToOmit: primary?.keysToOmit
|
|
1833
1869
|
});
|
|
@@ -1844,17 +1880,17 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1844
1880
|
const hasSchema = (res) => (res.content ?? []).some((entry) => entry.schema);
|
|
1845
1881
|
const responseName = resolver.response.response(node);
|
|
1846
1882
|
const responsesWithSchema = node.responses.filter(hasSchema);
|
|
1847
|
-
if (new Set(responsesWithSchema.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ?
|
|
1883
|
+
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
1884
|
return renderSchemaType({
|
|
1849
1885
|
schema: {
|
|
1850
|
-
...buildResponseUnion(node, { resolver }) ??
|
|
1886
|
+
...buildResponseUnion(node, { resolver }) ?? _kubb_kit.ast.factory.createSchema({ type: "unknown" }),
|
|
1851
1887
|
description: "Union of all possible responses"
|
|
1852
1888
|
},
|
|
1853
1889
|
name: responseName
|
|
1854
1890
|
});
|
|
1855
1891
|
}
|
|
1856
1892
|
const responseType = buildResponseType();
|
|
1857
|
-
return /* @__PURE__ */ (0,
|
|
1893
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1858
1894
|
baseName: meta.file.baseName,
|
|
1859
1895
|
path: meta.file.path,
|
|
1860
1896
|
meta: meta.file.meta,
|
|
@@ -1887,11 +1923,11 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1887
1923
|
});
|
|
1888
1924
|
// kubb-extension.json
|
|
1889
1925
|
var compatibility = {
|
|
1890
|
-
"kubb": ">=5.
|
|
1926
|
+
"kubb": ">=5.16.0",
|
|
1891
1927
|
"node": ">=22.22"
|
|
1892
1928
|
};
|
|
1893
1929
|
// package.json
|
|
1894
|
-
var version = "5.4.
|
|
1930
|
+
var version = "5.4.1";
|
|
1895
1931
|
// src/resolvers/resolverTs.ts
|
|
1896
1932
|
/**
|
|
1897
1933
|
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|
|
@@ -1911,12 +1947,12 @@ var version = "5.4.0-canary.20261029T124214";
|
|
|
1911
1947
|
* resolverTs.response.status(node, 200) // 'ListPetsStatus200'
|
|
1912
1948
|
* ```
|
|
1913
1949
|
*/
|
|
1914
|
-
const resolverTs = (0,
|
|
1950
|
+
const resolverTs = (0, _kubb_kit.createResolver)({
|
|
1915
1951
|
pluginName: "plugin-ts",
|
|
1916
1952
|
name(name) {
|
|
1917
|
-
return this.memo(`name:${name}`, () => ensureValidVarName((0,
|
|
1953
|
+
return this.memo(`name:${name}`, () => ensureValidVarName((0, _kubb_kit.pascalCase)(name)));
|
|
1918
1954
|
},
|
|
1919
|
-
file: createCasedFile(
|
|
1955
|
+
file: createCasedFile(_kubb_kit.pascalCase),
|
|
1920
1956
|
param: createOperationParamResolver(),
|
|
1921
1957
|
response: {
|
|
1922
1958
|
...createOperationResponseResolver(),
|
|
@@ -1962,7 +1998,7 @@ const pluginTsName = "plugin-ts";
|
|
|
1962
1998
|
* })
|
|
1963
1999
|
* ```
|
|
1964
2000
|
*/
|
|
1965
|
-
const pluginTs = (0,
|
|
2001
|
+
const pluginTs = (0, _kubb_kit.defineExtension)({
|
|
1966
2002
|
kind: "plugin",
|
|
1967
2003
|
meta: {
|
|
1968
2004
|
name: pluginTsName,
|
|
@@ -1980,9 +2016,9 @@ const pluginTs = (0, kubb_kit.defineExtension)({
|
|
|
1980
2016
|
typeSuffix: enumOptions.typeSuffix ?? "Key",
|
|
1981
2017
|
keyCasing: enumOptions.keyCasing ?? "none"
|
|
1982
2018
|
};
|
|
1983
|
-
(0,
|
|
1984
|
-
if (userMacros?.length) (0,
|
|
1985
|
-
(0,
|
|
2019
|
+
(0, _kubb_kit.setResolver)(userResolver ? _kubb_kit.Resolver.merge(resolverTs, userResolver) : resolverTs);
|
|
2020
|
+
if (userMacros?.length) (0, _kubb_kit.setMacros)(userMacros);
|
|
2021
|
+
(0, _kubb_kit.addGenerator)(typeGenerator);
|
|
1986
2022
|
return {
|
|
1987
2023
|
output,
|
|
1988
2024
|
exclude,
|