@kubb/plugin-ts 5.0.0-alpha.3 → 5.0.0-alpha.30

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.
Files changed (42) hide show
  1. package/dist/index.cjs +1806 -3
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +590 -4
  4. package/dist/index.js +1776 -2
  5. package/dist/index.js.map +1 -0
  6. package/package.json +7 -27
  7. package/src/components/Enum.tsx +82 -0
  8. package/src/components/Type.tsx +29 -162
  9. package/src/constants.ts +39 -0
  10. package/src/factory.ts +134 -49
  11. package/src/generators/typeGenerator.tsx +165 -428
  12. package/src/generators/typeGeneratorLegacy.tsx +349 -0
  13. package/src/index.ts +9 -1
  14. package/src/plugin.ts +98 -176
  15. package/src/presets.ts +28 -0
  16. package/src/printers/functionPrinter.ts +196 -0
  17. package/src/printers/printerTs.ts +310 -0
  18. package/src/resolvers/resolverTs.ts +66 -0
  19. package/src/resolvers/resolverTsLegacy.ts +60 -0
  20. package/src/types.ts +258 -98
  21. package/src/utils.ts +131 -0
  22. package/dist/components-CRjwjdyE.js +0 -725
  23. package/dist/components-CRjwjdyE.js.map +0 -1
  24. package/dist/components-DI0aTIBg.cjs +0 -978
  25. package/dist/components-DI0aTIBg.cjs.map +0 -1
  26. package/dist/components.cjs +0 -3
  27. package/dist/components.d.ts +0 -38
  28. package/dist/components.js +0 -2
  29. package/dist/generators.cjs +0 -4
  30. package/dist/generators.d.ts +0 -503
  31. package/dist/generators.js +0 -2
  32. package/dist/plugin-D5rCK1zO.cjs +0 -992
  33. package/dist/plugin-D5rCK1zO.cjs.map +0 -1
  34. package/dist/plugin-DmwgRHK8.js +0 -944
  35. package/dist/plugin-DmwgRHK8.js.map +0 -1
  36. package/dist/types-BpeKGgCn.d.ts +0 -170
  37. package/src/components/index.ts +0 -1
  38. package/src/components/v2/Type.tsx +0 -165
  39. package/src/generators/index.ts +0 -2
  40. package/src/generators/v2/typeGenerator.tsx +0 -196
  41. package/src/parser.ts +0 -396
  42. package/src/printer.ts +0 -244
package/dist/index.cjs CHANGED
@@ -1,4 +1,1807 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_plugin = require("./plugin-D5rCK1zO.cjs");
3
- exports.pluginTs = require_plugin.pluginTs;
4
- exports.pluginTsName = require_plugin.pluginTsName;
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let _kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
25
+ let _kubb_react_fabric = require("@kubb/react-fabric");
26
+ let _kubb_ast = require("@kubb/ast");
27
+ let remeda = require("remeda");
28
+ let typescript = require("typescript");
29
+ typescript = __toESM(typescript);
30
+ let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
31
+ let _kubb_core = require("@kubb/core");
32
+ //#region ../../internals/utils/src/casing.ts
33
+ /**
34
+ * Shared implementation for camelCase and PascalCase conversion.
35
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
36
+ * and capitalizes each word according to `pascal`.
37
+ *
38
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
39
+ */
40
+ function toCamelOrPascal(text, pascal) {
41
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
42
+ if (word.length > 1 && word === word.toUpperCase()) return word;
43
+ if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
44
+ return word.charAt(0).toUpperCase() + word.slice(1);
45
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
46
+ }
47
+ /**
48
+ * Splits `text` on `.` and applies `transformPart` to each segment.
49
+ * The last segment receives `isLast = true`, all earlier segments receive `false`.
50
+ * Segments are joined with `/` to form a file path.
51
+ *
52
+ * Only splits on dots followed by a letter so that version numbers
53
+ * embedded in operationIds (e.g. `v2025.0`) are kept intact.
54
+ */
55
+ function applyToFileParts(text, transformPart) {
56
+ const parts = text.split(/\.(?=[a-zA-Z])/);
57
+ return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
58
+ }
59
+ /**
60
+ * Converts `text` to camelCase.
61
+ * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
62
+ *
63
+ * @example
64
+ * camelCase('hello-world') // 'helloWorld'
65
+ * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
66
+ */
67
+ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
68
+ if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
69
+ prefix,
70
+ suffix
71
+ } : {}));
72
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
73
+ }
74
+ /**
75
+ * Converts `text` to PascalCase.
76
+ * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
77
+ *
78
+ * @example
79
+ * pascalCase('hello-world') // 'HelloWorld'
80
+ * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
81
+ */
82
+ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
83
+ if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
84
+ prefix,
85
+ suffix
86
+ }) : camelCase(part));
87
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
88
+ }
89
+ /**
90
+ * Converts `text` to snake_case.
91
+ *
92
+ * @example
93
+ * snakeCase('helloWorld') // 'hello_world'
94
+ * snakeCase('Hello-World') // 'hello_world'
95
+ */
96
+ function snakeCase(text, { prefix = "", suffix = "" } = {}) {
97
+ return `${prefix} ${text} ${suffix}`.trim().replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s\-.]+/g, "_").replace(/[^a-zA-Z0-9_]/g, "").toLowerCase().split("_").filter(Boolean).join("_");
98
+ }
99
+ /**
100
+ * Converts `text` to SCREAMING_SNAKE_CASE.
101
+ *
102
+ * @example
103
+ * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'
104
+ */
105
+ function screamingSnakeCase(text, { prefix = "", suffix = "" } = {}) {
106
+ return snakeCase(text, {
107
+ prefix,
108
+ suffix
109
+ }).toUpperCase();
110
+ }
111
+ //#endregion
112
+ //#region ../../internals/utils/src/string.ts
113
+ /**
114
+ * Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
115
+ * Returns the string unchanged when no balanced quote pair is found.
116
+ *
117
+ * @example
118
+ * trimQuotes('"hello"') // 'hello'
119
+ * trimQuotes('hello') // 'hello'
120
+ */
121
+ function trimQuotes(text) {
122
+ if (text.length >= 2) {
123
+ const first = text[0];
124
+ const last = text[text.length - 1];
125
+ if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
126
+ }
127
+ return text;
128
+ }
129
+ /**
130
+ * Escapes characters that are not allowed inside JS string literals.
131
+ * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).
132
+ *
133
+ * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
138
+ * ```
139
+ */
140
+ function jsStringEscape(input) {
141
+ return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
142
+ switch (character) {
143
+ case "\"":
144
+ case "'":
145
+ case "\\": return `\\${character}`;
146
+ case "\n": return "\\n";
147
+ case "\r": return "\\r";
148
+ case "\u2028": return "\\u2028";
149
+ case "\u2029": return "\\u2029";
150
+ default: return "";
151
+ }
152
+ });
153
+ }
154
+ //#endregion
155
+ //#region ../../internals/utils/src/object.ts
156
+ /**
157
+ * Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first.
158
+ *
159
+ * @example
160
+ * stringify('hello') // '"hello"'
161
+ * stringify('"hello"') // '"hello"'
162
+ */
163
+ function stringify(value) {
164
+ if (value === void 0 || value === null) return "\"\"";
165
+ return JSON.stringify(trimQuotes(value.toString()));
166
+ }
167
+ //#endregion
168
+ //#region src/constants.ts
169
+ /**
170
+ * `optionalType` values that cause a property's type to include `| undefined`.
171
+ */
172
+ const OPTIONAL_ADDS_UNDEFINED = new Set(["undefined", "questionTokenAndUndefined"]);
173
+ /**
174
+ * `optionalType` values that render the property key with a `?` token.
175
+ */
176
+ const OPTIONAL_ADDS_QUESTION_TOKEN = new Set(["questionToken", "questionTokenAndUndefined"]);
177
+ /**
178
+ * `enumType` values that append a `Key` suffix to the generated enum type alias.
179
+ */
180
+ const ENUM_TYPES_WITH_KEY_SUFFIX = new Set(["asConst", "asPascalConst"]);
181
+ /**
182
+ * `enumType` values that require a runtime value declaration (object, enum, or literal).
183
+ */
184
+ const ENUM_TYPES_WITH_RUNTIME_VALUE = new Set([
185
+ "enum",
186
+ "asConst",
187
+ "asPascalConst",
188
+ "constEnum",
189
+ "literal",
190
+ void 0
191
+ ]);
192
+ /**
193
+ * `enumType` values whose type declaration is type-only (no runtime value emitted for the type alias).
194
+ */
195
+ const ENUM_TYPES_WITH_TYPE_ONLY = new Set([
196
+ "asConst",
197
+ "asPascalConst",
198
+ "literal",
199
+ void 0
200
+ ]);
201
+ /**
202
+ * Ordering priority for function parameters: lower = sorted earlier.
203
+ */
204
+ const PARAM_RANK = {
205
+ required: 0,
206
+ optional: 1,
207
+ withDefault: 2,
208
+ rest: 3
209
+ };
210
+ //#endregion
211
+ //#region src/factory.ts
212
+ const { SyntaxKind, factory } = typescript.default;
213
+ const modifiers = {
214
+ async: factory.createModifier(typescript.default.SyntaxKind.AsyncKeyword),
215
+ export: factory.createModifier(typescript.default.SyntaxKind.ExportKeyword),
216
+ const: factory.createModifier(typescript.default.SyntaxKind.ConstKeyword),
217
+ static: factory.createModifier(typescript.default.SyntaxKind.StaticKeyword)
218
+ };
219
+ const syntaxKind = {
220
+ union: SyntaxKind.UnionType,
221
+ literalType: SyntaxKind.LiteralType,
222
+ stringLiteral: SyntaxKind.StringLiteral
223
+ };
224
+ function isValidIdentifier(str) {
225
+ if (!str.length || str.trim() !== str) return false;
226
+ const node = typescript.default.parseIsolatedEntityName(str, typescript.default.ScriptTarget.Latest);
227
+ return !!node && node.kind === typescript.default.SyntaxKind.Identifier && typescript.default.identifierToKeywordKind(node.kind) === void 0;
228
+ }
229
+ function propertyName(name) {
230
+ if (typeof name === "string") return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
231
+ return name;
232
+ }
233
+ const questionToken = factory.createToken(typescript.default.SyntaxKind.QuestionToken);
234
+ function createQuestionToken(token) {
235
+ if (!token) return;
236
+ if (token === true) return questionToken;
237
+ return token;
238
+ }
239
+ function createIntersectionDeclaration({ nodes, withParentheses }) {
240
+ if (!nodes.length) return null;
241
+ if (nodes.length === 1) return nodes[0] || null;
242
+ const node = factory.createIntersectionTypeNode(nodes);
243
+ if (withParentheses) return factory.createParenthesizedType(node);
244
+ return node;
245
+ }
246
+ function createArrayDeclaration({ nodes, arrayType = "array" }) {
247
+ if (!nodes.length) return factory.createTupleTypeNode([]);
248
+ if (nodes.length === 1) {
249
+ const node = nodes[0];
250
+ if (!node) return null;
251
+ if (arrayType === "generic") return factory.createTypeReferenceNode(factory.createIdentifier("Array"), [node]);
252
+ return factory.createArrayTypeNode(node);
253
+ }
254
+ const unionType = factory.createUnionTypeNode(nodes);
255
+ if (arrayType === "generic") return factory.createTypeReferenceNode(factory.createIdentifier("Array"), [unionType]);
256
+ return factory.createArrayTypeNode(factory.createParenthesizedType(unionType));
257
+ }
258
+ /**
259
+ * Minimum nodes length of 2
260
+ * @example `string | number`
261
+ */
262
+ function createUnionDeclaration({ nodes, withParentheses }) {
263
+ if (!nodes.length) return keywordTypeNodes.any;
264
+ if (nodes.length === 1) return nodes[0];
265
+ const node = factory.createUnionTypeNode(nodes);
266
+ if (withParentheses) return factory.createParenthesizedType(node);
267
+ return node;
268
+ }
269
+ function createPropertySignature({ readOnly, modifiers = [], name, questionToken, type }) {
270
+ return factory.createPropertySignature([...modifiers, readOnly ? factory.createToken(typescript.default.SyntaxKind.ReadonlyKeyword) : void 0].filter(Boolean), propertyName(name), createQuestionToken(questionToken), type);
271
+ }
272
+ function createParameterSignature(name, { modifiers, dotDotDotToken, questionToken, type, initializer }) {
273
+ return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer);
274
+ }
275
+ /**
276
+ * @link https://github.com/microsoft/TypeScript/issues/44151
277
+ */
278
+ function appendJSDocToNode({ node, comments }) {
279
+ const filteredComments = comments.filter(Boolean);
280
+ if (!filteredComments.length) return node;
281
+ const text = filteredComments.reduce((acc = "", comment = "") => {
282
+ return `${acc}\n * ${comment.replaceAll("*/", "*\\/")}`;
283
+ }, "*");
284
+ return typescript.default.addSyntheticLeadingComment(node, typescript.default.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
285
+ }
286
+ function createIndexSignature(type, { modifiers, indexName = "key", indexType = factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword) } = {}) {
287
+ return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type);
288
+ }
289
+ function createTypeAliasDeclaration({ modifiers, name, typeParameters, type }) {
290
+ return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type);
291
+ }
292
+ function createInterfaceDeclaration({ modifiers, name, typeParameters, members }) {
293
+ return factory.createInterfaceDeclaration(modifiers, name, typeParameters, void 0, members);
294
+ }
295
+ function createTypeDeclaration({ syntax, isExportable, comments, name, type }) {
296
+ if (syntax === "interface" && "members" in type) return appendJSDocToNode({
297
+ node: createInterfaceDeclaration({
298
+ members: [...type.members],
299
+ modifiers: isExportable ? [modifiers.export] : [],
300
+ name,
301
+ typeParameters: void 0
302
+ }),
303
+ comments
304
+ });
305
+ return appendJSDocToNode({
306
+ node: createTypeAliasDeclaration({
307
+ type,
308
+ modifiers: isExportable ? [modifiers.export] : [],
309
+ name,
310
+ typeParameters: void 0
311
+ }),
312
+ comments
313
+ });
314
+ }
315
+ /**
316
+ * Apply casing transformation to enum keys
317
+ */
318
+ function applyEnumKeyCasing(key, casing = "none") {
319
+ if (casing === "none") return key;
320
+ if (casing === "screamingSnakeCase") return screamingSnakeCase(key);
321
+ if (casing === "snakeCase") return snakeCase(key);
322
+ if (casing === "pascalCase") return pascalCase(key);
323
+ if (casing === "camelCase") return camelCase(key);
324
+ return key;
325
+ }
326
+ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCasing = "none" }) {
327
+ if (type === "literal" || type === "inlineLiteral") return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createUnionTypeNode(enums.map(([_key, value]) => {
328
+ if ((0, remeda.isNumber)(value)) {
329
+ if (value < 0) return factory.createLiteralTypeNode(factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value))));
330
+ return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()));
331
+ }
332
+ if (typeof value === "boolean") return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse());
333
+ if (value) return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()));
334
+ }).filter(Boolean)))];
335
+ if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(typescript.default.SyntaxKind.ConstKeyword) : void 0].filter(Boolean), factory.createIdentifier(typeName), enums.map(([key, value]) => {
336
+ let initializer = factory.createStringLiteral(value?.toString());
337
+ if (Number.parseInt(value.toString(), 10) === value && (0, remeda.isNumber)(Number.parseInt(value.toString(), 10))) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
338
+ else initializer = factory.createNumericLiteral(value);
339
+ if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
340
+ if ((0, remeda.isNumber)(Number.parseInt(key.toString(), 10))) {
341
+ const casingKey = applyEnumKeyCasing(`${typeName}_${key}`, enumKeyCasing);
342
+ return factory.createEnumMember(propertyName(casingKey), initializer);
343
+ }
344
+ if (key) {
345
+ const casingKey = applyEnumKeyCasing(key.toString(), enumKeyCasing);
346
+ return factory.createEnumMember(propertyName(casingKey), initializer);
347
+ }
348
+ }).filter(Boolean))];
349
+ const identifierName = name;
350
+ if (enums.length === 0) return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword))];
351
+ return [factory.createVariableStatement([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(identifierName), void 0, void 0, factory.createAsExpression(factory.createObjectLiteralExpression(enums.map(([key, value]) => {
352
+ let initializer = factory.createStringLiteral(value?.toString());
353
+ if ((0, remeda.isNumber)(value)) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
354
+ else initializer = factory.createNumericLiteral(value);
355
+ if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
356
+ if (key) {
357
+ const casingKey = applyEnumKeyCasing(key.toString(), enumKeyCasing);
358
+ return factory.createPropertyAssignment(propertyName(casingKey), initializer);
359
+ }
360
+ }).filter(Boolean), true), factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0)))], typescript.default.NodeFlags.Const)), factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createIndexedAccessTypeNode(factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)), factory.createTypeOperatorNode(typescript.default.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0))))];
361
+ }
362
+ function createOmitDeclaration({ keys, type, nonNullable }) {
363
+ const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier("NonNullable"), [type]) : type;
364
+ if (Array.isArray(keys)) return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createUnionTypeNode(keys.map((key) => {
365
+ return factory.createLiteralTypeNode(factory.createStringLiteral(key));
366
+ }))]);
367
+ return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))]);
368
+ }
369
+ const keywordTypeNodes = {
370
+ any: factory.createKeywordTypeNode(typescript.default.SyntaxKind.AnyKeyword),
371
+ unknown: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UnknownKeyword),
372
+ void: factory.createKeywordTypeNode(typescript.default.SyntaxKind.VoidKeyword),
373
+ number: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
374
+ integer: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
375
+ bigint: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BigIntKeyword),
376
+ object: factory.createKeywordTypeNode(typescript.default.SyntaxKind.ObjectKeyword),
377
+ string: factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword),
378
+ boolean: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BooleanKeyword),
379
+ undefined: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UndefinedKeyword),
380
+ null: factory.createLiteralTypeNode(factory.createToken(typescript.default.SyntaxKind.NullKeyword)),
381
+ never: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword)
382
+ };
383
+ /**
384
+ * Converts a path like '/pet/{petId}/uploadImage' to a template literal type
385
+ * like `/pet/${string}/uploadImage`
386
+ */
387
+ /**
388
+ * Converts an OAS-style path (e.g. `/pets/{petId}`) or an Express-style path
389
+ * (e.g. `/pets/:petId`) to a TypeScript template literal type
390
+ * like `` `/pets/${string}` ``.
391
+ */
392
+ function createUrlTemplateType(path) {
393
+ const normalized = path.replace(/:([^/]+)/g, "{$1}");
394
+ if (!normalized.includes("{")) return factory.createLiteralTypeNode(factory.createStringLiteral(normalized));
395
+ const segments = normalized.split(/(\{[^}]+\})/);
396
+ const parts = [];
397
+ const parameterIndices = [];
398
+ segments.forEach((segment) => {
399
+ if (segment.startsWith("{") && segment.endsWith("}")) {
400
+ parameterIndices.push(parts.length);
401
+ parts.push(segment);
402
+ } else if (segment) parts.push(segment);
403
+ });
404
+ const head = typescript.default.factory.createTemplateHead(parts[0] || "");
405
+ const templateSpans = [];
406
+ parameterIndices.forEach((paramIndex, i) => {
407
+ const isLast = i === parameterIndices.length - 1;
408
+ const nextPart = parts[paramIndex + 1] || "";
409
+ const literal = isLast ? typescript.default.factory.createTemplateTail(nextPart) : typescript.default.factory.createTemplateMiddle(nextPart);
410
+ templateSpans.push(typescript.default.factory.createTemplateLiteralTypeSpan(keywordTypeNodes.string, literal));
411
+ });
412
+ return typescript.default.factory.createTemplateLiteralType(head, templateSpans);
413
+ }
414
+ const createTypeLiteralNode = factory.createTypeLiteralNode;
415
+ const createTypeReferenceNode = factory.createTypeReferenceNode;
416
+ const createNumericLiteral = factory.createNumericLiteral;
417
+ const createStringLiteral = factory.createStringLiteral;
418
+ const createArrayTypeNode = factory.createArrayTypeNode;
419
+ factory.createParenthesizedType;
420
+ const createLiteralTypeNode = factory.createLiteralTypeNode;
421
+ factory.createNull;
422
+ const createIdentifier = factory.createIdentifier;
423
+ const createOptionalTypeNode = factory.createOptionalTypeNode;
424
+ const createTupleTypeNode = factory.createTupleTypeNode;
425
+ const createRestTypeNode = factory.createRestTypeNode;
426
+ const createTrue = factory.createTrue;
427
+ const createFalse = factory.createFalse;
428
+ factory.createIndexedAccessTypeNode;
429
+ factory.createTypeOperatorNode;
430
+ const createPrefixUnaryExpression = factory.createPrefixUnaryExpression;
431
+ /**
432
+ * Converts a primitive const value to a TypeScript literal type node.
433
+ * Handles negative numbers via a prefix unary expression.
434
+ */
435
+ function constToTypeNode(value, format) {
436
+ if (format === "boolean") return createLiteralTypeNode(value === true ? createTrue() : createFalse());
437
+ if (format === "number" && typeof value === "number") {
438
+ if (value < 0) return createLiteralTypeNode(createPrefixUnaryExpression(SyntaxKind.MinusToken, createNumericLiteral(Math.abs(value))));
439
+ return createLiteralTypeNode(createNumericLiteral(value));
440
+ }
441
+ return createLiteralTypeNode(createStringLiteral(String(value)));
442
+ }
443
+ /**
444
+ * Returns a `Date` reference type node when `representation` is `'date'`, otherwise falls back to `string`.
445
+ */
446
+ function dateOrStringNode(node) {
447
+ return node.representation === "date" ? createTypeReferenceNode(createIdentifier("Date")) : keywordTypeNodes.string;
448
+ }
449
+ /**
450
+ * Maps an array of `SchemaNode`s through the printer, filtering out `null` and `undefined` results.
451
+ */
452
+ function buildMemberNodes(members, print) {
453
+ return (members ?? []).map(print).filter(Boolean);
454
+ }
455
+ /**
456
+ * Builds a TypeScript tuple type node from an array schema's `items`,
457
+ * applying min/max slice and optional/rest element rules.
458
+ */
459
+ function buildTupleNode(node, print) {
460
+ let items = (node.items ?? []).map(print).filter(Boolean);
461
+ const restNode = node.rest ? print(node.rest) ?? void 0 : void 0;
462
+ const { min, max } = node;
463
+ if (max !== void 0) {
464
+ items = items.slice(0, max);
465
+ if (items.length < max && restNode) items = [...items, ...Array(max - items.length).fill(restNode)];
466
+ }
467
+ if (min !== void 0) items = items.map((item, i) => i >= min ? createOptionalTypeNode(item) : item);
468
+ if (max === void 0 && restNode) items.push(createRestTypeNode(createArrayTypeNode(restNode)));
469
+ return createTupleTypeNode(items);
470
+ }
471
+ /**
472
+ * Applies `nullable` and optional/nullish `| undefined` union modifiers to a property's resolved base type.
473
+ */
474
+ function buildPropertyType(schema, baseType, optionalType) {
475
+ const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
476
+ const meta = (0, _kubb_ast.syncSchemaRef)(schema);
477
+ let type = baseType;
478
+ if (meta.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
479
+ if ((meta.nullish || meta.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
480
+ return type;
481
+ }
482
+ /**
483
+ * Creates TypeScript index signatures for `additionalProperties` and `patternProperties` on an object schema node.
484
+ */
485
+ function buildIndexSignatures(node, propertyCount, print) {
486
+ const elements = [];
487
+ if (node.additionalProperties && node.additionalProperties !== true) {
488
+ const additionalType = print(node.additionalProperties) ?? keywordTypeNodes.unknown;
489
+ elements.push(createIndexSignature(propertyCount > 0 ? keywordTypeNodes.unknown : additionalType));
490
+ } else if (node.additionalProperties === true) elements.push(createIndexSignature(keywordTypeNodes.unknown));
491
+ if (node.patternProperties) {
492
+ const first = Object.values(node.patternProperties)[0];
493
+ if (first) {
494
+ let patternType = print(first) ?? keywordTypeNodes.unknown;
495
+ if (first.nullable) patternType = createUnionDeclaration({ nodes: [patternType, keywordTypeNodes.null] });
496
+ elements.push(createIndexSignature(patternType));
497
+ }
498
+ }
499
+ return elements;
500
+ }
501
+ //#endregion
502
+ //#region src/components/Enum.tsx
503
+ /**
504
+ * Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
505
+ *
506
+ * The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
507
+ * valid TypeScript identifier. The resolver normalizes it; for inline enum
508
+ * properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
509
+ */
510
+ function getEnumNames({ node, enumType, enumTypeSuffix, resolver }) {
511
+ const resolved = resolver.default(node.name, "type");
512
+ return {
513
+ enumName: enumType === "asPascalConst" ? resolved : camelCase(node.name),
514
+ typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? resolver.resolveEnumKeyName(node, enumTypeSuffix) : resolved
515
+ };
516
+ }
517
+ /**
518
+ * Renders the enum declaration(s) for a single named `EnumSchemaNode`.
519
+ *
520
+ * Depending on `enumType` this may emit:
521
+ * - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
522
+ * - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
523
+ * - A union literal type alias (`literal`)
524
+ *
525
+ * The emitted `File.Source` nodes carry the resolved names so that the barrel
526
+ * index picks up the correct export identifiers.
527
+ */
528
+ function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }) {
529
+ const { enumName, typeName } = getEnumNames({
530
+ node,
531
+ enumType,
532
+ enumTypeSuffix,
533
+ resolver
534
+ });
535
+ const [nameNode, typeNode] = createEnumDeclaration({
536
+ name: enumName,
537
+ typeName,
538
+ enums: node.namedEnumValues?.map((v) => [trimQuotes(v.name.toString()), v.value]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes(v.toString()), v]) ?? [],
539
+ type: enumType,
540
+ enumKeyCasing
541
+ });
542
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [nameNode && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
543
+ name: enumName,
544
+ isExportable: true,
545
+ isIndexable: true,
546
+ isTypeOnly: false,
547
+ children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(nameNode)
548
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
549
+ name: typeName,
550
+ isIndexable: true,
551
+ isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
552
+ isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
553
+ children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
554
+ })] });
555
+ }
556
+ //#endregion
557
+ //#region src/components/Type.tsx
558
+ function Type({ name, node, printer, enumType, enumTypeSuffix, enumKeyCasing, resolver }) {
559
+ const enumSchemaNodes = (0, _kubb_ast.collect)(node, { schema(n) {
560
+ const enumNode = (0, _kubb_ast.narrowSchema)(n, _kubb_ast.schemaTypes.enum);
561
+ if (enumNode?.name) return enumNode;
562
+ } });
563
+ const output = printer.print(node);
564
+ if (!output) return;
565
+ const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
566
+ return {
567
+ node,
568
+ ...getEnumNames({
569
+ node,
570
+ enumType,
571
+ enumTypeSuffix,
572
+ resolver
573
+ })
574
+ };
575
+ });
576
+ const shouldExportEnums = enumType !== "inlineLiteral";
577
+ const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
578
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Enum, {
579
+ node,
580
+ enumType,
581
+ enumTypeSuffix,
582
+ enumKeyCasing,
583
+ resolver
584
+ })), shouldExportType && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
585
+ name,
586
+ isTypeOnly: true,
587
+ isExportable: true,
588
+ isIndexable: true,
589
+ children: output
590
+ })] });
591
+ }
592
+ //#endregion
593
+ //#region src/utils.ts
594
+ /**
595
+ * Collects JSDoc annotation strings for a schema node.
596
+ *
597
+ * Only uses official JSDoc tags from https://jsdoc.app/: `@description`, `@deprecated`, `@default`, `@example`, `@type`.
598
+ * Constraint metadata (min/max length, pattern, multipleOf, min/maxProperties) is emitted as plain-text lines.
599
+
600
+ */
601
+ function buildPropertyJSDocComments(schema) {
602
+ const meta = (0, _kubb_ast.syncSchemaRef)(schema);
603
+ const isArray = meta?.primitive === "array";
604
+ return [
605
+ meta && "description" in meta && meta.description ? `@description ${jsStringEscape(meta.description)}` : void 0,
606
+ meta && "deprecated" in meta && meta.deprecated ? "@deprecated" : void 0,
607
+ !isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : void 0,
608
+ !isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : void 0,
609
+ meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : void 0,
610
+ meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" ? stringify(meta.default) : meta.default}` : void 0,
611
+ meta && "example" in meta && meta.example !== void 0 ? `@example ${meta.example}` : void 0,
612
+ meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
613
+ ].filter(Boolean);
614
+ }
615
+ function buildParams(node, { params, resolver }) {
616
+ return (0, _kubb_ast.createSchema)({
617
+ type: "object",
618
+ properties: params.map((param) => (0, _kubb_ast.createProperty)({
619
+ name: param.name,
620
+ required: param.required,
621
+ schema: (0, _kubb_ast.createSchema)({
622
+ type: "ref",
623
+ name: resolver.resolveParamName(node, param)
624
+ })
625
+ }))
626
+ });
627
+ }
628
+ function buildData(node, { resolver }) {
629
+ const pathParams = node.parameters.filter((p) => p.in === "path");
630
+ const queryParams = node.parameters.filter((p) => p.in === "query");
631
+ const headerParams = node.parameters.filter((p) => p.in === "header");
632
+ return (0, _kubb_ast.createSchema)({
633
+ type: "object",
634
+ deprecated: node.deprecated,
635
+ properties: [
636
+ (0, _kubb_ast.createProperty)({
637
+ name: "data",
638
+ schema: node.requestBody?.schema ? (0, _kubb_ast.createSchema)({
639
+ type: "ref",
640
+ name: resolver.resolveDataName(node),
641
+ optional: true
642
+ }) : (0, _kubb_ast.createSchema)({
643
+ type: "never",
644
+ primitive: void 0,
645
+ optional: true
646
+ })
647
+ }),
648
+ (0, _kubb_ast.createProperty)({
649
+ name: "pathParams",
650
+ required: pathParams.length > 0,
651
+ schema: pathParams.length > 0 ? buildParams(node, {
652
+ params: pathParams,
653
+ resolver
654
+ }) : (0, _kubb_ast.createSchema)({
655
+ type: "never",
656
+ primitive: void 0
657
+ })
658
+ }),
659
+ (0, _kubb_ast.createProperty)({
660
+ name: "queryParams",
661
+ schema: queryParams.length > 0 ? (0, _kubb_ast.createSchema)({
662
+ ...buildParams(node, {
663
+ params: queryParams,
664
+ resolver
665
+ }),
666
+ optional: true
667
+ }) : (0, _kubb_ast.createSchema)({
668
+ type: "never",
669
+ primitive: void 0,
670
+ optional: true
671
+ })
672
+ }),
673
+ (0, _kubb_ast.createProperty)({
674
+ name: "headerParams",
675
+ schema: headerParams.length > 0 ? (0, _kubb_ast.createSchema)({
676
+ ...buildParams(node, {
677
+ params: headerParams,
678
+ resolver
679
+ }),
680
+ optional: true
681
+ }) : (0, _kubb_ast.createSchema)({
682
+ type: "never",
683
+ primitive: void 0,
684
+ optional: true
685
+ })
686
+ }),
687
+ (0, _kubb_ast.createProperty)({
688
+ name: "url",
689
+ required: true,
690
+ schema: (0, _kubb_ast.createSchema)({
691
+ type: "url",
692
+ path: node.path
693
+ })
694
+ })
695
+ ]
696
+ });
697
+ }
698
+ function buildResponses(node, { resolver }) {
699
+ if (node.responses.length === 0) return null;
700
+ return (0, _kubb_ast.createSchema)({
701
+ type: "object",
702
+ properties: node.responses.map((res) => (0, _kubb_ast.createProperty)({
703
+ name: String(res.statusCode),
704
+ required: true,
705
+ schema: (0, _kubb_ast.createSchema)({
706
+ type: "ref",
707
+ name: resolver.resolveResponseStatusName(node, res.statusCode)
708
+ })
709
+ }))
710
+ });
711
+ }
712
+ function buildResponseUnion(node, { resolver }) {
713
+ const responsesWithSchema = node.responses.filter((res) => res.schema);
714
+ if (responsesWithSchema.length === 0) return null;
715
+ return (0, _kubb_ast.createSchema)({
716
+ type: "union",
717
+ members: responsesWithSchema.map((res) => (0, _kubb_ast.createSchema)({
718
+ type: "ref",
719
+ name: resolver.resolveResponseStatusName(node, res.statusCode)
720
+ }))
721
+ });
722
+ }
723
+ //#endregion
724
+ //#region src/printers/printerTs.ts
725
+ /**
726
+ * TypeScript type printer built with `definePrinter`.
727
+ *
728
+ * Converts a `SchemaNode` AST node into a TypeScript AST node:
729
+ * - **`printer.print(node)`** — when `options.typeName` is set, returns a full
730
+ * `type Name = …` or `interface Name { … }` declaration (`ts.Node`).
731
+ * Without `typeName`, returns the raw `ts.TypeNode` for the schema.
732
+ *
733
+ * Dispatches on `node.type` to the appropriate handler in `nodes`. Options are closed
734
+ * over per printer instance, so each call to `printerTs(options)` produces an independent printer.
735
+ *
736
+ * @example Raw type node (no `typeName`)
737
+ * ```ts
738
+ * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral' })
739
+ * const typeNode = printer.print(schemaNode) // ts.TypeNode
740
+ * ```
741
+ *
742
+ * @example Full declaration (with `typeName`)
743
+ * ```ts
744
+ * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral', typeName: 'MyType' })
745
+ * const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
746
+ * ```
747
+ */
748
+ const printerTs = (0, _kubb_core.definePrinter)((options) => {
749
+ const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(options.optionalType);
750
+ return {
751
+ name: "typescript",
752
+ options,
753
+ nodes: {
754
+ any: () => keywordTypeNodes.any,
755
+ unknown: () => keywordTypeNodes.unknown,
756
+ void: () => keywordTypeNodes.void,
757
+ never: () => keywordTypeNodes.never,
758
+ boolean: () => keywordTypeNodes.boolean,
759
+ null: () => keywordTypeNodes.null,
760
+ blob: () => createTypeReferenceNode("Blob", []),
761
+ string: () => keywordTypeNodes.string,
762
+ uuid: () => keywordTypeNodes.string,
763
+ email: () => keywordTypeNodes.string,
764
+ url: (node) => {
765
+ if (node.path) return createUrlTemplateType(node.path);
766
+ return keywordTypeNodes.string;
767
+ },
768
+ ipv4: () => keywordTypeNodes.string,
769
+ ipv6: () => keywordTypeNodes.string,
770
+ datetime: () => keywordTypeNodes.string,
771
+ number: () => keywordTypeNodes.number,
772
+ integer: () => keywordTypeNodes.number,
773
+ bigint: () => keywordTypeNodes.bigint,
774
+ date: dateOrStringNode,
775
+ time: dateOrStringNode,
776
+ ref(node) {
777
+ if (!node.name) return;
778
+ const refName = node.ref ? (0, _kubb_ast.extractRefName)(node.ref) ?? node.name : node.name;
779
+ return createTypeReferenceNode(node.ref && ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) && this.options.enumTypeSuffix && this.options.enumSchemaNames?.has(refName) ? this.options.resolver.resolveEnumKeyName({ name: refName }, this.options.enumTypeSuffix) : node.ref ? this.options.resolver.default(refName, "type") : refName, void 0);
780
+ },
781
+ enum(node) {
782
+ const values = node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? [];
783
+ if (this.options.enumType === "inlineLiteral" || !node.name) return createUnionDeclaration({
784
+ withParentheses: true,
785
+ nodes: values.filter((v) => v !== null && v !== void 0).map((value) => constToTypeNode(value, typeof value)).filter(Boolean)
786
+ }) ?? void 0;
787
+ return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) && this.options.enumTypeSuffix ? this.options.resolver.resolveEnumKeyName(node, this.options.enumTypeSuffix) : this.options.resolver.default(node.name, "type"), void 0);
788
+ },
789
+ union(node) {
790
+ const members = node.members ?? [];
791
+ const hasStringLiteral = members.some((m) => {
792
+ return (0, _kubb_ast.narrowSchema)(m, _kubb_ast.schemaTypes.enum)?.primitive === "string";
793
+ });
794
+ const hasPlainString = members.some((m) => (0, _kubb_ast.isStringType)(m));
795
+ if (hasStringLiteral && hasPlainString) return createUnionDeclaration({
796
+ withParentheses: true,
797
+ nodes: members.map((m) => {
798
+ if ((0, _kubb_ast.isStringType)(m)) return createIntersectionDeclaration({
799
+ nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
800
+ withParentheses: true
801
+ });
802
+ return this.transform(m);
803
+ }).filter(Boolean)
804
+ }) ?? void 0;
805
+ return createUnionDeclaration({
806
+ withParentheses: true,
807
+ nodes: buildMemberNodes(members, this.transform)
808
+ }) ?? void 0;
809
+ },
810
+ intersection(node) {
811
+ return createIntersectionDeclaration({
812
+ withParentheses: true,
813
+ nodes: buildMemberNodes(node.members, this.transform)
814
+ }) ?? void 0;
815
+ },
816
+ array(node) {
817
+ return createArrayDeclaration({
818
+ nodes: (node.items ?? []).map((item) => this.transform(item)).filter(Boolean),
819
+ arrayType: this.options.arrayType
820
+ }) ?? void 0;
821
+ },
822
+ tuple(node) {
823
+ return buildTupleNode(node, this.transform);
824
+ },
825
+ object(node) {
826
+ const { transform, options } = this;
827
+ const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options.optionalType);
828
+ const propertyNodes = node.properties.map((prop) => {
829
+ const baseType = transform(prop.schema) ?? keywordTypeNodes.unknown;
830
+ const type = buildPropertyType(prop.schema, baseType, options.optionalType);
831
+ const propMeta = (0, _kubb_ast.syncSchemaRef)(prop.schema);
832
+ return appendJSDocToNode({
833
+ node: createPropertySignature({
834
+ questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
835
+ name: prop.name,
836
+ type,
837
+ readOnly: propMeta?.readOnly
838
+ }),
839
+ comments: buildPropertyJSDocComments(prop.schema)
840
+ });
841
+ });
842
+ const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, transform)];
843
+ if (!allElements.length) return keywordTypeNodes.object;
844
+ return createTypeLiteralNode(allElements);
845
+ },
846
+ ...options.nodes
847
+ },
848
+ print(node) {
849
+ const { name, syntaxType = "type", description, keysToOmit } = this.options;
850
+ let base = this.transform(node);
851
+ if (!base) return null;
852
+ const meta = (0, _kubb_ast.syncSchemaRef)(node);
853
+ if (!name) {
854
+ if (meta.nullable) base = createUnionDeclaration({ nodes: [base, keywordTypeNodes.null] });
855
+ if ((meta.nullish || meta.optional) && addsUndefined) base = createUnionDeclaration({ nodes: [base, keywordTypeNodes.undefined] });
856
+ return (0, _kubb_fabric_core_parsers_typescript.safePrint)(base);
857
+ }
858
+ let inner = keysToOmit?.length ? createOmitDeclaration({
859
+ keys: keysToOmit,
860
+ type: base,
861
+ nonNullable: true
862
+ }) : base;
863
+ if (meta.nullable) inner = createUnionDeclaration({ nodes: [inner, keywordTypeNodes.null] });
864
+ if (meta.nullish || meta.optional) inner = createUnionDeclaration({ nodes: [inner, keywordTypeNodes.undefined] });
865
+ const useTypeGeneration = syntaxType === "type" || inner.kind === syntaxKind.union || !!keysToOmit?.length;
866
+ return (0, _kubb_fabric_core_parsers_typescript.safePrint)(createTypeDeclaration({
867
+ name,
868
+ isExportable: true,
869
+ type: inner,
870
+ syntax: useTypeGeneration ? "type" : "interface",
871
+ comments: buildPropertyJSDocComments({
872
+ ...meta,
873
+ description
874
+ })
875
+ }));
876
+ }
877
+ };
878
+ });
879
+ //#endregion
880
+ //#region src/generators/typeGenerator.tsx
881
+ const typeGenerator = (0, _kubb_core.defineGenerator)({
882
+ name: "typescript",
883
+ schema(node, options) {
884
+ const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group, printer } = options;
885
+ const { adapter, config, resolver, root } = this;
886
+ if (!node.name) return;
887
+ const mode = this.getMode(output);
888
+ const enumSchemaNames = new Set((adapter.rootNode?.schemas ?? []).filter((s) => (0, _kubb_ast.narrowSchema)(s, _kubb_ast.schemaTypes.enum) && s.name).map((s) => s.name));
889
+ function resolveImportName(schemaName) {
890
+ if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
891
+ return resolver.resolveTypeName(schemaName);
892
+ }
893
+ const imports = adapter.getImports(node, (schemaName) => ({
894
+ name: resolveImportName(schemaName),
895
+ path: resolver.resolveFile({
896
+ name: schemaName,
897
+ extname: ".ts"
898
+ }, {
899
+ root,
900
+ output,
901
+ group
902
+ }).path
903
+ }));
904
+ const isEnumSchema = !!(0, _kubb_ast.narrowSchema)(node, _kubb_ast.schemaTypes.enum);
905
+ const meta = {
906
+ name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(node, enumTypeSuffix) : resolver.resolveTypeName(node.name),
907
+ file: resolver.resolveFile({
908
+ name: node.name,
909
+ extname: ".ts"
910
+ }, {
911
+ root,
912
+ output,
913
+ group
914
+ })
915
+ };
916
+ const schemaPrinter = printerTs({
917
+ optionalType,
918
+ arrayType,
919
+ enumType,
920
+ enumTypeSuffix,
921
+ name: meta.name,
922
+ syntaxType,
923
+ description: node.description,
924
+ resolver,
925
+ enumSchemaNames,
926
+ nodes: printer?.nodes
927
+ });
928
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
929
+ baseName: meta.file.baseName,
930
+ path: meta.file.path,
931
+ meta: meta.file.meta,
932
+ banner: resolver.resolveBanner(adapter.rootNode, {
933
+ output,
934
+ config
935
+ }),
936
+ footer: resolver.resolveFooter(adapter.rootNode, {
937
+ output,
938
+ config
939
+ }),
940
+ children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
941
+ root: meta.file.path,
942
+ path: imp.path,
943
+ name: imp.name,
944
+ isTypeOnly: true
945
+ }, [
946
+ node.name,
947
+ imp.path,
948
+ imp.isTypeOnly
949
+ ].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Type, {
950
+ name: meta.name,
951
+ node,
952
+ enumType,
953
+ enumTypeSuffix,
954
+ enumKeyCasing,
955
+ resolver,
956
+ printer: schemaPrinter
957
+ })]
958
+ });
959
+ },
960
+ operation(node, options) {
961
+ const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output, printer } = options;
962
+ const { adapter, config, resolver, root } = this;
963
+ const mode = this.getMode(output);
964
+ const params = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
965
+ const meta = { file: resolver.resolveFile({
966
+ name: node.operationId,
967
+ extname: ".ts",
968
+ tag: node.tags[0] ?? "default",
969
+ path: node.path
970
+ }, {
971
+ root,
972
+ output,
973
+ group
974
+ }) };
975
+ const enumSchemaNames = new Set((adapter.rootNode?.schemas ?? []).filter((s) => (0, _kubb_ast.narrowSchema)(s, _kubb_ast.schemaTypes.enum) && s.name).map((s) => s.name));
976
+ function resolveImportName(schemaName) {
977
+ if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
978
+ return resolver.resolveTypeName(schemaName);
979
+ }
980
+ function renderSchemaType({ schema, name, keysToOmit }) {
981
+ if (!schema) return null;
982
+ const imports = adapter.getImports(schema, (schemaName) => ({
983
+ name: resolveImportName(schemaName),
984
+ path: resolver.resolveFile({
985
+ name: schemaName,
986
+ extname: ".ts"
987
+ }, {
988
+ root,
989
+ output,
990
+ group
991
+ }).path
992
+ }));
993
+ const schemaPrinter = printerTs({
994
+ optionalType,
995
+ arrayType,
996
+ enumType,
997
+ enumTypeSuffix,
998
+ name,
999
+ syntaxType,
1000
+ description: schema.description,
1001
+ keysToOmit,
1002
+ resolver,
1003
+ enumSchemaNames,
1004
+ nodes: printer?.nodes
1005
+ });
1006
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1007
+ root: meta.file.path,
1008
+ path: imp.path,
1009
+ name: imp.name,
1010
+ isTypeOnly: true
1011
+ }, [
1012
+ name,
1013
+ imp.path,
1014
+ imp.isTypeOnly
1015
+ ].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Type, {
1016
+ name,
1017
+ node: schema,
1018
+ enumType,
1019
+ enumTypeSuffix,
1020
+ enumKeyCasing,
1021
+ resolver,
1022
+ printer: schemaPrinter
1023
+ })] });
1024
+ }
1025
+ const paramTypes = params.map((param) => renderSchemaType({
1026
+ schema: param.schema,
1027
+ name: resolver.resolveParamName(node, param)
1028
+ }));
1029
+ const requestType = node.requestBody?.schema ? renderSchemaType({
1030
+ schema: {
1031
+ ...node.requestBody.schema,
1032
+ description: node.requestBody.description ?? node.requestBody.schema.description
1033
+ },
1034
+ name: resolver.resolveDataName(node),
1035
+ keysToOmit: node.requestBody.keysToOmit
1036
+ }) : null;
1037
+ const responseTypes = node.responses.map((res) => renderSchemaType({
1038
+ schema: res.schema,
1039
+ name: resolver.resolveResponseStatusName(node, res.statusCode),
1040
+ keysToOmit: res.keysToOmit
1041
+ }));
1042
+ const dataType = renderSchemaType({
1043
+ schema: buildData({
1044
+ ...node,
1045
+ parameters: params
1046
+ }, { resolver }),
1047
+ name: resolver.resolveRequestConfigName(node)
1048
+ });
1049
+ const responsesType = renderSchemaType({
1050
+ schema: buildResponses(node, { resolver }),
1051
+ name: resolver.resolveResponsesName(node)
1052
+ });
1053
+ const responseType = renderSchemaType({
1054
+ schema: node.responses.some((res) => res.schema) ? {
1055
+ ...buildResponseUnion(node, { resolver }),
1056
+ description: "Union of all possible responses"
1057
+ } : null,
1058
+ name: resolver.resolveResponseName(node)
1059
+ });
1060
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1061
+ baseName: meta.file.baseName,
1062
+ path: meta.file.path,
1063
+ meta: meta.file.meta,
1064
+ banner: resolver.resolveBanner(adapter.rootNode, {
1065
+ output,
1066
+ config
1067
+ }),
1068
+ footer: resolver.resolveFooter(adapter.rootNode, {
1069
+ output,
1070
+ config
1071
+ }),
1072
+ children: [
1073
+ paramTypes,
1074
+ responseTypes,
1075
+ requestType,
1076
+ dataType,
1077
+ responsesType,
1078
+ responseType
1079
+ ]
1080
+ });
1081
+ }
1082
+ });
1083
+ //#endregion
1084
+ //#region package.json
1085
+ var version = "5.0.0-alpha.30";
1086
+ //#endregion
1087
+ //#region src/resolvers/resolverTs.ts
1088
+ /**
1089
+ * Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
1090
+ * helpers used by the plugin. Import this in other plugins to resolve the exact names and
1091
+ * paths that `plugin-ts` generates without hardcoding the conventions.
1092
+ *
1093
+ * The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
1094
+ * for identifiers/files and `pascalCase` for type names.
1095
+ *
1096
+ * @example
1097
+ * ```ts
1098
+ * import { resolver } from '@kubb/plugin-ts'
1099
+ *
1100
+ * resolver.default('list pets', 'type') // → 'ListPets'
1101
+ * resolver.resolveName('list pets status 200') // → 'ListPetsStatus200'
1102
+ * resolver.resolvePathName('list pets', 'file') // → 'listPets'
1103
+ * ```
1104
+ */
1105
+ const resolverTs = (0, _kubb_core.defineResolver)(() => {
1106
+ return {
1107
+ name: "default",
1108
+ pluginName: "plugin-ts",
1109
+ default(name, type) {
1110
+ return pascalCase(name, { isFile: type === "file" });
1111
+ },
1112
+ resolveTypeName(name) {
1113
+ return pascalCase(name);
1114
+ },
1115
+ resolvePathName(name, type) {
1116
+ return pascalCase(name, { isFile: type === "file" });
1117
+ },
1118
+ resolveParamName(node, param) {
1119
+ return this.resolveTypeName(`${node.operationId} ${param.in} ${param.name}`);
1120
+ },
1121
+ resolveResponseStatusName(node, statusCode) {
1122
+ return this.resolveTypeName(`${node.operationId} Status ${statusCode}`);
1123
+ },
1124
+ resolveDataName(node) {
1125
+ return this.resolveTypeName(`${node.operationId} Data`);
1126
+ },
1127
+ resolveRequestConfigName(node) {
1128
+ return this.resolveTypeName(`${node.operationId} RequestConfig`);
1129
+ },
1130
+ resolveResponsesName(node) {
1131
+ return this.resolveTypeName(`${node.operationId} Responses`);
1132
+ },
1133
+ resolveResponseName(node) {
1134
+ return this.resolveTypeName(`${node.operationId} Response`);
1135
+ },
1136
+ resolveEnumKeyName(node, enumTypeSuffix = "key") {
1137
+ return `${this.resolveTypeName(node.name ?? "")}${enumTypeSuffix}`;
1138
+ },
1139
+ resolvePathParamsName(node, param) {
1140
+ return this.resolveParamName(node, param);
1141
+ },
1142
+ resolveQueryParamsName(node, param) {
1143
+ return this.resolveParamName(node, param);
1144
+ },
1145
+ resolveHeaderParamsName(node, param) {
1146
+ return this.resolveParamName(node, param);
1147
+ }
1148
+ };
1149
+ });
1150
+ //#endregion
1151
+ //#region src/resolvers/resolverTsLegacy.ts
1152
+ /**
1153
+ * Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions
1154
+ * used before the v2 resolver refactor. Enable via `compatibilityPreset: 'kubbV4'`
1155
+ * (or by composing this resolver manually).
1156
+ *
1157
+ * Key differences from the default resolver:
1158
+ * - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`
1159
+ * - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`
1160
+ * - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)
1161
+ * - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`
1162
+ * - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`
1163
+ *
1164
+ * @example
1165
+ * ```ts
1166
+ * import { resolverTsLegacy } from '@kubb/plugin-ts'
1167
+ *
1168
+ * resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'
1169
+ * resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'
1170
+ * resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)
1171
+ * resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)
1172
+ * resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)
1173
+ * ```
1174
+ */
1175
+ const resolverTsLegacy = (0, _kubb_core.defineResolver)(() => {
1176
+ return {
1177
+ ...resolverTs,
1178
+ pluginName: "plugin-ts",
1179
+ resolveResponseStatusName(node, statusCode) {
1180
+ if (statusCode === "default") return this.resolveTypeName(`${node.operationId} Error`);
1181
+ return this.resolveTypeName(`${node.operationId} ${statusCode}`);
1182
+ },
1183
+ resolveDataName(node) {
1184
+ const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
1185
+ return this.resolveTypeName(`${node.operationId} ${suffix}`);
1186
+ },
1187
+ resolveResponsesName(node) {
1188
+ const suffix = node.method === "GET" ? "Query" : "Mutation";
1189
+ return this.resolveTypeName(`${node.operationId} ${suffix}`);
1190
+ },
1191
+ resolveResponseName(node) {
1192
+ const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
1193
+ return this.resolveTypeName(`${node.operationId} ${suffix}`);
1194
+ },
1195
+ resolvePathParamsName(node, _param) {
1196
+ return this.resolveTypeName(`${node.operationId} PathParams`);
1197
+ },
1198
+ resolveQueryParamsName(node, _param) {
1199
+ return this.resolveTypeName(`${node.operationId} QueryParams`);
1200
+ },
1201
+ resolveHeaderParamsName(node, _param) {
1202
+ return this.resolveTypeName(`${node.operationId} HeaderParams`);
1203
+ }
1204
+ };
1205
+ });
1206
+ //#endregion
1207
+ //#region src/generators/typeGeneratorLegacy.tsx
1208
+ function buildGroupedParamsSchema({ params, parentName }) {
1209
+ return (0, _kubb_ast.createSchema)({
1210
+ type: "object",
1211
+ properties: params.map((param) => {
1212
+ let schema = param.schema;
1213
+ if ((0, _kubb_ast.narrowSchema)(schema, "enum") && !schema.name && parentName) schema = {
1214
+ ...schema,
1215
+ name: pascalCase([
1216
+ parentName,
1217
+ param.name,
1218
+ "enum"
1219
+ ].join(" "))
1220
+ };
1221
+ return (0, _kubb_ast.createProperty)({
1222
+ name: param.name,
1223
+ required: param.required,
1224
+ schema
1225
+ });
1226
+ })
1227
+ });
1228
+ }
1229
+ function buildLegacyResponsesSchemaNode(node, { resolver }) {
1230
+ const isGet = node.method.toLowerCase() === "get";
1231
+ const successResponses = node.responses.filter((res) => {
1232
+ const code = Number(res.statusCode);
1233
+ return !Number.isNaN(code) && code >= 200 && code < 300;
1234
+ });
1235
+ const errorResponses = node.responses.filter((res) => res.statusCode === "default" || Number(res.statusCode) >= 400);
1236
+ const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ? (0, _kubb_ast.createSchema)({
1237
+ type: "ref",
1238
+ name: resolver.resolveResponseStatusName(node, successResponses[0].statusCode)
1239
+ }) : (0, _kubb_ast.createSchema)({
1240
+ type: "union",
1241
+ members: successResponses.map((res) => (0, _kubb_ast.createSchema)({
1242
+ type: "ref",
1243
+ name: resolver.resolveResponseStatusName(node, res.statusCode)
1244
+ }))
1245
+ }) : (0, _kubb_ast.createSchema)({
1246
+ type: "any",
1247
+ primitive: void 0
1248
+ });
1249
+ const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ? (0, _kubb_ast.createSchema)({
1250
+ type: "ref",
1251
+ name: resolver.resolveResponseStatusName(node, errorResponses[0].statusCode)
1252
+ }) : (0, _kubb_ast.createSchema)({
1253
+ type: "union",
1254
+ members: errorResponses.map((res) => (0, _kubb_ast.createSchema)({
1255
+ type: "ref",
1256
+ name: resolver.resolveResponseStatusName(node, res.statusCode)
1257
+ }))
1258
+ }) : (0, _kubb_ast.createSchema)({
1259
+ type: "any",
1260
+ primitive: void 0
1261
+ });
1262
+ const properties = [(0, _kubb_ast.createProperty)({
1263
+ name: "Response",
1264
+ required: true,
1265
+ schema: responseSchema
1266
+ })];
1267
+ if (!isGet && node.requestBody?.schema) properties.push((0, _kubb_ast.createProperty)({
1268
+ name: "Request",
1269
+ required: true,
1270
+ schema: (0, _kubb_ast.createSchema)({
1271
+ type: "ref",
1272
+ name: resolver.resolveDataName(node)
1273
+ })
1274
+ }));
1275
+ const queryParam = node.parameters.find((p) => p.in === "query");
1276
+ if (queryParam) properties.push((0, _kubb_ast.createProperty)({
1277
+ name: "QueryParams",
1278
+ required: true,
1279
+ schema: (0, _kubb_ast.createSchema)({
1280
+ type: "ref",
1281
+ name: resolver.resolveQueryParamsName(node, queryParam)
1282
+ })
1283
+ }));
1284
+ const pathParam = node.parameters.find((p) => p.in === "path");
1285
+ if (pathParam) properties.push((0, _kubb_ast.createProperty)({
1286
+ name: "PathParams",
1287
+ required: true,
1288
+ schema: (0, _kubb_ast.createSchema)({
1289
+ type: "ref",
1290
+ name: resolver.resolvePathParamsName(node, pathParam)
1291
+ })
1292
+ }));
1293
+ const headerParam = node.parameters.find((p) => p.in === "header");
1294
+ if (headerParam) properties.push((0, _kubb_ast.createProperty)({
1295
+ name: "HeaderParams",
1296
+ required: true,
1297
+ schema: (0, _kubb_ast.createSchema)({
1298
+ type: "ref",
1299
+ name: resolver.resolveHeaderParamsName(node, headerParam)
1300
+ })
1301
+ }));
1302
+ properties.push((0, _kubb_ast.createProperty)({
1303
+ name: "Errors",
1304
+ required: true,
1305
+ schema: errorsSchema
1306
+ }));
1307
+ return (0, _kubb_ast.createSchema)({
1308
+ type: "object",
1309
+ properties
1310
+ });
1311
+ }
1312
+ function buildLegacyResponseUnionSchemaNode(node, { resolver }) {
1313
+ const successResponses = node.responses.filter((res) => {
1314
+ const code = Number(res.statusCode);
1315
+ return !Number.isNaN(code) && code >= 200 && code < 300;
1316
+ });
1317
+ if (successResponses.length === 0) return (0, _kubb_ast.createSchema)({
1318
+ type: "any",
1319
+ primitive: void 0
1320
+ });
1321
+ if (successResponses.length === 1) return (0, _kubb_ast.createSchema)({
1322
+ type: "ref",
1323
+ name: resolver.resolveResponseStatusName(node, successResponses[0].statusCode)
1324
+ });
1325
+ return (0, _kubb_ast.createSchema)({
1326
+ type: "union",
1327
+ members: successResponses.map((res) => (0, _kubb_ast.createSchema)({
1328
+ type: "ref",
1329
+ name: resolver.resolveResponseStatusName(node, res.statusCode)
1330
+ }))
1331
+ });
1332
+ }
1333
+ function nameUnnamedEnums(node, parentName) {
1334
+ return (0, _kubb_ast.transform)(node, {
1335
+ schema(n) {
1336
+ const enumNode = (0, _kubb_ast.narrowSchema)(n, "enum");
1337
+ if (enumNode && !enumNode.name) return {
1338
+ ...enumNode,
1339
+ name: pascalCase([parentName, "enum"].join(" "))
1340
+ };
1341
+ },
1342
+ property(p) {
1343
+ const enumNode = (0, _kubb_ast.narrowSchema)(p.schema, "enum");
1344
+ if (enumNode && !enumNode.name) return {
1345
+ ...p,
1346
+ schema: {
1347
+ ...enumNode,
1348
+ name: pascalCase([
1349
+ parentName,
1350
+ p.name,
1351
+ "enum"
1352
+ ].join(" "))
1353
+ }
1354
+ };
1355
+ }
1356
+ });
1357
+ }
1358
+ const typeGeneratorLegacy = (0, _kubb_core.defineGenerator)({
1359
+ name: "typescript-legacy",
1360
+ schema(node, options) {
1361
+ const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group } = options;
1362
+ const { adapter, config, resolver, root } = this;
1363
+ if (!node.name) return;
1364
+ const mode = this.getMode(output);
1365
+ const imports = adapter.getImports(node, (schemaName) => ({
1366
+ name: resolver.resolveTypeName(schemaName),
1367
+ path: resolver.resolveFile({
1368
+ name: schemaName,
1369
+ extname: ".ts"
1370
+ }, {
1371
+ root,
1372
+ output,
1373
+ group
1374
+ }).path
1375
+ }));
1376
+ const isEnumSchema = !!(0, _kubb_ast.narrowSchema)(node, _kubb_ast.schemaTypes.enum);
1377
+ const meta = {
1378
+ name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(node, enumTypeSuffix) : resolver.resolveTypeName(node.name),
1379
+ file: resolver.resolveFile({
1380
+ name: node.name,
1381
+ extname: ".ts"
1382
+ }, {
1383
+ root,
1384
+ output,
1385
+ group
1386
+ })
1387
+ };
1388
+ const schemaPrinter = printerTs({
1389
+ optionalType,
1390
+ arrayType,
1391
+ enumType,
1392
+ enumTypeSuffix,
1393
+ name: meta.name,
1394
+ syntaxType,
1395
+ description: node.description,
1396
+ resolver
1397
+ });
1398
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1399
+ baseName: meta.file.baseName,
1400
+ path: meta.file.path,
1401
+ meta: meta.file.meta,
1402
+ banner: resolver.resolveBanner(adapter.rootNode, {
1403
+ output,
1404
+ config
1405
+ }),
1406
+ footer: resolver.resolveFooter(adapter.rootNode, {
1407
+ output,
1408
+ config
1409
+ }),
1410
+ children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1411
+ root: meta.file.path,
1412
+ path: imp.path,
1413
+ name: imp.name,
1414
+ isTypeOnly: true
1415
+ }, [
1416
+ node.name,
1417
+ imp.path,
1418
+ imp.isTypeOnly
1419
+ ].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Type, {
1420
+ name: meta.name,
1421
+ node,
1422
+ enumType,
1423
+ enumTypeSuffix,
1424
+ enumKeyCasing,
1425
+ resolver,
1426
+ printer: schemaPrinter
1427
+ })]
1428
+ });
1429
+ },
1430
+ operation(node, options) {
1431
+ const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output } = options;
1432
+ const { adapter, config, resolver, root } = this;
1433
+ const mode = this.getMode(output);
1434
+ const params = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
1435
+ const meta = { file: resolver.resolveFile({
1436
+ name: node.operationId,
1437
+ extname: ".ts",
1438
+ tag: node.tags[0] ?? "default",
1439
+ path: node.path
1440
+ }, {
1441
+ root,
1442
+ output,
1443
+ group
1444
+ }) };
1445
+ function renderSchemaType({ schema, name, description, keysToOmit }) {
1446
+ if (!schema) return null;
1447
+ const imports = adapter.getImports(schema, (schemaName) => ({
1448
+ name: resolver.resolveTypeName(schemaName),
1449
+ path: resolver.resolveFile({
1450
+ name: schemaName,
1451
+ extname: ".ts"
1452
+ }, {
1453
+ root,
1454
+ output,
1455
+ group
1456
+ }).path
1457
+ }));
1458
+ const opPrinter = printerTs({
1459
+ optionalType,
1460
+ arrayType,
1461
+ enumType,
1462
+ enumTypeSuffix,
1463
+ name,
1464
+ syntaxType,
1465
+ description,
1466
+ keysToOmit,
1467
+ resolver
1468
+ });
1469
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1470
+ root: meta.file.path,
1471
+ path: imp.path,
1472
+ name: imp.name,
1473
+ isTypeOnly: true
1474
+ }, [
1475
+ name,
1476
+ imp.path,
1477
+ imp.isTypeOnly
1478
+ ].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Type, {
1479
+ name,
1480
+ node: schema,
1481
+ enumType,
1482
+ enumTypeSuffix,
1483
+ enumKeyCasing,
1484
+ resolver,
1485
+ printer: opPrinter
1486
+ })] });
1487
+ }
1488
+ const pathParams = params.filter((p) => p.in === "path");
1489
+ const queryParams = params.filter((p) => p.in === "query");
1490
+ const headerParams = params.filter((p) => p.in === "header");
1491
+ const responseTypes = node.responses.map((res) => {
1492
+ const responseName = resolver.resolveResponseStatusName(node, res.statusCode);
1493
+ const baseResponseName = resolverTsLegacy.resolveResponseStatusName(node, res.statusCode);
1494
+ return renderSchemaType({
1495
+ schema: res.schema ? nameUnnamedEnums(res.schema, baseResponseName) : res.schema,
1496
+ name: responseName,
1497
+ description: res.description,
1498
+ keysToOmit: res.keysToOmit
1499
+ });
1500
+ });
1501
+ const requestType = node.requestBody?.schema ? renderSchemaType({
1502
+ schema: nameUnnamedEnums(node.requestBody.schema, resolverTsLegacy.resolveDataName(node)),
1503
+ name: resolver.resolveDataName(node),
1504
+ description: node.requestBody.description ?? node.requestBody.schema.description,
1505
+ keysToOmit: node.requestBody.keysToOmit
1506
+ }) : null;
1507
+ const legacyParamTypes = [
1508
+ pathParams.length > 0 ? renderSchemaType({
1509
+ schema: buildGroupedParamsSchema({
1510
+ params: pathParams,
1511
+ parentName: resolverTsLegacy.resolvePathParamsName(node, pathParams[0])
1512
+ }),
1513
+ name: resolver.resolvePathParamsName(node, pathParams[0])
1514
+ }) : null,
1515
+ queryParams.length > 0 ? renderSchemaType({
1516
+ schema: buildGroupedParamsSchema({
1517
+ params: queryParams,
1518
+ parentName: resolverTsLegacy.resolveQueryParamsName(node, queryParams[0])
1519
+ }),
1520
+ name: resolver.resolveQueryParamsName(node, queryParams[0])
1521
+ }) : null,
1522
+ headerParams.length > 0 ? renderSchemaType({
1523
+ schema: buildGroupedParamsSchema({
1524
+ params: headerParams,
1525
+ parentName: resolverTsLegacy.resolveHeaderParamsName(node, headerParams[0])
1526
+ }),
1527
+ name: resolver.resolveHeaderParamsName(node, headerParams[0])
1528
+ }) : null
1529
+ ];
1530
+ const legacyResponsesType = renderSchemaType({
1531
+ schema: buildLegacyResponsesSchemaNode(node, { resolver }),
1532
+ name: resolver.resolveResponsesName(node)
1533
+ });
1534
+ const legacyResponseType = renderSchemaType({
1535
+ schema: buildLegacyResponseUnionSchemaNode(node, { resolver }),
1536
+ name: resolver.resolveResponseName(node)
1537
+ });
1538
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1539
+ baseName: meta.file.baseName,
1540
+ path: meta.file.path,
1541
+ meta: meta.file.meta,
1542
+ banner: resolver.resolveBanner(adapter.rootNode, {
1543
+ output,
1544
+ config
1545
+ }),
1546
+ footer: resolver.resolveFooter(adapter.rootNode, {
1547
+ output,
1548
+ config
1549
+ }),
1550
+ children: [
1551
+ legacyParamTypes,
1552
+ responseTypes,
1553
+ requestType,
1554
+ legacyResponseType,
1555
+ legacyResponsesType
1556
+ ]
1557
+ });
1558
+ }
1559
+ });
1560
+ //#endregion
1561
+ //#region src/presets.ts
1562
+ /**
1563
+ * Built-in preset registry for `@kubb/plugin-ts`.
1564
+ *
1565
+ * - `default` — uses `resolverTs` and `typeGenerator` (current naming conventions).
1566
+ * - `kubbV4` — uses `resolverTsLegacy` and `typeGeneratorLegacy` (Kubb v4 naming conventions).
1567
+ */
1568
+ const presets = (0, _kubb_core.definePresets)({
1569
+ default: {
1570
+ name: "default",
1571
+ resolver: resolverTs,
1572
+ generators: [typeGenerator],
1573
+ printer: printerTs
1574
+ },
1575
+ kubbV4: {
1576
+ name: "kubbV4",
1577
+ resolver: resolverTsLegacy,
1578
+ generators: [typeGeneratorLegacy],
1579
+ printer: printerTs
1580
+ }
1581
+ });
1582
+ //#endregion
1583
+ //#region src/plugin.ts
1584
+ /**
1585
+ * Canonical plugin name for `@kubb/plugin-ts`, used to identify the plugin in driver lookups and warnings.
1586
+ */
1587
+ const pluginTsName = "plugin-ts";
1588
+ /**
1589
+ * The `@kubb/plugin-ts` plugin factory.
1590
+ *
1591
+ * Generates TypeScript type declarations from an OpenAPI/AST `RootNode`.
1592
+ * Walks schemas and operations, delegates rendering to the active generators,
1593
+ * and writes barrel files based on `output.barrelType`.
1594
+ *
1595
+ * @example
1596
+ * ```ts
1597
+ * import { pluginTs } from '@kubb/plugin-ts'
1598
+ *
1599
+ * export default defineConfig({
1600
+ * plugins: [pluginTs({ output: { path: 'types' }, enumType: 'asConst' })],
1601
+ * })
1602
+ * ```
1603
+ */
1604
+ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
1605
+ const { output = {
1606
+ path: "types",
1607
+ barrelType: "named"
1608
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumTypeSuffix = "Key", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", paramsCasing, printer, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
1609
+ const preset = (0, _kubb_core.getPreset)({
1610
+ preset: compatibilityPreset,
1611
+ presets,
1612
+ resolver: userResolver,
1613
+ transformer: userTransformer,
1614
+ generators: userGenerators
1615
+ });
1616
+ const mergedGenerator = (0, _kubb_core.mergeGenerators)(preset.generators ?? []);
1617
+ let resolveNameWarning = false;
1618
+ let resolvePathWarning = false;
1619
+ return {
1620
+ name: pluginTsName,
1621
+ version,
1622
+ get resolver() {
1623
+ return preset.resolver;
1624
+ },
1625
+ get transformer() {
1626
+ return preset.transformer;
1627
+ },
1628
+ get options() {
1629
+ return {
1630
+ output,
1631
+ exclude,
1632
+ include,
1633
+ override,
1634
+ optionalType,
1635
+ group: group ? {
1636
+ ...group,
1637
+ name: (ctx) => {
1638
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1639
+ return `${camelCase(ctx.group)}Controller`;
1640
+ }
1641
+ } : void 0,
1642
+ arrayType,
1643
+ enumType,
1644
+ enumTypeSuffix,
1645
+ enumKeyCasing,
1646
+ syntaxType,
1647
+ paramsCasing,
1648
+ printer
1649
+ };
1650
+ },
1651
+ resolvePath(baseName, pathMode, options) {
1652
+ if (!resolvePathWarning) {
1653
+ this.warn("Do not use resolvePath for pluginTs, use resolverTs.resolvePath instead");
1654
+ resolvePathWarning = true;
1655
+ }
1656
+ return this.plugin.resolver.resolvePath({
1657
+ baseName,
1658
+ pathMode,
1659
+ tag: options?.group?.tag,
1660
+ path: options?.group?.path
1661
+ }, {
1662
+ root: this.root,
1663
+ output,
1664
+ group: this.plugin.options.group
1665
+ });
1666
+ },
1667
+ resolveName(name, type) {
1668
+ if (!resolveNameWarning) {
1669
+ this.warn("Do not use resolveName for pluginTs, use resolverTs.default instead");
1670
+ resolveNameWarning = true;
1671
+ }
1672
+ return this.plugin.resolver.default(name, type);
1673
+ },
1674
+ async schema(node, options) {
1675
+ return mergedGenerator.schema?.call(this, node, options);
1676
+ },
1677
+ async operation(node, options) {
1678
+ return mergedGenerator.operation?.call(this, node, options);
1679
+ },
1680
+ async operations(nodes, options) {
1681
+ return mergedGenerator.operations?.call(this, nodes, options);
1682
+ },
1683
+ async buildStart() {
1684
+ await this.openInStudio({ ast: true });
1685
+ }
1686
+ };
1687
+ });
1688
+ //#endregion
1689
+ //#region src/printers/functionPrinter.ts
1690
+ const kindToHandlerKey = {
1691
+ FunctionParameter: "functionParameter",
1692
+ ParameterGroup: "parameterGroup",
1693
+ FunctionParameters: "functionParameters",
1694
+ Type: "type"
1695
+ };
1696
+ /**
1697
+ * Creates a function-parameter printer factory.
1698
+ *
1699
+ * Uses `createPrinterFactory` and dispatches handlers by `node.kind`
1700
+ * (for function nodes) rather than by `node.type` (for schema nodes).
1701
+ */
1702
+ const defineFunctionPrinter = (0, _kubb_ast.createPrinterFactory)((node) => kindToHandlerKey[node.kind]);
1703
+ function rank(param) {
1704
+ if (param.kind === "ParameterGroup") {
1705
+ if (param.default) return PARAM_RANK.withDefault;
1706
+ return param.optional ?? param.properties.every((p) => p.optional || p.default !== void 0) ? PARAM_RANK.optional : PARAM_RANK.required;
1707
+ }
1708
+ if (param.rest) return PARAM_RANK.rest;
1709
+ if (param.default) return PARAM_RANK.withDefault;
1710
+ return param.optional ? PARAM_RANK.optional : PARAM_RANK.required;
1711
+ }
1712
+ function sortParams(params) {
1713
+ return [...params].sort((a, b) => rank(a) - rank(b));
1714
+ }
1715
+ function sortChildParams(params) {
1716
+ return [...params].sort((a, b) => rank(a) - rank(b));
1717
+ }
1718
+ /**
1719
+ * Default function-signature printer.
1720
+ * Covers the four standard output modes used across Kubb plugins.
1721
+ *
1722
+ * @example
1723
+ * ```ts
1724
+ * const printer = functionPrinter({ mode: 'declaration' })
1725
+ *
1726
+ * const sig = createFunctionParameters({
1727
+ * params: [
1728
+ * createFunctionParameter({ name: 'petId', type: 'string', optional: false }),
1729
+ * createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),
1730
+ * ],
1731
+ * })
1732
+ *
1733
+ * printer.print(sig) // → "petId: string, config: Config = {}"
1734
+ * ```
1735
+ */
1736
+ const functionPrinter = defineFunctionPrinter((options) => ({
1737
+ name: "functionParameters",
1738
+ options,
1739
+ nodes: {
1740
+ type(node) {
1741
+ if (node.variant === "member") return `${node.base}['${node.key}']`;
1742
+ if (node.variant === "struct") return `{ ${node.properties.map((p) => {
1743
+ const typeStr = this.transform(p.type);
1744
+ const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
1745
+ return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
1746
+ }).join("; ")} }`;
1747
+ if (node.variant === "reference") return node.name;
1748
+ return null;
1749
+ },
1750
+ functionParameter(node) {
1751
+ const { mode, transformName, transformType } = this.options;
1752
+ const name = transformName ? transformName(node.name) : node.name;
1753
+ const rawType = node.type ? this.transform(node.type) : void 0;
1754
+ const type = rawType != null && transformType ? transformType(rawType) : rawType;
1755
+ if (mode === "keys" || mode === "values") return node.rest ? `...${name}` : name;
1756
+ if (mode === "call") return node.rest ? `...${name}` : name;
1757
+ if (node.rest) return type ? `...${name}: ${type}` : `...${name}`;
1758
+ if (type) {
1759
+ if (node.optional) return `${name}?: ${type}`;
1760
+ return node.default ? `${name}: ${type} = ${node.default}` : `${name}: ${type}`;
1761
+ }
1762
+ return node.default ? `${name} = ${node.default}` : name;
1763
+ },
1764
+ parameterGroup(node) {
1765
+ const { mode, transformName, transformType } = this.options;
1766
+ const sorted = sortChildParams(node.properties);
1767
+ const isOptional = node.optional ?? sorted.every((p) => p.optional || p.default !== void 0);
1768
+ if (node.inline) return sorted.map((p) => this.transform(p)).filter(Boolean).join(", ");
1769
+ if (mode === "keys" || mode === "values") return `{ ${sorted.map((p) => p.name).join(", ")} }`;
1770
+ if (mode === "call") return `{ ${sorted.map((p) => p.name).join(", ")} }`;
1771
+ const names = sorted.map((p) => {
1772
+ return transformName ? transformName(p.name) : p.name;
1773
+ });
1774
+ const nameStr = names.length ? `{ ${names.join(", ")} }` : void 0;
1775
+ if (!nameStr) return null;
1776
+ let typeAnnotation = node.type ? this.transform(node.type) ?? void 0 : void 0;
1777
+ if (!typeAnnotation) {
1778
+ const typeParts = sorted.filter((p) => p.type).map((p) => {
1779
+ const rawT = p.type ? this.transform(p.type) : void 0;
1780
+ const t = rawT != null && transformType ? transformType(rawT) : rawT;
1781
+ return p.optional || p.default !== void 0 ? `${p.name}?: ${t}` : `${p.name}: ${t}`;
1782
+ });
1783
+ typeAnnotation = typeParts.length ? `{ ${typeParts.join("; ")} }` : void 0;
1784
+ }
1785
+ if (typeAnnotation) {
1786
+ if (isOptional) return `${nameStr}: ${typeAnnotation} = ${node.default ?? "{}"}`;
1787
+ return node.default ? `${nameStr}: ${typeAnnotation} = ${node.default}` : `${nameStr}: ${typeAnnotation}`;
1788
+ }
1789
+ return node.default ? `${nameStr} = ${node.default}` : nameStr;
1790
+ },
1791
+ functionParameters(node) {
1792
+ return sortParams(node.params).map((p) => this.transform(p)).filter(Boolean).join(", ");
1793
+ }
1794
+ }
1795
+ }));
1796
+ //#endregion
1797
+ exports.Enum = Enum;
1798
+ exports.Type = Type;
1799
+ exports.functionPrinter = functionPrinter;
1800
+ exports.pluginTs = pluginTs;
1801
+ exports.pluginTsName = pluginTsName;
1802
+ exports.printerTs = printerTs;
1803
+ exports.resolverTs = resolverTs;
1804
+ exports.resolverTsLegacy = resolverTsLegacy;
1805
+ exports.typeGenerator = typeGenerator;
1806
+
1807
+ //# sourceMappingURL=index.cjs.map