@kubb/ast 5.0.0-alpha.7 → 5.0.0-alpha.71

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.d.ts CHANGED
@@ -1,55 +1,3443 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { D as OperationNode, J as SchemaNodeByType, N as ParameterNode, O as ResponseNode, S as createSchema, T as RootNode, _ as createOperation, a as transform, at as httpMethods, b as createResponse, c as buildRefMap, ct as schemaTypes, h as definePrinter, i as collect, l as refMapToObject, o as walk, ot as mediaTypes, q as SchemaNode, st as nodeKinds, tt as PropertyNode, u as resolveRef, v as createParameter, x as createRoot, y as createProperty } from "./visitor-DagMPgGo.js";
3
2
 
3
+ //#region src/constants.d.ts
4
+ /**
5
+ * Traversal depth used by AST visitor utilities.
6
+ */
7
+ type VisitorDepth = 'shallow' | 'deep';
8
+ declare const nodeKinds: {
9
+ readonly input: "Input";
10
+ readonly output: "Output";
11
+ readonly operation: "Operation";
12
+ readonly schema: "Schema";
13
+ readonly property: "Property";
14
+ readonly parameter: "Parameter";
15
+ readonly response: "Response";
16
+ readonly functionParameter: "FunctionParameter";
17
+ readonly parameterGroup: "ParameterGroup";
18
+ readonly functionParameters: "FunctionParameters";
19
+ readonly type: "Type";
20
+ readonly file: "File";
21
+ readonly import: "Import";
22
+ readonly export: "Export";
23
+ readonly source: "Source";
24
+ readonly text: "Text";
25
+ readonly break: "Break";
26
+ };
27
+ /**
28
+ * Canonical schema type strings used by AST schema nodes.
29
+ *
30
+ * These values are used across the AST as stable discriminators
31
+ * (for example `schema.type === schemaTypes.object`).
32
+ *
33
+ * The map is grouped by intent:
34
+ * - primitives (`string`, `number`, `boolean`, ...)
35
+ * - structural/composite (`object`, `array`, `union`, ...)
36
+ * - special OpenAPI-oriented types (`ref`, `datetime`, `uuid`, ...)
37
+ */
38
+ declare const schemaTypes: {
39
+ /**
40
+ * Text value.
41
+ */
42
+ readonly string: "string";
43
+ /**
44
+ * Floating-point number (`float`, `double`).
45
+ */
46
+ readonly number: "number";
47
+ /**
48
+ * Whole number (`int32`). Use `bigint` for `int64`.
49
+ */
50
+ readonly integer: "integer";
51
+ /**
52
+ * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
53
+ */
54
+ readonly bigint: "bigint";
55
+ /**
56
+ * Boolean value
57
+ */
58
+ readonly boolean: "boolean";
59
+ /**
60
+ * Explicit null value.
61
+ */
62
+ readonly null: "null";
63
+ /**
64
+ * Any value (no type restriction).
65
+ */
66
+ readonly any: "any";
67
+ /**
68
+ * Unknown value (must be narrowed before usage).
69
+ */
70
+ readonly unknown: "unknown";
71
+ /**
72
+ * No return value (`void`).
73
+ */
74
+ readonly void: "void";
75
+ /**
76
+ * Object with named properties.
77
+ */
78
+ readonly object: "object";
79
+ /**
80
+ * Sequential list of items.
81
+ */
82
+ readonly array: "array";
83
+ /**
84
+ * Fixed-length list with position-specific items.
85
+ */
86
+ readonly tuple: "tuple";
87
+ /**
88
+ * "One of" multiple schema members.
89
+ */
90
+ readonly union: "union";
91
+ /**
92
+ * "All of" multiple schema members.
93
+ */
94
+ readonly intersection: "intersection";
95
+ /**
96
+ * Enum schema.
97
+ */
98
+ readonly enum: "enum";
99
+ /**
100
+ * Reference to another schema.
101
+ */
102
+ readonly ref: "ref";
103
+ /**
104
+ * Calendar date (for example `2026-03-24`).
105
+ */
106
+ readonly date: "date";
107
+ /**
108
+ * Date-time value (for example `2026-03-24T09:00:00Z`).
109
+ */
110
+ readonly datetime: "datetime";
111
+ /**
112
+ * Time-only value (for example `09:00:00`).
113
+ */
114
+ readonly time: "time";
115
+ /**
116
+ * UUID value.
117
+ */
118
+ readonly uuid: "uuid";
119
+ /**
120
+ * Email address value.
121
+ */
122
+ readonly email: "email";
123
+ /**
124
+ * URL value.
125
+ */
126
+ readonly url: "url";
127
+ /**
128
+ * IPv4 address value.
129
+ */
130
+ readonly ipv4: "ipv4";
131
+ /**
132
+ * IPv6 address value.
133
+ */
134
+ readonly ipv6: "ipv6";
135
+ /**
136
+ * Binary/blob value.
137
+ */
138
+ readonly blob: "blob";
139
+ /**
140
+ * Impossible value (`never`).
141
+ */
142
+ readonly never: "never";
143
+ };
144
+ type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean';
145
+ /**
146
+ * Returns `true` when `type` is a scalar primitive schema type.
147
+ */
148
+ declare function isScalarPrimitive(type: string): type is ScalarPrimitive;
149
+ declare const httpMethods: {
150
+ readonly get: "GET";
151
+ readonly post: "POST";
152
+ readonly put: "PUT";
153
+ readonly patch: "PATCH";
154
+ readonly delete: "DELETE";
155
+ readonly head: "HEAD";
156
+ readonly options: "OPTIONS";
157
+ readonly trace: "TRACE";
158
+ };
159
+ declare const mediaTypes: {
160
+ readonly applicationJson: "application/json";
161
+ readonly applicationXml: "application/xml";
162
+ readonly applicationFormUrlEncoded: "application/x-www-form-urlencoded";
163
+ readonly applicationOctetStream: "application/octet-stream";
164
+ readonly applicationPdf: "application/pdf";
165
+ readonly applicationZip: "application/zip";
166
+ readonly applicationGraphql: "application/graphql";
167
+ readonly multipartFormData: "multipart/form-data";
168
+ readonly textPlain: "text/plain";
169
+ readonly textHtml: "text/html";
170
+ readonly textCsv: "text/csv";
171
+ readonly textXml: "text/xml";
172
+ readonly imagePng: "image/png";
173
+ readonly imageJpeg: "image/jpeg";
174
+ readonly imageGif: "image/gif";
175
+ readonly imageWebp: "image/webp";
176
+ readonly imageSvgXml: "image/svg+xml";
177
+ readonly audioMpeg: "audio/mpeg";
178
+ readonly videoMp4: "video/mp4";
179
+ };
180
+ //#endregion
181
+ //#region src/nodes/base.d.ts
182
+ /**
183
+ * `kind` values used by AST nodes.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const kind: NodeKind = 'Schema'
188
+ * ```
189
+ */
190
+ type NodeKind = 'Input' | 'Output' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'FunctionParameter' | 'ParameterGroup' | 'FunctionParameters' | 'Type' | 'ParamsType' | 'File' | 'Import' | 'Export' | 'Source' | 'Const' | 'Function' | 'ArrowFunction' | 'Text' | 'Break' | 'Jsx';
191
+ /**
192
+ * Base shape shared by all AST nodes.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * const base: BaseNode = { kind: 'Input' }
197
+ * ```
198
+ */
199
+ type BaseNode = {
200
+ /**
201
+ * Node discriminator.
202
+ */
203
+ kind: NodeKind;
204
+ };
205
+ //#endregion
206
+ //#region src/nodes/code.d.ts
207
+ /**
208
+ * JSDoc documentation metadata attached to code declarations.
209
+ */
210
+ type JSDocNode = {
211
+ /**
212
+ * JSDoc comment lines. `undefined` entries are filtered out during rendering.
213
+ * @example ['@description A pet resource', '@deprecated']
214
+ */
215
+ comments?: Array<string | undefined>;
216
+ };
217
+ /**
218
+ * AST node representing a TypeScript `const` declaration.
219
+ *
220
+ * Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
221
+ * The `children` prop of the component is represented as `nodes`.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * createConst({ name: 'pet', export: true, asConst: true })
226
+ * // export const pet = ... as const
227
+ * ```
228
+ */
229
+ type ConstNode = BaseNode & {
230
+ /**
231
+ * Node kind.
232
+ */
233
+ kind: 'Const';
234
+ /**
235
+ * Name of the constant declaration.
236
+ */
237
+ name: string;
238
+ /**
239
+ * Whether the declaration should be exported.
240
+ * @default false
241
+ */
242
+ export?: boolean;
243
+ /**
244
+ * Optional explicit type annotation.
245
+ * @example 'Pet'
246
+ */
247
+ type?: string;
248
+ /**
249
+ * JSDoc documentation metadata.
250
+ */
251
+ JSDoc?: JSDocNode;
252
+ /**
253
+ * Whether to append `as const` to the declaration.
254
+ * @default false
255
+ */
256
+ asConst?: boolean;
257
+ /**
258
+ * Child nodes representing the value of the constant (children of the `Const` component).
259
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
260
+ */
261
+ nodes?: Array<CodeNode>;
262
+ };
263
+ /**
264
+ * AST node representing a TypeScript `type` alias declaration.
265
+ *
266
+ * Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
267
+ * The `children` prop of the component is represented as `nodes`.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * createType({ name: 'Pet', export: true })
272
+ * // export type Pet = ...
273
+ * ```
274
+ */
275
+ type TypeNode = BaseNode & {
276
+ /**
277
+ * Node kind.
278
+ */
279
+ kind: 'Type';
280
+ /**
281
+ * Name of the type alias.
282
+ */
283
+ name: string;
284
+ /**
285
+ * Whether the declaration should be exported.
286
+ * @default false
287
+ */
288
+ export?: boolean;
289
+ /**
290
+ * JSDoc documentation metadata.
291
+ */
292
+ JSDoc?: JSDocNode;
293
+ /**
294
+ * Child nodes representing the type body (children of the `Type` component).
295
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
296
+ */
297
+ nodes?: Array<CodeNode>;
298
+ };
299
+ /**
300
+ * Convenience alias for {@link TypeNode}.
301
+ * @deprecated Use `TypeNode` directly.
302
+ */
303
+ type TypeDeclarationNode = TypeNode;
304
+ /**
305
+ * AST node representing a TypeScript `function` declaration.
306
+ *
307
+ * Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
308
+ * The `children` prop of the component is represented as `nodes`.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * createFunctionDeclaration({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
313
+ * // export async function getPet(): Promise<Pet> { ... }
314
+ * ```
315
+ */
316
+ type FunctionNode = BaseNode & {
317
+ /**
318
+ * Node kind.
319
+ */
320
+ kind: 'Function';
321
+ /**
322
+ * Name of the function.
323
+ */
324
+ name: string;
325
+ /**
326
+ * Whether the function is a default export.
327
+ * @default false
328
+ */
329
+ default?: boolean;
330
+ /**
331
+ * Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).
332
+ */
333
+ params?: string;
334
+ /**
335
+ * Whether the function should be exported.
336
+ * @default false
337
+ */
338
+ export?: boolean;
339
+ /**
340
+ * Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
341
+ * @default false
342
+ */
343
+ async?: boolean;
344
+ /**
345
+ * TypeScript generic type parameters.
346
+ * @example ['T', 'U extends string']
347
+ */
348
+ generics?: string | string[];
349
+ /**
350
+ * Return type annotation.
351
+ * @example 'Pet'
352
+ */
353
+ returnType?: string;
354
+ /**
355
+ * JSDoc documentation metadata.
356
+ */
357
+ JSDoc?: JSDocNode;
358
+ /**
359
+ * Child nodes representing the function body (children of the `Function` component).
360
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
361
+ */
362
+ nodes?: Array<CodeNode>;
363
+ };
364
+ /**
365
+ * AST node representing a TypeScript arrow function (`const name = () => { ... }`).
366
+ *
367
+ * Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
368
+ * The `children` prop of the component is represented as `nodes`.
369
+ *
370
+ * @example
371
+ * ```ts
372
+ * createArrowFunctionDeclaration({ name: 'getPet', export: true, singleLine: true })
373
+ * // export const getPet = () => ...
374
+ * ```
375
+ */
376
+ type ArrowFunctionNode = BaseNode & {
377
+ /**
378
+ * Node kind.
379
+ */
380
+ kind: 'ArrowFunction';
381
+ /**
382
+ * Name of the arrow function (used as the `const` variable name).
383
+ */
384
+ name: string;
385
+ /**
386
+ * Whether the function is a default export.
387
+ * @default false
388
+ */
389
+ default?: boolean;
390
+ /**
391
+ * Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).
392
+ */
393
+ params?: string;
394
+ /**
395
+ * Whether the arrow function should be exported.
396
+ * @default false
397
+ */
398
+ export?: boolean;
399
+ /**
400
+ * Whether the arrow function is async. When `true`, the return type is wrapped in `Promise<>`.
401
+ * @default false
402
+ */
403
+ async?: boolean;
404
+ /**
405
+ * TypeScript generic type parameters.
406
+ * @example ['T', 'U extends string']
407
+ */
408
+ generics?: string | string[];
409
+ /**
410
+ * Return type annotation.
411
+ * @example 'Pet'
412
+ */
413
+ returnType?: string;
414
+ /**
415
+ * JSDoc documentation metadata.
416
+ */
417
+ JSDoc?: JSDocNode;
418
+ /**
419
+ * Render the arrow function body as a single-line expression.
420
+ * @default false
421
+ */
422
+ singleLine?: boolean;
423
+ /**
424
+ * Child nodes representing the function body (children of the `Function.Arrow` component).
425
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
426
+ */
427
+ nodes?: Array<CodeNode>;
428
+ };
429
+ /**
430
+ * AST node representing a raw text/string fragment in the source output.
431
+ *
432
+ * Used instead of bare `string` values so that all entries in `nodes` arrays
433
+ * are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
434
+ *
435
+ * @example
436
+ * ```ts
437
+ * createText('return fetch(id)')
438
+ * // { kind: 'Text', value: 'return fetch(id)' }
439
+ * ```
440
+ */
441
+ type TextNode = BaseNode & {
442
+ /**
443
+ * Node kind.
444
+ */
445
+ kind: 'Text';
446
+ /**
447
+ * The raw string content.
448
+ */
449
+ value: string;
450
+ };
451
+ /**
452
+ * AST node representing a line break in the source output.
453
+ *
454
+ * Corresponds to `<br/>` in JSX components. When printed, produces an empty
455
+ * string that — joined with `\n` by `printNodes` — creates a blank line
456
+ * between surrounding code nodes.
457
+ *
458
+ * @example
459
+ * ```ts
460
+ * createBreak()
461
+ * // { kind: 'Break' }
462
+ * // prints as '' → blank line when surrounded by other nodes
463
+ * ```
464
+ */
465
+ type BreakNode = BaseNode & {
466
+ /**
467
+ * Node kind.
468
+ */
469
+ kind: 'Break';
470
+ };
471
+ /**
472
+ * AST node representing a raw JSX fragment in the source output.
473
+ *
474
+ * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Use this to embed raw
475
+ * JSX/TSX markup (including fragments `<>…</>`) directly in generated code.
476
+ *
477
+ * @example
478
+ * ```ts
479
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
480
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
481
+ * ```
482
+ */
483
+ type JsxNode = BaseNode & {
484
+ /**
485
+ * Node kind.
486
+ */
487
+ kind: 'Jsx';
488
+ /**
489
+ * The raw JSX string content.
490
+ */
491
+ value: string;
492
+ };
493
+ /**
494
+ * Union of all code-generation AST nodes.
495
+ *
496
+ * These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
497
+ * structured children in {@link SourceNode.nodes}.
498
+ */
499
+ type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
500
+ //#endregion
501
+ //#region src/nodes/file.d.ts
502
+ /**
503
+ * Supported file extensions.
504
+ */
505
+ type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
506
+ type ImportName = string | Array<string | {
507
+ propertyName: string;
508
+ name?: string;
509
+ }>;
510
+ /**
511
+ * Represents a language-agnostic import/dependency declaration.
512
+ *
513
+ * @example Named import (TypeScript: `import { useState } from 'react'`)
514
+ * ```ts
515
+ * createImport({ name: ['useState'], path: 'react' })
516
+ * ```
517
+ *
518
+ * @example Default import (TypeScript: `import React from 'react'`)
519
+ * ```ts
520
+ * createImport({ name: 'React', path: 'react' })
521
+ * ```
522
+ *
523
+ * @example Type-only import (TypeScript: `import type { FC } from 'react'`)
524
+ * ```ts
525
+ * createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
526
+ * ```
527
+ *
528
+ * @example Namespace import (TypeScript: `import * as React from 'react'`)
529
+ * ```ts
530
+ * createImport({ name: 'React', path: 'react', isNameSpace: true })
531
+ * ```
532
+ */
533
+ type ImportNode = BaseNode & {
534
+ kind: 'Import';
535
+ /**
536
+ * Import name(s) to be used.
537
+ * @example ['useState']
538
+ * @example 'React'
539
+ */
540
+ name: ImportName;
541
+ /**
542
+ * Path for the import.
543
+ * @example '@kubb/core'
544
+ */
545
+ path: string;
546
+ /**
547
+ * Add type-only import prefix.
548
+ * - `true` generates `import type { Type } from './path'`
549
+ * - `false` generates `import { Type } from './path'`
550
+ * @default false
551
+ */
552
+ isTypeOnly?: boolean;
553
+ /**
554
+ * Import entire module as namespace.
555
+ * - `true` generates `import * as Name from './path'`
556
+ * - `false` generates standard import
557
+ * @default false
558
+ */
559
+ isNameSpace?: boolean;
560
+ /**
561
+ * When set, the import path is resolved relative to this root.
562
+ */
563
+ root?: string;
564
+ };
565
+ /**
566
+ * Represents a language-agnostic export/public API declaration.
567
+ *
568
+ * @example Named export (TypeScript: `export { Pets } from './Pets'`)
569
+ * ```ts
570
+ * createExport({ name: ['Pets'], path: './Pets' })
571
+ * ```
572
+ *
573
+ * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
574
+ * ```ts
575
+ * createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
576
+ * ```
577
+ *
578
+ * @example Wildcard export (TypeScript: `export * from './utils'`)
579
+ * ```ts
580
+ * createExport({ path: './utils' })
581
+ * ```
582
+ *
583
+ * @example Namespace alias (TypeScript: `export * as utils from './utils'`)
584
+ * ```ts
585
+ * createExport({ name: 'utils', path: './utils', asAlias: true })
586
+ * ```
587
+ */
588
+ type ExportNode = BaseNode & {
589
+ kind: 'Export';
590
+ /**
591
+ * Export name(s) to be used. When omitted, generates a wildcard export.
592
+ * @example ['useState']
593
+ * @example 'React'
594
+ */
595
+ name?: string | Array<string>;
596
+ /**
597
+ * Path for the export.
598
+ * @example '@kubb/core'
599
+ */
600
+ path: string;
601
+ /**
602
+ * Add type-only export prefix.
603
+ * - `true` generates `export type { Type } from './path'`
604
+ * - `false` generates `export { Type } from './path'`
605
+ * @default false
606
+ */
607
+ isTypeOnly?: boolean;
608
+ /**
609
+ * Export as an aliased namespace.
610
+ * - `true` generates `export * as aliasName from './path'`
611
+ * - `false` generates a standard export
612
+ * @default false
613
+ */
614
+ asAlias?: boolean;
615
+ };
616
+ /**
617
+ * Represents a fragment of source code within a file.
618
+ *
619
+ * @example Named exportable source
620
+ * ```ts
621
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
622
+ * ```
623
+ *
624
+ * @example Inline unnamed code block
625
+ * ```ts
626
+ * createSource({ nodes: [createText('const x = 1')] })
627
+ * ```
628
+ */
629
+ type SourceNode = BaseNode & {
630
+ kind: 'Source';
631
+ /**
632
+ * Optional name identifying this source (used for deduplication and barrel generation).
633
+ */
634
+ name?: string;
635
+ /**
636
+ * Mark this source as a type-only export.
637
+ * @default false
638
+ */
639
+ isTypeOnly?: boolean;
640
+ /**
641
+ * Include `export` keyword in the generated source.
642
+ * @default false
643
+ */
644
+ isExportable?: boolean;
645
+ /**
646
+ * Include this source in barrel/index file generation.
647
+ * @default false
648
+ */
649
+ isIndexable?: boolean;
650
+ /**
651
+ * Structured child nodes representing the content of this source fragment, in DOM order.
652
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
653
+ */
654
+ nodes?: Array<CodeNode>;
655
+ };
656
+ /**
657
+ * Represents a fully resolved file in the AST.
658
+ *
659
+ * Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input
660
+ * and deduplicates `imports`, `exports`, and `sources`.
661
+ *
662
+ * @example
663
+ * ```ts
664
+ * const file = createFile({
665
+ * baseName: 'petStore.ts',
666
+ * path: 'src/models/petStore.ts',
667
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],
668
+ * imports: [createImport({ name: ['z'], path: 'zod' })],
669
+ * exports: [createExport({ name: ['Pet'], path: './petStore' })],
670
+ * })
671
+ * // file.id = SHA256 hash of the path
672
+ * // file.name = 'petStore'
673
+ * // file.extname = '.ts'
674
+ * ```
675
+ */
676
+ type FileNode<TMeta extends object = object> = BaseNode & {
677
+ kind: 'File';
678
+ /**
679
+ * Unique identifier derived from a SHA256 hash of the file path.
680
+ * @default hash
681
+ */
682
+ id: string;
683
+ /**
684
+ * File name without extension, derived from `baseName`.
685
+ * @link https://nodejs.org/api/path.html#pathformatpathobject
686
+ */
687
+ name: string;
688
+ /**
689
+ * File base name, including extension.
690
+ * Based on UNIX basename: `${name}${extname}`
691
+ * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
692
+ */
693
+ baseName: `${string}.${string}`;
694
+ /**
695
+ * Full qualified path to the file.
696
+ */
697
+ path: string;
698
+ /**
699
+ * File extension extracted from `baseName`.
700
+ */
701
+ extname: Extname;
702
+ /**
703
+ * Deduplicated list of source code fragments.
704
+ */
705
+ sources: Array<SourceNode>;
706
+ /**
707
+ * Deduplicated list of import declarations.
708
+ */
709
+ imports: Array<ImportNode>;
710
+ /**
711
+ * Deduplicated list of export declarations.
712
+ */
713
+ exports: Array<ExportNode>;
714
+ /**
715
+ * Optional metadata attached to this file (used by plugins for barrel generation etc.).
716
+ */
717
+ meta?: TMeta;
718
+ /**
719
+ * Optional banner prepended to the generated file content.
720
+ */
721
+ banner?: string;
722
+ /**
723
+ * Optional footer appended to the generated file content.
724
+ */
725
+ footer?: string;
726
+ };
727
+ //#endregion
728
+ //#region src/nodes/function.d.ts
729
+ /**
730
+ * AST node representing a language-agnostic type expression used as a function parameter
731
+ * type annotation. Each language printer renders the variant into its own syntax.
732
+ *
733
+ * - `struct` — an inline anonymous type grouping named fields.
734
+ * TypeScript renders as `{ petId: string; name?: string }`.
735
+ * - `member` — a single named field accessed from a named group type.
736
+ * TypeScript renders as `PathParams['petId']`.
737
+ *
738
+ * @example Reference variant
739
+ * ```ts
740
+ * createParamsType({ variant: 'reference', name: 'QueryParams' })
741
+ * // QueryParams
742
+ * ```
743
+ *
744
+ * @example Struct variant
745
+ * ```ts
746
+ * createParamsType({ variant: 'struct', properties: [{ name: 'petId', optional: false, type: createParamsType({ variant: 'reference', name: 'string' }) }] })
747
+ * // { petId: string }
748
+ * ```
749
+ *
750
+ * @example Member variant
751
+ * ```ts
752
+ * createParamsType({ variant: 'member', base: 'PathParams', key: 'petId' })
753
+ * // PathParams['petId']
754
+ * ```
755
+ */
756
+ type ParamsTypeNode = BaseNode & {
757
+ /**
758
+ * Node kind.
759
+ */
760
+ kind: 'ParamsType';
761
+ } & ({
762
+ /**
763
+ * Reference variant — a plain type name or identifier.
764
+ * TypeScript renders as-is, e.g. `string`, `QueryParams`, `Partial<Config>`.
765
+ */
766
+ variant: 'reference';
767
+ /**
768
+ * The full type name string, e.g. `'string'`, `'QueryParams'`, `'Partial<Config>'`.
769
+ */
770
+ name: string;
771
+ } | {
772
+ /**
773
+ * Struct variant — an inline anonymous type grouping named fields.
774
+ * TypeScript renders as `{ key: Type; other?: OtherType }`.
775
+ */
776
+ variant: 'struct';
777
+ /**
778
+ * Properties of the struct type.
779
+ */
780
+ properties: Array<{
781
+ name: string;
782
+ optional: boolean;
783
+ type: ParamsTypeNode;
784
+ }>;
785
+ } | {
786
+ /**
787
+ * Member variant — a single named field accessed from a group type.
788
+ * TypeScript renders as `Base['key']`.
789
+ */
790
+ variant: 'member';
791
+ /**
792
+ * Base type name, e.g. `'DeletePetPathParams'`.
793
+ */
794
+ base: string;
795
+ /**
796
+ * The field name to access, e.g. `'petId'`.
797
+ */
798
+ key: string;
799
+ });
800
+ /**
801
+ * AST node for one function parameter.
802
+ *
803
+ * @example Required parameter
804
+ * `name: Type`
805
+ *
806
+ * @example Optional parameter
807
+ * `name?: Type`
808
+ *
809
+ * @example Parameter with default value
810
+ * `name: Type = defaultValue`
811
+ *
812
+ * @example Rest parameter
813
+ * `...name: Type[]`
814
+ */
815
+ type FunctionParameterNode = BaseNode & {
816
+ /**
817
+ * Node kind.
818
+ */
819
+ kind: 'FunctionParameter';
820
+ /**
821
+ * Parameter name in the generated signature.
822
+ */
823
+ name: string;
824
+ /**
825
+ * Type annotation as a structured {@link ParamsTypeNode}.
826
+ * Omit for untyped output.
827
+ *
828
+ * @example Reference type node
829
+ * `{ kind: 'ParamsType', variant: 'reference', name: 'string' }` → `petId: string`
830
+ *
831
+ * @example Struct type node
832
+ * `{ kind: 'ParamsType', variant: 'struct', properties: [...] }` → `{ key: Type; other?: OtherType }`
833
+ *
834
+ * @example Member type node
835
+ * `{ kind: 'ParamsType', variant: 'member', base: 'PathParams', key: 'petId' }` → `PathParams['petId']`
836
+ */
837
+ type?: ParamsTypeNode;
838
+ /**
839
+ * When `true` the parameter is emitted as a rest parameter.
840
+ *
841
+ * @example Rest parameter
842
+ * `...name: Type[]`
843
+ */
844
+ rest?: boolean;
845
+ }
846
+ /**
847
+ * Optional parameter — rendered with `?` and may be omitted by the caller.
848
+ * Cannot be combined with `default` because a defaulted parameter is already optional.
849
+ */
850
+ & ({
851
+ optional: true;
852
+ default?: never;
853
+ }
854
+ /**
855
+ * Required parameter, or a parameter with a default value.
856
+ *
857
+ * @example Required
858
+ * `name: Type`
859
+ *
860
+ * @example With default
861
+ * `name: Type = default`
862
+ */
863
+ | {
864
+ optional?: false;
865
+ default?: string;
866
+ });
867
+ /**
868
+ * AST node for a group of related function parameters treated as a single unit.
869
+ *
870
+ * Each language printer decides how to render this group:
871
+ * - TypeScript/JS: destructured object `{ key1, key2 }: { key1: Type1; key2: Type2 } = {}`
872
+ * - Python: keyword-only args or a typed dict parameter
873
+ * - C# / Kotlin: named record / data-class parameter
874
+ *
875
+ * When `inline` is `true`, the group is spread as individual top-level parameters
876
+ * rather than wrapped in a single grouped construct.
877
+ *
878
+ * @example Grouped destructuring
879
+ * `{ id, name }: { id: string; name: string } = {}`
880
+ *
881
+ * @example Inline (spread as individual parameters)
882
+ * `id: string, name: string`
883
+ */
884
+ type ParameterGroupNode = BaseNode & {
885
+ /**
886
+ * Node kind.
887
+ */
888
+ kind: 'ParameterGroup';
889
+ /**
890
+ * The individual parameters that form the group.
891
+ * Rendered as a destructured object or spread inline when `inline` is `true`.
892
+ */
893
+ properties: Array<FunctionParameterNode>;
894
+ /**
895
+ * Optional explicit type annotation for the whole group.
896
+ * When absent, printers auto-compute it from `properties`.
897
+ */
898
+ type?: ParamsTypeNode;
899
+ /**
900
+ * When `true`, `properties` are emitted as individual top-level parameters instead of
901
+ * being wrapped in a single grouped construct.
902
+ *
903
+ * @default false
904
+ */
905
+ inline?: boolean;
906
+ /**
907
+ * Whether the group as a whole is optional.
908
+ * If omitted, printers infer this from child properties.
909
+ */
910
+ optional?: boolean;
911
+ /**
912
+ * Default value for the group, written verbatim after `=`.
913
+ * Commonly `'{}'` to allow omitting the argument entirely.
914
+ */
915
+ default?: string;
916
+ };
917
+ /**
918
+ * AST node for a complete function parameter list.
919
+ *
920
+ * Printers are responsible for sorting (`required` → `optional` → `defaulted`).
921
+ * Nodes are plain immutable data.
922
+ *
923
+ * Renders differently depending on the output mode:
924
+ * - `declaration` → `(id: string, config: Config = {})` — function declaration parameters
925
+ * - `call` → `(id, { method, url })` — function call arguments
926
+ * - `keys` → `{ id, config }` — key names only (for destructuring)
927
+ * - `values` → `{ id: id, config: config }` — key → value pairs
928
+ */
929
+ type FunctionParametersNode = BaseNode & {
930
+ /**
931
+ * Node kind.
932
+ */
933
+ kind: 'FunctionParameters';
934
+ /**
935
+ * Ordered parameter nodes.
936
+ */
937
+ params: ReadonlyArray<FunctionParameterNode | ParameterGroupNode>;
938
+ };
939
+ /**
940
+ * Union of all function-parameter AST node variants used by the function-parameter printer.
941
+ */
942
+ type FunctionParamNode = FunctionParameterNode | ParameterGroupNode | FunctionParametersNode | ParamsTypeNode;
943
+ /**
944
+ * Handler map keys — one per `FunctionParamNode` kind.
945
+ */
946
+ type FunctionNodeType = 'functionParameter' | 'parameterGroup' | 'functionParameters' | 'paramsType';
947
+ //#endregion
948
+ //#region src/nodes/property.d.ts
949
+ /**
950
+ * AST node representing one named object property.
951
+ *
952
+ * @example
953
+ * ```ts
954
+ * const property: PropertyNode = {
955
+ * kind: 'Property',
956
+ * name: 'id',
957
+ * schema: createSchema({ type: 'integer' }),
958
+ * required: true,
959
+ * }
960
+ * ```
961
+ */
962
+ type PropertyNode = BaseNode & {
963
+ /**
964
+ * Node kind.
965
+ */
966
+ kind: 'Property';
967
+ /**
968
+ * Property key.
969
+ */
970
+ name: string;
971
+ /**
972
+ * Property schema.
973
+ */
974
+ schema: SchemaNode;
975
+ /**
976
+ * Whether the property is required.
977
+ */
978
+ required: boolean;
979
+ };
980
+ //#endregion
981
+ //#region src/nodes/schema.d.ts
982
+ type PrimitiveSchemaType =
983
+ /**
984
+ * Text value.
985
+ */
986
+ 'string'
987
+ /**
988
+ * Floating-point number.
989
+ */
990
+ | 'number'
991
+ /**
992
+ * Integer number.
993
+ */
994
+ | 'integer'
995
+ /**
996
+ * Big integer number.
997
+ */
998
+ | 'bigint'
999
+ /**
1000
+ * Boolean value.
1001
+ */
1002
+ | 'boolean'
1003
+ /**
1004
+ * Null value.
1005
+ */
1006
+ | 'null'
1007
+ /**
1008
+ * Any value.
1009
+ */
1010
+ | 'any'
1011
+ /**
1012
+ * Unknown value.
1013
+ */
1014
+ | 'unknown'
1015
+ /**
1016
+ * No value (`void`).
1017
+ */
1018
+ | 'void'
1019
+ /**
1020
+ * Never value.
1021
+ */
1022
+ | 'never'
1023
+ /**
1024
+ * Object value.
1025
+ */
1026
+ | 'object'
1027
+ /**
1028
+ * Array value.
1029
+ */
1030
+ | 'array'
1031
+ /**
1032
+ * Date value.
1033
+ */
1034
+ | 'date';
1035
+ /**
1036
+ * Composite schema types.
1037
+ */
1038
+ type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum';
1039
+ /**
1040
+ * Schema types that need special handling in generators.
1041
+ */
1042
+ type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'ipv4' | 'ipv6' | 'blob';
1043
+ /**
1044
+ * All schema type strings.
1045
+ */
1046
+ type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType;
1047
+ /**
1048
+ * Scalar schema types without extra object/array/ref structure.
1049
+ */
1050
+ type ScalarSchemaType = Exclude<SchemaType, 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint' | 'url' | 'uuid' | 'email'>;
1051
+ /**
1052
+ * Fields shared by all schema nodes.
1053
+ */
1054
+ type SchemaNodeBase = BaseNode & {
1055
+ /**
1056
+ * Node kind.
1057
+ */
1058
+ kind: 'Schema';
1059
+ /**
1060
+ * Schema name for named definitions (for example, `"Pet"`).
1061
+ * Inline schemas omit this field.
1062
+ * `null` means kubb has processed this and determined there is no applicable name.
1063
+ * `undefined` means the name has not been set yet.
1064
+ */
1065
+ name?: string | null;
1066
+ /**
1067
+ * Short schema title.
1068
+ */
1069
+ title?: string;
1070
+ /**
1071
+ * Schema description text.
1072
+ */
1073
+ description?: string;
1074
+ /**
1075
+ * Whether `null` is allowed.
1076
+ */
1077
+ nullable?: boolean;
1078
+ /**
1079
+ * Whether the field is optional.
1080
+ */
1081
+ optional?: boolean;
1082
+ /**
1083
+ * Both optional and nullable (`optional` + `nullable`).
1084
+ */
1085
+ nullish?: boolean;
1086
+ /**
1087
+ * Whether the schema is deprecated.
1088
+ */
1089
+ deprecated?: boolean;
1090
+ /**
1091
+ * Whether the schema is read-only.
1092
+ */
1093
+ readOnly?: boolean;
1094
+ /**
1095
+ * Whether the schema is write-only.
1096
+ */
1097
+ writeOnly?: boolean;
1098
+ /**
1099
+ * Default value.
1100
+ */
1101
+ default?: unknown;
1102
+ /**
1103
+ * Example value.
1104
+ */
1105
+ example?: unknown;
1106
+ /**
1107
+ * Base primitive type.
1108
+ * For example, this is `'string'` for a `uuid` schema.
1109
+ */
1110
+ primitive?: PrimitiveSchemaType;
1111
+ };
1112
+ /**
1113
+ * Object schema with ordered properties.
1114
+ *
1115
+ * @example
1116
+ * ```ts
1117
+ * const objectSchema: ObjectSchemaNode = {
1118
+ * kind: 'Schema',
1119
+ * type: 'object',
1120
+ * properties: [],
1121
+ * }
1122
+ * ```
1123
+ */
1124
+ type ObjectSchemaNode = SchemaNodeBase & {
1125
+ /**
1126
+ * Schema type discriminator.
1127
+ */
1128
+ type: 'object';
1129
+ /**
1130
+ * Primitive type — always `'object'` for object schemas.
1131
+ */
1132
+ primitive: 'object';
1133
+ /**
1134
+ * Ordered object properties.
1135
+ */
1136
+ properties: Array<PropertyNode>;
1137
+ /**
1138
+ * Additional object properties behavior:
1139
+ * - `true`: allow any value
1140
+ * - `false`: reject unknown properties (maps to `.strict()` in Zod)
1141
+ * - `SchemaNode`: allow values that match that schema
1142
+ * - `undefined`: no additional properties constraint (open object)
1143
+ */
1144
+ additionalProperties?: SchemaNode | boolean;
1145
+ /**
1146
+ * Pattern-based property schemas.
1147
+ */
1148
+ patternProperties?: Record<string, SchemaNode>;
1149
+ /**
1150
+ * Minimum number of properties allowed.
1151
+ */
1152
+ minProperties?: number;
1153
+ /**
1154
+ * Maximum number of properties allowed.
1155
+ */
1156
+ maxProperties?: number;
1157
+ };
1158
+ /**
1159
+ * Array-like schema (`array` or `tuple`).
1160
+ *
1161
+ * @example
1162
+ * ```ts
1163
+ * const arraySchema: ArraySchemaNode = {
1164
+ * kind: 'Schema',
1165
+ * type: 'array',
1166
+ * items: [],
1167
+ * }
1168
+ * ```
1169
+ */
1170
+ type ArraySchemaNode = SchemaNodeBase & {
1171
+ /**
1172
+ * Schema type discriminator (`array` or `tuple`).
1173
+ */
1174
+ type: 'array' | 'tuple';
1175
+ /**
1176
+ * Item schemas.
1177
+ */
1178
+ items?: Array<SchemaNode>;
1179
+ /**
1180
+ * Tuple rest-item schema for elements beyond positional `items`.
1181
+ */
1182
+ rest?: SchemaNode;
1183
+ /**
1184
+ * Minimum item count (or tuple length).
1185
+ */
1186
+ min?: number;
1187
+ /**
1188
+ * Maximum item count (or tuple length).
1189
+ */
1190
+ max?: number;
1191
+ /**
1192
+ * Whether all items must be unique.
1193
+ */
1194
+ unique?: boolean;
1195
+ };
1196
+ /**
1197
+ * Shared shape for union and intersection schemas.
1198
+ */
1199
+ type CompositeSchemaNodeBase = SchemaNodeBase & {
1200
+ /**
1201
+ * Member schemas.
1202
+ */
1203
+ members?: Array<SchemaNode>;
1204
+ };
1205
+ /**
1206
+ * Union schema, often from `oneOf` or `anyOf`.
1207
+ *
1208
+ * @example
1209
+ * ```ts
1210
+ * const unionSchema: UnionSchemaNode = {
1211
+ * kind: 'Schema',
1212
+ * type: 'union',
1213
+ * members: [],
1214
+ * }
1215
+ * ```
1216
+ */
1217
+ type UnionSchemaNode = CompositeSchemaNodeBase & {
1218
+ /**
1219
+ * Schema type discriminator.
1220
+ */
1221
+ type: 'union';
1222
+ /**
1223
+ * Discriminator property name from OpenAPI `discriminator.propertyName`.
1224
+ */
1225
+ discriminatorPropertyName?: string;
1226
+ /**
1227
+ * Logical strategy applied to union members: 'one' means exactly one member must be valid (from `oneOf`),
1228
+ * 'any' means any number of members can be valid (from `anyOf`).
1229
+ */
1230
+ strategy?: 'one' | 'any';
1231
+ };
1232
+ /**
1233
+ * Intersection schema, often from `allOf`.
1234
+ *
1235
+ * @example
1236
+ * ```ts
1237
+ * const intersectionSchema: IntersectionSchemaNode = {
1238
+ * kind: 'Schema',
1239
+ * type: 'intersection',
1240
+ * members: [],
1241
+ * }
1242
+ * ```
1243
+ */
1244
+ type IntersectionSchemaNode = CompositeSchemaNodeBase & {
1245
+ /**
1246
+ * Schema type discriminator.
1247
+ */
1248
+ type: 'intersection';
1249
+ };
1250
+ /**
1251
+ * One named enum item.
1252
+ */
1253
+ type EnumValueNode = {
1254
+ /**
1255
+ * Enum item name.
1256
+ */
1257
+ name: string;
1258
+ /**
1259
+ * Enum item value.
1260
+ */
1261
+ value: string | number | boolean;
1262
+ /**
1263
+ * Primitive type of the enum value.
1264
+ */
1265
+ primitive: Extract<PrimitiveSchemaType, 'string' | 'number' | 'boolean'>;
1266
+ };
1267
+ /**
1268
+ * Enum schema node.
1269
+ *
1270
+ * @example
1271
+ * ```ts
1272
+ * const enumSchema: EnumSchemaNode = {
1273
+ * kind: 'Schema',
1274
+ * type: 'enum',
1275
+ * enumValues: ['a', 'b'],
1276
+ * }
1277
+ * ```
1278
+ */
1279
+ type EnumSchemaNode = SchemaNodeBase & {
1280
+ /**
1281
+ * Schema type discriminator.
1282
+ */
1283
+ type: 'enum';
1284
+ /**
1285
+ * Enum values in simple form.
1286
+ */
1287
+ enumValues?: Array<string | number | boolean | null>;
1288
+ /**
1289
+ * Enum values in named form.
1290
+ * If present, this is used instead of `enumValues`.
1291
+ */
1292
+ namedEnumValues?: Array<EnumValueNode>;
1293
+ };
1294
+ /**
1295
+ * Reference schema that points to another schema definition.
1296
+ *
1297
+ * @example
1298
+ * ```ts
1299
+ * const refSchema: RefSchemaNode = {
1300
+ * kind: 'Schema',
1301
+ * type: 'ref',
1302
+ * ref: '#/components/schemas/Pet',
1303
+ * }
1304
+ * ```
1305
+ */
1306
+ type RefSchemaNode = SchemaNodeBase & {
1307
+ /**
1308
+ * Schema type discriminator.
1309
+ */
1310
+ type: 'ref';
1311
+ /**
1312
+ * Referenced schema name.
1313
+ */
1314
+ name?: string;
1315
+ /**
1316
+ * Original `$ref` path, for example, `#/components/schemas/Order`.
1317
+ * Used to resolve names later.
1318
+ */
1319
+ ref?: string;
1320
+ /**
1321
+ * Pattern copied from a sibling `pattern` field.
1322
+ */
1323
+ pattern?: string;
1324
+ /**
1325
+ * The fully-parsed schema that this ref resolves to.
1326
+ * Populated during OAS parsing when the referenced definition can be resolved.
1327
+ * `undefined` when the ref cannot be resolved or is part of a circular chain.
1328
+ *
1329
+ * Useful for inspecting the referenced schema's structure (e.g. `primitive`, `properties`)
1330
+ * without following the reference manually.
1331
+ */
1332
+ schema?: SchemaNode;
1333
+ };
1334
+ /**
1335
+ * Datetime schema.
1336
+ *
1337
+ * @example
1338
+ * ```ts
1339
+ * const datetimeSchema: DatetimeSchemaNode = { kind: 'Schema', type: 'datetime' }
1340
+ * ```
1341
+ */
1342
+ type DatetimeSchemaNode = SchemaNodeBase & {
1343
+ /**
1344
+ * Schema type discriminator.
1345
+ */
1346
+ type: 'datetime';
1347
+ /**
1348
+ * Whether the datetime includes a timezone offset (`dateType: 'stringOffset'`).
1349
+ */
1350
+ offset?: boolean;
1351
+ /**
1352
+ * Whether the datetime is local (no timezone, `dateType: 'stringLocal'`).
1353
+ */
1354
+ local?: boolean;
1355
+ };
1356
+ /**
1357
+ * Shared base for `date` and `time` schemas.
1358
+ */
1359
+ type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
1360
+ /**
1361
+ * Schema type discriminator.
1362
+ */
1363
+ type: T;
1364
+ /**
1365
+ * Output representation in generated code.
1366
+ */
1367
+ representation: 'date' | 'string';
1368
+ };
1369
+ /**
1370
+ * Date schema node.
1371
+ *
1372
+ * @example
1373
+ * ```ts
1374
+ * const dateSchema: DateSchemaNode = { kind: 'Schema', type: 'date', representation: 'string' }
1375
+ * ```
1376
+ */
1377
+ type DateSchemaNode = TemporalSchemaNodeBase<'date'>;
1378
+ /**
1379
+ * Time schema node.
1380
+ *
1381
+ * @example
1382
+ * ```ts
1383
+ * const timeSchema: TimeSchemaNode = { kind: 'Schema', type: 'time', representation: 'string' }
1384
+ * ```
1385
+ */
1386
+ type TimeSchemaNode = TemporalSchemaNodeBase<'time'>;
1387
+ /**
1388
+ * String schema node.
1389
+ *
1390
+ * @example
1391
+ * ```ts
1392
+ * const stringSchema: StringSchemaNode = { kind: 'Schema', type: 'string' }
1393
+ * ```
1394
+ */
1395
+ type StringSchemaNode = SchemaNodeBase & {
1396
+ /**
1397
+ * Schema type discriminator.
1398
+ */
1399
+ type: 'string';
1400
+ /**
1401
+ * Minimum string length.
1402
+ */
1403
+ min?: number;
1404
+ /**
1405
+ * Maximum string length.
1406
+ */
1407
+ max?: number;
1408
+ /**
1409
+ * Regex pattern.
1410
+ */
1411
+ pattern?: string;
1412
+ };
1413
+ /**
1414
+ * Numeric schema (`number`, `integer`, or `bigint`).
1415
+ *
1416
+ * @example
1417
+ * ```ts
1418
+ * const numberSchema: NumberSchemaNode = { kind: 'Schema', type: 'number' }
1419
+ * ```
1420
+ */
1421
+ type NumberSchemaNode = SchemaNodeBase & {
1422
+ /**
1423
+ * Schema type discriminator.
1424
+ */
1425
+ type: 'number' | 'integer' | 'bigint';
1426
+ /**
1427
+ * Minimum value.
1428
+ */
1429
+ min?: number;
1430
+ /**
1431
+ * Maximum value.
1432
+ */
1433
+ max?: number;
1434
+ /**
1435
+ * Exclusive minimum value.
1436
+ */
1437
+ exclusiveMinimum?: number;
1438
+ /**
1439
+ * Exclusive maximum value.
1440
+ */
1441
+ exclusiveMaximum?: number;
1442
+ /**
1443
+ * The value must be a multiple of this number.
1444
+ */
1445
+ multipleOf?: number;
1446
+ };
1447
+ /**
1448
+ * Scalar schema with no extra constraints.
1449
+ *
1450
+ * @example
1451
+ * ```ts
1452
+ * const anySchema: ScalarSchemaNode = { kind: 'Schema', type: 'any' }
1453
+ * ```
1454
+ */
1455
+ type ScalarSchemaNode = SchemaNodeBase & {
1456
+ /**
1457
+ * Schema type discriminator.
1458
+ */
1459
+ type: ScalarSchemaType;
1460
+ };
1461
+ /**
1462
+ * URL schema node.
1463
+ * Can include an OpenAPI-style path template for template literal types.
1464
+ *
1465
+ * @example
1466
+ * ```ts
1467
+ * const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets/{petId}' }
1468
+ * ```
1469
+ */
1470
+ type UrlSchemaNode = SchemaNodeBase & {
1471
+ /**
1472
+ * Schema type discriminator.
1473
+ */
1474
+ type: 'url';
1475
+ /**
1476
+ * OpenAPI-style path template, for example, `'/pets/{petId}'`.
1477
+ */
1478
+ path?: string;
1479
+ /**
1480
+ * Minimum string length.
1481
+ */
1482
+ min?: number;
1483
+ /**
1484
+ * Maximum string length.
1485
+ */
1486
+ max?: number;
1487
+ };
1488
+ /**
1489
+ * Format-string schema for string-based formats that support length constraints.
1490
+ *
1491
+ * @example
1492
+ * ```ts
1493
+ * const uuidSchema: FormatStringSchemaNode = { kind: 'Schema', type: 'uuid', min: 36, max: 36 }
1494
+ * ```
1495
+ */
1496
+ type FormatStringSchemaNode = SchemaNodeBase & {
1497
+ /**
1498
+ * Schema type discriminator.
1499
+ */
1500
+ type: 'uuid' | 'email';
1501
+ /**
1502
+ * Minimum string length.
1503
+ */
1504
+ min?: number;
1505
+ /**
1506
+ * Maximum string length.
1507
+ */
1508
+ max?: number;
1509
+ };
1510
+ /**
1511
+ * IPv4 address schema node.
1512
+ *
1513
+ * @example
1514
+ * ```ts
1515
+ * const ipv4Schema: Ipv4SchemaNode = { kind: 'Schema', type: 'ipv4' }
1516
+ * ```
1517
+ */
1518
+ type Ipv4SchemaNode = SchemaNodeBase & {
1519
+ /**
1520
+ * Schema type discriminator.
1521
+ */
1522
+ type: 'ipv4';
1523
+ };
1524
+ /**
1525
+ * IPv6 address schema node.
1526
+ *
1527
+ * @example
1528
+ * ```ts
1529
+ * const ipv6Schema: Ipv6SchemaNode = { kind: 'Schema', type: 'ipv6' }
1530
+ * ```
1531
+ */
1532
+ type Ipv6SchemaNode = SchemaNodeBase & {
1533
+ /**
1534
+ * Schema type discriminator.
1535
+ */
1536
+ type: 'ipv6';
1537
+ };
1538
+ /**
1539
+ * Mapping from schema type literals to concrete schema node types.
1540
+ * Used by `narrowSchema`.
1541
+ */
1542
+ type SchemaNodeByType = {
1543
+ object: ObjectSchemaNode;
1544
+ array: ArraySchemaNode;
1545
+ tuple: ArraySchemaNode;
1546
+ union: UnionSchemaNode;
1547
+ intersection: IntersectionSchemaNode;
1548
+ enum: EnumSchemaNode;
1549
+ ref: RefSchemaNode;
1550
+ datetime: DatetimeSchemaNode;
1551
+ date: DateSchemaNode;
1552
+ time: TimeSchemaNode;
1553
+ string: StringSchemaNode;
1554
+ number: NumberSchemaNode;
1555
+ integer: NumberSchemaNode;
1556
+ bigint: NumberSchemaNode;
1557
+ boolean: ScalarSchemaNode;
1558
+ null: ScalarSchemaNode;
1559
+ any: ScalarSchemaNode;
1560
+ unknown: ScalarSchemaNode;
1561
+ void: ScalarSchemaNode;
1562
+ never: ScalarSchemaNode;
1563
+ uuid: FormatStringSchemaNode;
1564
+ email: FormatStringSchemaNode;
1565
+ url: UrlSchemaNode;
1566
+ ipv4: Ipv4SchemaNode;
1567
+ ipv6: Ipv6SchemaNode;
1568
+ blob: ScalarSchemaNode;
1569
+ };
1570
+ /**
1571
+ * Union of all schema node types.
1572
+ */
1573
+ type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | FormatStringSchemaNode | Ipv4SchemaNode | Ipv6SchemaNode | ScalarSchemaNode;
1574
+ //#endregion
1575
+ //#region src/nodes/parameter.d.ts
1576
+ type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
1577
+ /**
1578
+ * AST node representing one operation parameter.
1579
+ *
1580
+ * @example
1581
+ * ```ts
1582
+ * const param: ParameterNode = {
1583
+ * kind: 'Parameter',
1584
+ * name: 'petId',
1585
+ * in: 'path',
1586
+ * schema: createSchema({ type: 'string' }),
1587
+ * required: true,
1588
+ * }
1589
+ * ```
1590
+ */
1591
+ type ParameterNode = BaseNode & {
1592
+ /**
1593
+ * Node kind.
1594
+ */
1595
+ kind: 'Parameter';
1596
+ /**
1597
+ * Parameter name.
1598
+ */
1599
+ name: string;
1600
+ /**
1601
+ * Parameter location (`path`, `query`, `header`, or `cookie`).
1602
+ */
1603
+ in: ParameterLocation;
1604
+ /**
1605
+ * Parameter schema.
1606
+ */
1607
+ schema: SchemaNode;
1608
+ /**
1609
+ * Whether the parameter is required.
1610
+ */
1611
+ required: boolean;
1612
+ };
1613
+ //#endregion
1614
+ //#region src/nodes/http.d.ts
1615
+ /**
1616
+ * All supported HTTP status code literals as strings, as used in API specs
1617
+ * (for example, `"200"` and `"404"`).
1618
+ */
1619
+ type HttpStatusCode = '100' | '101' | '102' | '103' | '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226' | '300' | '301' | '302' | '303' | '304' | '305' | '307' | '308' | '400' | '401' | '402' | '403' | '404' | '405' | '406' | '407' | '408' | '409' | '410' | '411' | '412' | '413' | '414' | '415' | '416' | '417' | '418' | '421' | '422' | '423' | '424' | '425' | '426' | '428' | '429' | '431' | '451' | '500' | '501' | '502' | '503' | '504' | '505' | '506' | '507' | '508' | '510' | '511';
1620
+ /**
1621
+ * Response status code literal used by operations.
1622
+ *
1623
+ * Includes specific HTTP status code strings and `"default"` for catch-all responses.
1624
+ *
1625
+ * @example
1626
+ * ```ts
1627
+ * const status: StatusCode = '200'
1628
+ * const fallback: StatusCode = 'default'
1629
+ * ```
1630
+ */
1631
+ type StatusCode = HttpStatusCode | 'default';
1632
+ /**
1633
+ * Supported media type strings used in request and response bodies.
1634
+ *
1635
+ * @example
1636
+ * ```ts
1637
+ * const mediaType: MediaType = 'application/json'
1638
+ * ```
1639
+ */
1640
+ type MediaType = 'application/json' | 'application/xml' | 'application/x-www-form-urlencoded' | 'application/octet-stream' | 'application/pdf' | 'application/zip' | 'application/graphql' | 'multipart/form-data' | 'text/plain' | 'text/html' | 'text/csv' | 'text/xml' | 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/svg+xml' | 'audio/mpeg' | 'video/mp4';
1641
+ //#endregion
1642
+ //#region src/nodes/response.d.ts
1643
+ /**
1644
+ * AST node representing one operation response variant.
1645
+ *
1646
+ * @example
1647
+ * ```ts
1648
+ * const response: ResponseNode = {
1649
+ * kind: 'Response',
1650
+ * statusCode: '200',
1651
+ * schema: createSchema({ type: 'string' }),
1652
+ * }
1653
+ * ```
1654
+ */
1655
+ type ResponseNode = BaseNode & {
1656
+ /**
1657
+ * Node kind.
1658
+ */
1659
+ kind: 'Response';
1660
+ /**
1661
+ * HTTP status code or `'default'` for a fallback response.
1662
+ */
1663
+ statusCode: StatusCode;
1664
+ /**
1665
+ * Optional response description.
1666
+ */
1667
+ description?: string;
1668
+ /**
1669
+ * Response body schema.
1670
+ */
1671
+ schema: SchemaNode;
1672
+ /**
1673
+ * Response media type.
1674
+ */
1675
+ mediaType?: MediaType | null;
1676
+ /**
1677
+ * Property keys to exclude from the generated type via `Omit<Type, Keys>`.
1678
+ * Set when a referenced schema has `writeOnly` fields that should not appear in response types.
1679
+ */
1680
+ keysToOmit?: Array<string>;
1681
+ };
1682
+ //#endregion
1683
+ //#region src/nodes/operation.d.ts
1684
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
1685
+ /**
1686
+ * AST node representing one API operation.
1687
+ *
1688
+ * @example
1689
+ * ```ts
1690
+ * const operation: OperationNode = {
1691
+ * kind: 'Operation',
1692
+ * operationId: 'listPets',
1693
+ * method: 'GET',
1694
+ * path: '/pets',
1695
+ * tags: [],
1696
+ * parameters: [],
1697
+ * responses: [],
1698
+ * }
1699
+ * ```
1700
+ */
1701
+ type OperationNode = BaseNode & {
1702
+ /**
1703
+ * Node kind.
1704
+ */
1705
+ kind: 'Operation';
1706
+ /**
1707
+ * Operation identifier, usually from OpenAPI `operationId`.
1708
+ */
1709
+ operationId: string;
1710
+ /**
1711
+ * HTTP Method like 'GET'
1712
+ */
1713
+ method: HttpMethod;
1714
+ /**
1715
+ * OpenAPI-style path string, for example `/pets/{petId}`.
1716
+ * Path parameters retain the `{param}` notation from the original spec.
1717
+ */
1718
+ path: string;
1719
+ /**
1720
+ * Group labels for the operation.
1721
+ * Usually copied from OpenAPI `tags`.
1722
+ */
1723
+ tags: Array<string>;
1724
+ /**
1725
+ * Short one-line operation summary.
1726
+ */
1727
+ summary?: string;
1728
+ /**
1729
+ * Full operation description.
1730
+ */
1731
+ description?: string;
1732
+ /**
1733
+ * Marks the operation as deprecated.
1734
+ */
1735
+ deprecated?: boolean;
1736
+ /**
1737
+ * Parameters that could be used, we have QueryParams, PathParams, HeaderParams and CookieParams
1738
+ */
1739
+ parameters: Array<ParameterNode>;
1740
+ /**
1741
+ * Request body metadata for the operation.
1742
+ */
1743
+ requestBody?: {
1744
+ /**
1745
+ * Human-readable request body description.
1746
+ */
1747
+ description?: string;
1748
+ /**
1749
+ * Whether the request body is required (`requestBody.required: true` in the spec).
1750
+ * When `false` or absent, the generated `data` parameter should be optional.
1751
+ */
1752
+ required?: boolean;
1753
+ /**
1754
+ * All available content type entries for this request body.
1755
+ *
1756
+ * When the adapter `contentType` option is set, this array contains exactly one entry for
1757
+ * that content type. Otherwise it contains one entry per content type declared in the spec,
1758
+ * so that plugins can generate code for every variant (e.g. separate hooks for
1759
+ * `application/json` and `multipart/form-data`).
1760
+ *
1761
+ * @example
1762
+ * ```ts
1763
+ * // spec has both application/json and multipart/form-data
1764
+ * requestBody.content[0].contentType // 'application/json'
1765
+ * requestBody.content[1].contentType // 'multipart/form-data'
1766
+ * ```
1767
+ */
1768
+ content?: Array<{
1769
+ /**
1770
+ * The content type for this entry (e.g. `'application/json'`).
1771
+ */
1772
+ contentType: string;
1773
+ /**
1774
+ * Request body schema for this content type.
1775
+ */
1776
+ schema?: SchemaNode;
1777
+ /**
1778
+ * Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
1779
+ * Set when a referenced schema has `readOnly` fields that should be omitted in request types.
1780
+ */
1781
+ keysToOmit?: Array<string>;
1782
+ }>;
1783
+ };
1784
+ /**
1785
+ * Operation responses.
1786
+ */
1787
+ responses: Array<ResponseNode>;
1788
+ };
1789
+ //#endregion
1790
+ //#region src/nodes/output.d.ts
1791
+ /**
1792
+ * Output AST node that groups all generated file output for one API document.
1793
+ *
1794
+ * Produced by generators and consumed by the build pipeline to write files.
1795
+ *
1796
+ * @example
1797
+ * ```ts
1798
+ * const output: OutputNode = {
1799
+ * kind: 'Output',
1800
+ * files: [],
1801
+ * }
1802
+ * ```
1803
+ */
1804
+ type OutputNode = BaseNode & {
1805
+ /**
1806
+ * Node kind.
1807
+ */
1808
+ kind: 'Output';
1809
+ /**
1810
+ * Generated file nodes.
1811
+ */
1812
+ files: Array<FileNode>;
1813
+ };
1814
+ //#endregion
1815
+ //#region src/nodes/root.d.ts
1816
+ /**
1817
+ * Basic metadata for an API document.
1818
+ * Adapters fill fields that exist in their source format.
1819
+ *
1820
+ * @example
1821
+ * ```ts
1822
+ * const meta: InputMeta = { title: 'Pet API', version: '1.0.0' }
1823
+ * ```
1824
+ */
1825
+ type InputMeta = {
1826
+ /**
1827
+ * API title (from `info.title` in OAS/AsyncAPI).
1828
+ */
1829
+ title?: string;
1830
+ /**
1831
+ * API description (from `info.description` in OAS/AsyncAPI).
1832
+ */
1833
+ description?: string;
1834
+ /**
1835
+ * API version string (from `info.version` in OAS/AsyncAPI).
1836
+ */
1837
+ version?: string;
1838
+ /**
1839
+ * Resolved API base URL.
1840
+ * For OpenAPI and AsyncAPI, this comes from the selected server URL.
1841
+ */
1842
+ baseURL?: string;
1843
+ };
1844
+ /**
1845
+ * Input AST node that contains all schemas and operations for one API document.
1846
+ * Produced by the adapter and consumed by all Kubb plugins.
1847
+ *
1848
+ * @example
1849
+ * ```ts
1850
+ * const input: InputNode = {
1851
+ * kind: 'Input',
1852
+ * schemas: [],
1853
+ * operations: [],
1854
+ * }
1855
+ * ```
1856
+ */
1857
+ type InputNode = BaseNode & {
1858
+ /**
1859
+ * Node kind.
1860
+ */
1861
+ kind: 'Input';
1862
+ /**
1863
+ * All schema nodes in the document.
1864
+ */
1865
+ schemas: Array<SchemaNode>;
1866
+ /**
1867
+ * All operation nodes in the document.
1868
+ */
1869
+ operations: Array<OperationNode>;
1870
+ /**
1871
+ * Optional document metadata populated by the adapter.
1872
+ */
1873
+ meta?: InputMeta;
1874
+ };
1875
+ //#endregion
1876
+ //#region src/nodes/index.d.ts
1877
+ /**
1878
+ * Union of all AST node types.
1879
+ *
1880
+ * This lets TypeScript narrow types in `switch (node.kind)` blocks.
1881
+ *
1882
+ * @example
1883
+ * ```ts
1884
+ * function getKind(node: Node): string {
1885
+ * switch (node.kind) {
1886
+ * case 'Input':
1887
+ * return 'input'
1888
+ * case 'Output':
1889
+ * return 'output'
1890
+ * default:
1891
+ * return 'other'
1892
+ * }
1893
+ * }
1894
+ * ```
1895
+ */
1896
+ type Node = InputNode | OutputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | FunctionParamNode | FileNode | ImportNode | ExportNode | SourceNode | ConstNode | TypeNode | ParamsTypeNode | FunctionNode | ArrowFunctionNode;
1897
+ //#endregion
1898
+ //#region src/infer.d.ts
1899
+ /**
1900
+ * Shared parser options used by OAS-to-AST inference and parser flows.
1901
+ */
1902
+ type ParserOptions = {
1903
+ /**
1904
+ * How `format: 'date-time'` schemas are represented. `false` falls through to a plain string.
1905
+ */
1906
+ dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
1907
+ /**
1908
+ * Whether `type: 'integer'` and `format: 'int64'` produce `number` or `bigint` nodes.
1909
+ */
1910
+ integerType?: 'number' | 'bigint';
1911
+ /**
1912
+ * AST type used when no schema type can be inferred.
1913
+ */
1914
+ unknownType: 'any' | 'unknown' | 'void';
1915
+ /**
1916
+ * AST type used for completely empty schemas (`{}`).
1917
+ */
1918
+ emptySchemaType: 'any' | 'unknown' | 'void';
1919
+ /**
1920
+ * Suffix appended to derived enum names when building property schema names.
1921
+ */
1922
+ enumSuffix: 'enum' | (string & {});
1923
+ };
1924
+ /**
1925
+ * Maps each `dateType` option value to the AST node produced by `format: 'date-time'`.
1926
+ */
1927
+ type DateTimeNodeByDateType = {
1928
+ date: DateSchemaNode;
1929
+ string: DatetimeSchemaNode;
1930
+ stringOffset: DatetimeSchemaNode;
1931
+ stringLocal: DatetimeSchemaNode;
1932
+ false: StringSchemaNode;
1933
+ };
1934
+ /**
1935
+ * Resolves the AST node produced by `format: 'date-time'` based on the `dateType` option.
1936
+ */
1937
+ type ResolveDateTimeNode<TDateType extends ParserOptions['dateType']> = DateTimeNodeByDateType[TDateType extends keyof DateTimeNodeByDateType ? TDateType : 'string'];
1938
+ /**
1939
+ * Ordered list of `[schema-shape, SchemaNode]` pairs.
1940
+ * `InferSchemaNode` walks this tuple in order and returns the first matching node type.
1941
+ */
1942
+ type SchemaNodeMap<TDateType extends ParserOptions['dateType'] = 'string'> = [[{
1943
+ $ref: string;
1944
+ }, RefSchemaNode], [{
1945
+ allOf: ReadonlyArray<unknown>;
1946
+ properties: object;
1947
+ }, IntersectionSchemaNode], [{
1948
+ allOf: readonly [unknown, unknown, ...unknown[]];
1949
+ }, IntersectionSchemaNode], [{
1950
+ allOf: ReadonlyArray<unknown>;
1951
+ }, SchemaNode], [{
1952
+ oneOf: ReadonlyArray<unknown>;
1953
+ }, UnionSchemaNode], [{
1954
+ anyOf: ReadonlyArray<unknown>;
1955
+ }, UnionSchemaNode], [{
1956
+ const: null;
1957
+ }, ScalarSchemaNode], [{
1958
+ const: string | number | boolean;
1959
+ }, EnumSchemaNode], [{
1960
+ type: ReadonlyArray<string>;
1961
+ }, UnionSchemaNode], [{
1962
+ type: 'array';
1963
+ enum: ReadonlyArray<unknown>;
1964
+ }, ArraySchemaNode], [{
1965
+ enum: ReadonlyArray<unknown>;
1966
+ }, EnumSchemaNode], [{
1967
+ type: 'enum';
1968
+ }, EnumSchemaNode], [{
1969
+ type: 'union';
1970
+ }, UnionSchemaNode], [{
1971
+ type: 'intersection';
1972
+ }, IntersectionSchemaNode], [{
1973
+ type: 'tuple';
1974
+ }, ArraySchemaNode], [{
1975
+ type: 'ref';
1976
+ }, RefSchemaNode], [{
1977
+ type: 'datetime';
1978
+ }, DatetimeSchemaNode], [{
1979
+ type: 'date';
1980
+ }, DateSchemaNode], [{
1981
+ type: 'time';
1982
+ }, TimeSchemaNode], [{
1983
+ type: 'url';
1984
+ }, UrlSchemaNode], [{
1985
+ type: 'object';
1986
+ }, ObjectSchemaNode], [{
1987
+ additionalProperties: boolean | {};
1988
+ }, ObjectSchemaNode], [{
1989
+ type: 'array';
1990
+ }, ArraySchemaNode], [{
1991
+ items: object;
1992
+ }, ArraySchemaNode], [{
1993
+ prefixItems: ReadonlyArray<unknown>;
1994
+ }, ArraySchemaNode], [{
1995
+ type: string;
1996
+ format: 'date-time';
1997
+ }, ResolveDateTimeNode<TDateType>], [{
1998
+ type: string;
1999
+ format: 'date';
2000
+ }, DateSchemaNode], [{
2001
+ type: string;
2002
+ format: 'time';
2003
+ }, TimeSchemaNode], [{
2004
+ format: 'date-time';
2005
+ }, ResolveDateTimeNode<TDateType>], [{
2006
+ format: 'date';
2007
+ }, DateSchemaNode], [{
2008
+ format: 'time';
2009
+ }, TimeSchemaNode], [{
2010
+ type: 'string';
2011
+ }, StringSchemaNode], [{
2012
+ type: 'number';
2013
+ }, NumberSchemaNode], [{
2014
+ type: 'integer';
2015
+ }, NumberSchemaNode], [{
2016
+ type: 'bigint';
2017
+ }, NumberSchemaNode], [{
2018
+ type: string;
2019
+ }, ScalarSchemaNode], [{
2020
+ minLength: number;
2021
+ }, StringSchemaNode], [{
2022
+ maxLength: number;
2023
+ }, StringSchemaNode], [{
2024
+ pattern: string;
2025
+ }, StringSchemaNode], [{
2026
+ minimum: number;
2027
+ }, NumberSchemaNode], [{
2028
+ maximum: number;
2029
+ }, NumberSchemaNode]];
2030
+ /**
2031
+ * Infers the matching AST `SchemaNode` type from an input schema shape.
2032
+ */
2033
+ type InferSchemaNode<TSchema extends object, TDateType extends ParserOptions['dateType'] = 'string', TEntries extends ReadonlyArray<[object, SchemaNode]> = SchemaNodeMap<TDateType>> = TEntries extends [infer TEntry extends [object, SchemaNode], ...infer TRest extends ReadonlyArray<[object, SchemaNode]>] ? TSchema extends TEntry[0] ? TEntry[1] : InferSchemaNode<TSchema, TDateType, TRest> : SchemaNode;
2034
+ /**
2035
+ * Backward-compatible alias for `InferSchemaNode`.
2036
+ */
2037
+ type InferSchema<TSchema extends object, TDateType extends ParserOptions['dateType'] = 'string', TEntries extends ReadonlyArray<[object, SchemaNode]> = SchemaNodeMap<TDateType>> = InferSchemaNode<TSchema, TDateType, TEntries>;
2038
+ //#endregion
2039
+ //#region src/factory.d.ts
2040
+ /**
2041
+ * Syncs property/parameter schema optionality flags from `required` and `schema.nullable`.
2042
+ *
2043
+ * - `optional` is set for non-required, non-nullable schemas.
2044
+ * - `nullish` is set for non-required, nullable schemas.
2045
+ */
2046
+ declare function syncOptionality(schema: SchemaNode, required: boolean): SchemaNode;
2047
+ /**
2048
+ * Distributive `Omit` that preserves each member of a union.
2049
+ *
2050
+ * @example
2051
+ * ```ts
2052
+ * type A = { kind: 'a'; keep: string; drop: number }
2053
+ * type B = { kind: 'b'; keep: boolean; drop: number }
2054
+ * type Result = DistributiveOmit<A | B, 'drop'>
2055
+ * // -> { kind: 'a'; keep: string } | { kind: 'b'; keep: boolean }
2056
+ * ```
2057
+ */
2058
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
2059
+ type CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties' | 'primitive'> & {
2060
+ properties?: Array<PropertyNode>;
2061
+ primitive?: 'object';
2062
+ };
2063
+ type CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>;
2064
+ type CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {
2065
+ kind: 'Schema';
2066
+ };
2067
+ /**
2068
+ * Creates an `InputNode` with stable defaults for `schemas` and `operations`.
2069
+ *
2070
+ * @example
2071
+ * ```ts
2072
+ * const input = createInput()
2073
+ * // { kind: 'Input', schemas: [], operations: [] }
2074
+ * ```
2075
+ *
2076
+ * @example
2077
+ * ```ts
2078
+ * const input = createInput({ schemas: [petSchema] })
2079
+ * // keeps default operations: []
2080
+ * ```
2081
+ */
2082
+ declare function createInput(overrides?: Partial<Omit<InputNode, 'kind'>>): InputNode;
2083
+ /**
2084
+ * Creates an `OutputNode` with a stable default for `files`.
2085
+ *
2086
+ * @example
2087
+ * ```ts
2088
+ * const output = createOutput()
2089
+ * // { kind: 'Output', files: [] }
2090
+ * ```
2091
+ *
2092
+ * @example
2093
+ * ```ts
2094
+ * const output = createOutput({ files: [petFile] })
2095
+ * ```
2096
+ */
2097
+ declare function createOutput(overrides?: Partial<Omit<OutputNode, 'kind'>>): OutputNode;
2098
+ /**
2099
+ * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.
2100
+ *
2101
+ * @example
2102
+ * ```ts
2103
+ * const operation = createOperation({
2104
+ * operationId: 'getPetById',
2105
+ * method: 'GET',
2106
+ * path: '/pet/{petId}',
2107
+ * })
2108
+ * // tags, parameters, and responses are []
2109
+ * ```
2110
+ *
2111
+ * @example
2112
+ * ```ts
2113
+ * const operation = createOperation({
2114
+ * operationId: 'findPets',
2115
+ * method: 'GET',
2116
+ * path: '/pet/findByStatus',
2117
+ * tags: ['pet'],
2118
+ * })
2119
+ * ```
2120
+ */
2121
+ declare function createOperation(props: Pick<OperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<OperationNode, 'kind' | 'operationId' | 'method' | 'path'>>): OperationNode;
2122
+ /**
2123
+ * Creates a `SchemaNode`, narrowed to the variant of `props.type`.
2124
+ * For object schemas, `properties` defaults to an empty array.
2125
+ * `primitive` is automatically inferred from `type` when not explicitly provided.
2126
+ *
2127
+ * @example
2128
+ * ```ts
2129
+ * const scalar = createSchema({ type: 'string' })
2130
+ * // { kind: 'Schema', type: 'string', primitive: 'string' }
2131
+ * ```
2132
+ *
2133
+ * @example
2134
+ * ```ts
2135
+ * const uuid = createSchema({ type: 'uuid' })
2136
+ * // { kind: 'Schema', type: 'uuid', primitive: 'string' }
2137
+ * ```
2138
+ *
2139
+ * @example
2140
+ * ```ts
2141
+ * const object = createSchema({ type: 'object' })
2142
+ * // { kind: 'Schema', type: 'object', primitive: 'object', properties: [] }
2143
+ * ```
2144
+ *
2145
+ * @example
2146
+ * ```ts
2147
+ * const enumSchema = createSchema({
2148
+ * type: 'enum',
2149
+ * primitive: 'string',
2150
+ * enumValues: ['available', 'pending'],
2151
+ * })
2152
+ * ```
2153
+ */
2154
+ declare function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>;
2155
+ declare function createSchema(props: CreateSchemaInput): SchemaNode;
2156
+ type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>;
2157
+ /**
2158
+ * Creates a `PropertyNode`.
2159
+ *
2160
+ * `required` defaults to `false`.
2161
+ * `schema.optional` and `schema.nullish` are derived from `required` and `schema.nullable`.
2162
+ *
2163
+ * @example
2164
+ * ```ts
2165
+ * const property = createProperty({
2166
+ * name: 'status',
2167
+ * schema: createSchema({ type: 'string' }),
2168
+ * })
2169
+ * // required=false, schema.optional=true
2170
+ * ```
2171
+ *
2172
+ * @example
2173
+ * ```ts
2174
+ * const property = createProperty({
2175
+ * name: 'status',
2176
+ * required: true,
2177
+ * schema: createSchema({ type: 'string', nullable: true }),
2178
+ * })
2179
+ * // required=true, no optional/nullish
2180
+ * ```
2181
+ */
2182
+ declare function createProperty(props: UserPropertyNode): PropertyNode;
2183
+ /**
2184
+ * Creates a `ParameterNode`.
2185
+ *
2186
+ * `required` defaults to `false`.
2187
+ * Nested schema flags are set from `required` and `schema.nullable`.
2188
+ *
2189
+ * @example
2190
+ * ```ts
2191
+ * const param = createParameter({
2192
+ * name: 'petId',
2193
+ * in: 'path',
2194
+ * required: true,
2195
+ * schema: createSchema({ type: 'string' }),
2196
+ * })
2197
+ * ```
2198
+ *
2199
+ * @example
2200
+ * ```ts
2201
+ * const param = createParameter({
2202
+ * name: 'status',
2203
+ * in: 'query',
2204
+ * schema: createSchema({ type: 'string', nullable: true }),
2205
+ * })
2206
+ * // required=false, schema.nullish=true
2207
+ * ```
2208
+ */
2209
+ declare function createParameter(props: Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>): ParameterNode;
2210
+ /**
2211
+ * Creates a `ResponseNode`.
2212
+ *
2213
+ * @example
2214
+ * ```ts
2215
+ * const response = createResponse({
2216
+ * statusCode: '200',
2217
+ * description: 'Success',
2218
+ * schema: createSchema({ type: 'object', properties: [] }),
2219
+ * })
2220
+ * ```
2221
+ */
2222
+ declare function createResponse(props: Pick<ResponseNode, 'statusCode' | 'schema'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'schema'>>): ResponseNode;
2223
+ /**
2224
+ * Creates a `FunctionParameterNode`.
2225
+ *
2226
+ * `optional` defaults to `false`.
2227
+ *
2228
+ * @example Required typed param
2229
+ * ```ts
2230
+ * createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }) })
2231
+ * // → petId: string
2232
+ * ```
2233
+ *
2234
+ * @example Optional param
2235
+ * ```ts
2236
+ * createFunctionParameter({ name: 'params', type: createParamsType({ variant: 'reference', name: 'QueryParams' }), optional: true })
2237
+ * // → params?: QueryParams
2238
+ * ```
2239
+ *
2240
+ * @example Param with default (implicitly optional; cannot combine with `optional: true`)
2241
+ * ```ts
2242
+ * createFunctionParameter({ name: 'config', type: createParamsType({ variant: 'reference', name: 'RequestConfig' }), default: '{}' })
2243
+ * // → config: RequestConfig = {}
2244
+ * ```
2245
+ */
2246
+ declare function createFunctionParameter(props: {
2247
+ name: string;
2248
+ type?: ParamsTypeNode;
2249
+ rest?: boolean;
2250
+ } & ({
2251
+ optional: true;
2252
+ default?: never;
2253
+ } | {
2254
+ optional?: false;
2255
+ default?: string;
2256
+ })): FunctionParameterNode;
2257
+ /**
2258
+ * Creates a {@link TypeNode} representing a language-agnostic structured type expression.
2259
+ *
2260
+ * Use `variant: 'struct'` for inline anonymous types and `variant: 'member'` for a single
2261
+ * named field accessed from a group type. Each language's printer renders the variant
2262
+ * into its own syntax (TypeScript, Python, C#, Kotlin, …).
2263
+ *
2264
+ * @example Reference type (TypeScript: `QueryParams`)
2265
+ * ```ts
2266
+ * createParamsType({ variant: 'reference', name: 'QueryParams' })
2267
+ * ```
2268
+ *
2269
+ * @example Struct type (TypeScript: `{ petId: string }`)
2270
+ * ```ts
2271
+ * createParamsType({ variant: 'struct', properties: [{ name: 'petId', optional: false, type: createParamsType({ variant: 'reference', name: 'string' }) }] })
2272
+ * ```
2273
+ *
2274
+ * @example Member type (TypeScript: `DeletePetPathParams['petId']`)
2275
+ * ```ts
2276
+ * createParamsType({ variant: 'member', base: 'DeletePetPathParams', key: 'petId' })
2277
+ * ```
2278
+ */
2279
+ declare function createParamsType(props: {
2280
+ variant: 'reference';
2281
+ name: string;
2282
+ } | {
2283
+ variant: 'struct';
2284
+ properties: Array<{
2285
+ name: string;
2286
+ optional: boolean;
2287
+ type: ParamsTypeNode;
2288
+ }>;
2289
+ } | {
2290
+ variant: 'member';
2291
+ base: string;
2292
+ key: string;
2293
+ }): ParamsTypeNode;
2294
+ /**
2295
+ * Creates a `ParameterGroupNode` representing a group of related parameters treated as a unit.
2296
+ *
2297
+ * @example Grouped param (TypeScript declaration)
2298
+ * ```ts
2299
+ * createParameterGroup({
2300
+ * properties: [
2301
+ * createFunctionParameter({ name: 'id', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false }),
2302
+ * createFunctionParameter({ name: 'name', type: createParamsType({ variant: 'reference', name: 'string' }), optional: true }),
2303
+ * ],
2304
+ * default: '{}',
2305
+ * })
2306
+ * // declaration → { id, name? }: { id: string; name?: string } = {}
2307
+ * // call → { id, name }
2308
+ * ```
2309
+ *
2310
+ * @example Inline (spread) — children emitted as individual top-level parameters
2311
+ * ```ts
2312
+ * createParameterGroup({
2313
+ * properties: [createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false })],
2314
+ * inline: true,
2315
+ * })
2316
+ * // declaration → petId: string
2317
+ * // call → petId
2318
+ * ```
2319
+ */
2320
+ declare function createParameterGroup(props: Pick<ParameterGroupNode, 'properties'> & Partial<Omit<ParameterGroupNode, 'kind' | 'properties'>>): ParameterGroupNode;
2321
+ /**
2322
+ * Creates a `FunctionParametersNode` from an ordered list of parameters.
2323
+ *
2324
+ * @example
2325
+ * ```ts
2326
+ * createFunctionParameters({
2327
+ * params: [
2328
+ * createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false }),
2329
+ * createFunctionParameter({ name: 'config', type: createParamsType({ variant: 'reference', name: 'RequestConfig' }), optional: false, default: '{}' }),
2330
+ * ],
2331
+ * })
2332
+ * ```
2333
+ *
2334
+ * @example
2335
+ * ```ts
2336
+ * const empty = createFunctionParameters()
2337
+ * // { kind: 'FunctionParameters', params: [] }
2338
+ * ```
2339
+ */
2340
+ declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
2341
+ /**
2342
+ * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
2343
+ *
2344
+ * @example Named import
2345
+ * ```ts
2346
+ * createImport({ name: ['useState'], path: 'react' })
2347
+ * // import { useState } from 'react'
2348
+ * ```
2349
+ *
2350
+ * @example Type-only import
2351
+ * ```ts
2352
+ * createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
2353
+ * // import type { FC } from 'react'
2354
+ * ```
2355
+ */
2356
+ declare function createImport(props: Omit<ImportNode, 'kind'>): ImportNode;
2357
+ /**
2358
+ * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
2359
+ *
2360
+ * @example Named export
2361
+ * ```ts
2362
+ * createExport({ name: ['Pet'], path: './Pet' })
2363
+ * // export { Pet } from './Pet'
2364
+ * ```
2365
+ *
2366
+ * @example Wildcard export
2367
+ * ```ts
2368
+ * createExport({ path: './utils' })
2369
+ * // export * from './utils'
2370
+ * ```
2371
+ */
2372
+ declare function createExport(props: Omit<ExportNode, 'kind'>): ExportNode;
2373
+ /**
2374
+ * Creates a `SourceNode` representing a fragment of source code within a file.
2375
+ *
2376
+ * @example
2377
+ * ```ts
2378
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
2379
+ * ```
2380
+ */
2381
+ declare function createSource(props: Omit<SourceNode, 'kind'>): SourceNode;
2382
+ type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> & Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>;
2383
+ /**
2384
+ * Creates a fully resolved `FileNode` from a file input descriptor.
2385
+ *
2386
+ * Computes:
2387
+ * - `id` — SHA256 hash of the file path
2388
+ * - `name` — `baseName` without extension
2389
+ * - `extname` — extension extracted from `baseName`
2390
+ *
2391
+ * Deduplicates:
2392
+ * - `sources` via `combineSources`
2393
+ * - `exports` via `combineExports`
2394
+ * - `imports` via `combineImports` (also filters unused imports)
2395
+ *
2396
+ * @throws {Error} when `baseName` has no extension.
2397
+ *
2398
+ * @example
2399
+ * ```ts
2400
+ * const file = createFile({
2401
+ * baseName: 'petStore.ts',
2402
+ * path: 'src/models/petStore.ts',
2403
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
2404
+ * imports: [createImport({ name: ['z'], path: 'zod' })],
2405
+ * exports: [createExport({ name: ['Pet'], path: './petStore' })],
2406
+ * })
2407
+ * // file.id = SHA256 hash of 'src/models/petStore.ts'
2408
+ * // file.name = 'petStore'
2409
+ * // file.extname = '.ts'
2410
+ * ```
2411
+ */
2412
+ declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
2413
+ /**
2414
+ * Creates a `ConstNode` representing a TypeScript `const` declaration.
2415
+ *
2416
+ * Mirrors the `Const` component from `@kubb/renderer-jsx`.
2417
+ * The component's `children` are represented as `nodes`.
2418
+ *
2419
+ * @example Simple constant
2420
+ * ```ts
2421
+ * createConst({ name: 'pet' })
2422
+ * // const pet = ...
2423
+ * ```
2424
+ *
2425
+ * @example Exported constant with type and `as const`
2426
+ * ```ts
2427
+ * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
2428
+ * // export const pets: Pet[] = ... as const
2429
+ * ```
2430
+ *
2431
+ * @example With JSDoc and child nodes
2432
+ * ```ts
2433
+ * createConst({
2434
+ * name: 'config',
2435
+ * export: true,
2436
+ * JSDoc: { comments: ['@description App configuration'] },
2437
+ * nodes: [],
2438
+ * })
2439
+ * ```
2440
+ */
2441
+ declare function createConst(props: Omit<ConstNode, 'kind'>): ConstNode;
2442
+ /**
2443
+ * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
2444
+ *
2445
+ * Mirrors the `Type` component from `@kubb/renderer-jsx`.
2446
+ * The component's `children` are represented as `nodes`.
2447
+ *
2448
+ * @example Simple type alias
2449
+ * ```ts
2450
+ * createType({ name: 'Pet' })
2451
+ * // type Pet = ...
2452
+ * ```
2453
+ *
2454
+ * @example Exported type with JSDoc
2455
+ * ```ts
2456
+ * createType({
2457
+ * name: 'PetStatus',
2458
+ * export: true,
2459
+ * JSDoc: { comments: ['@description Status of a pet'] },
2460
+ * })
2461
+ * // export type PetStatus = ...
2462
+ * ```
2463
+ */
2464
+ declare function createType(props: Omit<TypeNode, 'kind'>): TypeNode;
2465
+ /**
2466
+ * Creates a `FunctionNode` representing a TypeScript `function` declaration.
2467
+ *
2468
+ * Mirrors the `Function` component from `@kubb/renderer-jsx`.
2469
+ * The component's `children` are represented as `nodes`.
2470
+ *
2471
+ * @example Simple function
2472
+ * ```ts
2473
+ * createFunction({ name: 'getPet' })
2474
+ * // function getPet() { ... }
2475
+ * ```
2476
+ *
2477
+ * @example Exported async function with return type
2478
+ * ```ts
2479
+ * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
2480
+ * // export async function fetchPet(): Promise<Pet> { ... }
2481
+ * ```
2482
+ *
2483
+ * @example Function with generics and params
2484
+ * ```ts
2485
+ * createFunction({
2486
+ * name: 'identity',
2487
+ * export: true,
2488
+ * generics: ['T'],
2489
+ * params: 'value: T',
2490
+ * returnType: 'T',
2491
+ * })
2492
+ * // export function identity<T>(value: T): T { ... }
2493
+ * ```
2494
+ */
2495
+ declare function createFunction(props: Omit<FunctionNode, 'kind'>): FunctionNode;
2496
+ /**
2497
+ * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
2498
+ *
2499
+ * Mirrors the `Function.Arrow` component from `@kubb/renderer-jsx`.
2500
+ * The component's `children` are represented as `nodes`.
2501
+ *
2502
+ * @example Simple arrow function
2503
+ * ```ts
2504
+ * createArrowFunction({ name: 'getPet' })
2505
+ * // const getPet = () => { ... }
2506
+ * ```
2507
+ *
2508
+ * @example Single-line exported arrow function
2509
+ * ```ts
2510
+ * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
2511
+ * // export const double = (n: number) => ...
2512
+ * ```
2513
+ *
2514
+ * @example Async arrow function with generics
2515
+ * ```ts
2516
+ * createArrowFunction({
2517
+ * name: 'fetchPet',
2518
+ * export: true,
2519
+ * async: true,
2520
+ * generics: ['T'],
2521
+ * params: 'id: string',
2522
+ * returnType: 'T',
2523
+ * })
2524
+ * // export const fetchPet = async <T>(id: string): Promise<T> => { ... }
2525
+ * ```
2526
+ */
2527
+ declare function createArrowFunction(props: Omit<ArrowFunctionNode, 'kind'>): ArrowFunctionNode;
2528
+ /**
2529
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
2530
+ *
2531
+ * Use this instead of bare strings when building `nodes` arrays so that every
2532
+ * entry in the array is a typed {@link CodeNode}.
2533
+ *
2534
+ * @example
2535
+ * ```ts
2536
+ * createText('return fetch(id)')
2537
+ * // { kind: 'Text', value: 'return fetch(id)' }
2538
+ * ```
2539
+ */
2540
+ declare function createText(value: string): TextNode;
2541
+ /**
2542
+ * Creates a {@link BreakNode} representing a line break in the source output.
2543
+ *
2544
+ * Corresponds to `<br/>` in JSX components. Prints as an empty string which,
2545
+ * when joined with `\n` by `printNodes`, produces a blank line.
2546
+ *
2547
+ * @example
2548
+ * ```ts
2549
+ * createBreak()
2550
+ * // { kind: 'Break' }
2551
+ * ```
2552
+ */
2553
+ declare function createBreak(): BreakNode;
2554
+ /**
2555
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
2556
+ *
2557
+ * Use this to embed JSX markup (including fragments `<>…</>`) directly in generated code.
2558
+ *
2559
+ * @example
2560
+ * ```ts
2561
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
2562
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
2563
+ * ```
2564
+ */
2565
+ declare function createJsx(value: string): JsxNode;
2566
+ //#endregion
4
2567
  //#region src/guards.d.ts
5
2568
  /**
6
- * Narrows a `SchemaNode` to the specific variant matching `type`.
2569
+ * Narrows a `SchemaNode` to the variant that matches `type`.
2570
+ *
2571
+ * @example
2572
+ * ```ts
2573
+ * const schema = createSchema({ type: 'string' })
2574
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | undefined
2575
+ * ```
7
2576
  */
8
2577
  declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | undefined;
9
2578
  /**
10
- * Type guard for `RootNode`.
2579
+ * Returns `true` when the input is an `InputNode`.
2580
+ *
2581
+ * @example
2582
+ * ```ts
2583
+ * if (isInputNode(node)) {
2584
+ * console.log(node.schemas.length)
2585
+ * }
2586
+ * ```
2587
+ */
2588
+ declare const isInputNode: (node: unknown) => node is InputNode;
2589
+ /**
2590
+ * Returns `true` when the input is an `OutputNode`.
2591
+ *
2592
+ * @example
2593
+ * ```ts
2594
+ * if (isOutputNode(node)) {
2595
+ * console.log(node.files.length)
2596
+ * }
2597
+ * ```
11
2598
  */
12
- declare const isRootNode: (node: unknown) => node is RootNode;
2599
+ declare const isOutputNode: (node: unknown) => node is OutputNode;
13
2600
  /**
14
- * Type guard for `OperationNode`.
2601
+ * Returns `true` when the input is an `OperationNode`.
2602
+ *
2603
+ * @example
2604
+ * ```ts
2605
+ * if (isOperationNode(node)) {
2606
+ * console.log(node.operationId)
2607
+ * }
2608
+ * ```
15
2609
  */
16
2610
  declare const isOperationNode: (node: unknown) => node is OperationNode;
17
2611
  /**
18
- * Type guard for `SchemaNode`.
2612
+ * Returns `true` when the input is a `SchemaNode`.
2613
+ *
2614
+ * @example
2615
+ * ```ts
2616
+ * if (isSchemaNode(node)) {
2617
+ * console.log(node.type)
2618
+ * }
2619
+ * ```
19
2620
  */
20
2621
  declare const isSchemaNode: (node: unknown) => node is SchemaNode;
2622
+ //#endregion
2623
+ //#region src/printer.d.ts
21
2624
  /**
22
- * Type guard for `PropertyNode`.
2625
+ * Runtime context passed as `this` to printer handlers.
2626
+ *
2627
+ * `this.transform` dispatches to node-level handlers from `nodes`.
2628
+ *
2629
+ * @example
2630
+ * ```ts
2631
+ * const context: PrinterHandlerContext<string, {}> = {
2632
+ * options: {},
2633
+ * transform: () => 'value',
2634
+ * }
2635
+ * ```
23
2636
  */
24
- declare const isPropertyNode: (node: unknown) => node is PropertyNode;
2637
+ type PrinterHandlerContext<TOutput, TOptions extends object> = {
2638
+ /**
2639
+ * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
2640
+ * Use `this.transform` inside `nodes` handlers and inside the `print` override.
2641
+ */
2642
+ transform: (node: SchemaNode) => TOutput | null | undefined;
2643
+ /**
2644
+ * Options for this printer instance.
2645
+ */
2646
+ options: TOptions;
2647
+ };
25
2648
  /**
26
- * Type guard for `ParameterNode`.
2649
+ * Handler for one schema node type.
2650
+ *
2651
+ * Use a regular function (not an arrow function) if you need `this`.
2652
+ *
2653
+ * @example
2654
+ * ```ts
2655
+ * const handler: PrinterHandler<string, {}, 'string'> = function () {
2656
+ * return 'string'
2657
+ * }
2658
+ * ```
27
2659
  */
28
- declare const isParameterNode: (node: unknown) => node is ParameterNode;
2660
+ type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null | undefined;
29
2661
  /**
30
- * Type guard for `ResponseNode`.
2662
+ * Partial map of per-node-type handler overrides for a printer.
2663
+ *
2664
+ * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
2665
+ * Supply only the handlers you want to replace; the printer's built-in
2666
+ * defaults fill in the rest.
2667
+ *
2668
+ * @example
2669
+ * ```ts
2670
+ * pluginZod({
2671
+ * printer: {
2672
+ * nodes: {
2673
+ * date(): string {
2674
+ * return 'z.string().date()'
2675
+ * },
2676
+ * } satisfies PrinterPartial<string, PrinterZodOptions>,
2677
+ * },
2678
+ * })
2679
+ * ```
2680
+ */
2681
+ type PrinterPartial<TOutput, TOptions extends object> = Partial<{ [K in SchemaType]: PrinterHandler<TOutput, TOptions, K> }>;
2682
+ /**
2683
+ * Generic shape used by `definePrinter`.
2684
+ *
2685
+ * - `TName` — unique string identifier (e.g. `'zod'`, `'ts'`)
2686
+ * - `TOptions` — options passed to and stored on the printer instance
2687
+ * - `TOutput` — the type emitted by node handlers
2688
+ * - `TPrintOutput` — type returned by public `print` (defaults to `TOutput`)
2689
+ *
2690
+ * @example
2691
+ * ```ts
2692
+ * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>
2693
+ * ```
2694
+ */
2695
+ type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
2696
+ name: TName;
2697
+ options: TOptions;
2698
+ output: TOutput;
2699
+ printOutput: TPrintOutput;
2700
+ };
2701
+ /**
2702
+ * Printer instance returned by a printer factory.
2703
+ *
2704
+ * @example
2705
+ * ```ts
2706
+ * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})
2707
+ * ```
2708
+ */
2709
+ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
2710
+ /**
2711
+ * Unique identifier supplied at creation time.
2712
+ */
2713
+ name: T['name'];
2714
+ /**
2715
+ * Options for this printer instance.
2716
+ */
2717
+ options: T['options'];
2718
+ /**
2719
+ * Node-level dispatcher — converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
2720
+ * Always dispatches through the `nodes` map; never calls the `print` override.
2721
+ * Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
2722
+ */
2723
+ transform: (node: SchemaNode) => T['output'] | null | undefined;
2724
+ /**
2725
+ * Public printer. If the builder provides a root-level `print`, this calls that
2726
+ * higher-level function (which may produce full declarations).
2727
+ * Otherwise, falls back to the node-level dispatcher.
2728
+ */
2729
+ print: (node: SchemaNode) => T['printOutput'] | null | undefined;
2730
+ };
2731
+ /**
2732
+ * Builder function passed to `definePrinter`.
2733
+ *
2734
+ * It receives resolved options and returns:
2735
+ * - `name`
2736
+ * - `options`
2737
+ * - `nodes` handlers
2738
+ * - optional top-level `print` override
2739
+ *
2740
+ * @example
2741
+ * ```ts
2742
+ * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })
2743
+ * ```
2744
+ */
2745
+ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
2746
+ name: T['name'];
2747
+ /**
2748
+ * Options to store on the printer.
2749
+ */
2750
+ options: T['options'];
2751
+ nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
2752
+ /**
2753
+ * Optional root-level print override. When provided, becomes the public `printer.print`.
2754
+ * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
2755
+ * not the override itself — so recursion is safe.
2756
+ */
2757
+ print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null;
2758
+ };
2759
+ /**
2760
+ * Creates a schema printer factory.
2761
+ *
2762
+ * This function wraps a builder and makes options optional at call sites.
2763
+ *
2764
+ * The builder receives resolved options and returns:
2765
+ * - `name` — a unique identifier for the printer
2766
+ * - `options` — options stored on the returned printer instance
2767
+ * - `nodes` — a map of `SchemaType` → handler functions that convert a `SchemaNode` to `TOutput`
2768
+ * - `print` _(optional)_ — top-level override exposed as `printer.print`
2769
+ * - Inside this function, use `this.transform(node)` to dispatch to the `nodes` map
2770
+ * - This keeps recursion safe and avoids self-calls
2771
+ *
2772
+ * When no `print` override is provided, `printer.print` falls back to `printer.transform` (the node-level dispatcher).
2773
+ *
2774
+ * @example Basic usage — Zod schema printer
2775
+ * ```ts
2776
+ * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
2777
+ *
2778
+ * export const zodPrinter = definePrinter<PrinterZod>((options) => ({
2779
+ * name: 'zod',
2780
+ * options: { strict: options.strict ?? true },
2781
+ * nodes: {
2782
+ * string: () => 'z.string()',
2783
+ * object(node) {
2784
+ * const props = node.properties.map(p => `${p.name}: ${this.transform(p.schema)}`).join(', ')
2785
+ * return `z.object({ ${props} })`
2786
+ * },
2787
+ * },
2788
+ * }))
2789
+ * ```
2790
+ */
2791
+ declare function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
2792
+ /**
2793
+ * Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.
2794
+ **
2795
+ * @example
2796
+ * ```ts
2797
+ * export const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>(
2798
+ * (node) => kindToHandlerKey[node.kind],
2799
+ * )
2800
+ * ```
2801
+ */
2802
+ declare function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | undefined): <T extends PrinterFactoryOptions>(build: (options: T["options"]) => {
2803
+ name: T["name"];
2804
+ options: T["options"];
2805
+ nodes: Partial<{ [K in TKey]: (this: {
2806
+ transform: (node: TNode) => T["output"] | null | undefined;
2807
+ options: T["options"];
2808
+ }, node: TNodeByKey[K]) => T["output"] | null | undefined }>;
2809
+ print?: (this: {
2810
+ transform: (node: TNode) => T["output"] | null | undefined;
2811
+ options: T["options"];
2812
+ }, node: TNode) => T["printOutput"] | null | undefined;
2813
+ }) => (options?: T["options"]) => {
2814
+ name: T["name"];
2815
+ options: T["options"];
2816
+ transform: (node: TNode) => T["output"] | null | undefined;
2817
+ print: (node: TNode) => T["printOutput"] | null | undefined;
2818
+ };
2819
+ //#endregion
2820
+ //#region src/refs.d.ts
2821
+ /**
2822
+ * Lookup map from schema name to `SchemaNode`.
2823
+ */
2824
+ type RefMap = Map<string, SchemaNode>;
2825
+ /**
2826
+ * Returns the last path segment of a reference string.
2827
+ *
2828
+ * Example: `#/components/schemas/Pet` becomes `Pet`.
2829
+ *
2830
+ * @example
2831
+ * ```ts
2832
+ * extractRefName('#/components/schemas/Pet') // 'Pet'
2833
+ * ```
2834
+ */
2835
+ declare function extractRefName(ref: string): string;
2836
+ //#endregion
2837
+ //#region src/resolvers.d.ts
2838
+ declare function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null;
2839
+ declare function childName(parentName: string | null | undefined, propName: string): string | null;
2840
+ declare function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string;
2841
+ /**
2842
+ * Collects import entries for all `ref` schema nodes in `node`.
2843
+ */
2844
+ declare function collectImports<TImport>({
2845
+ node,
2846
+ nameMapping,
2847
+ resolve
2848
+ }: {
2849
+ node: SchemaNode;
2850
+ nameMapping: Map<string, string>;
2851
+ resolve: (schemaName: string) => TImport | undefined;
2852
+ }): Array<TImport>;
2853
+ //#endregion
2854
+ //#region src/transformers.d.ts
2855
+ /**
2856
+ * Replaces a discriminator property's schema with a string enum of allowed values.
2857
+ *
2858
+ * If `node` is not an object schema, or if the property does not exist, the input
2859
+ * node is returned as-is.
2860
+ *
2861
+ * @example
2862
+ * ```ts
2863
+ * const schema = createSchema({
2864
+ * type: 'object',
2865
+ * properties: [createProperty({ name: 'type', required: true, schema: createSchema({ type: 'string' }) })],
2866
+ * })
2867
+ * const result = setDiscriminatorEnum({ node: schema, propertyName: 'type', values: ['dog', 'cat'] })
2868
+ * ```
2869
+ */
2870
+ declare function setDiscriminatorEnum({
2871
+ node,
2872
+ propertyName,
2873
+ values,
2874
+ enumName
2875
+ }: {
2876
+ node: SchemaNode;
2877
+ propertyName: string;
2878
+ values: Array<string>;
2879
+ enumName?: string;
2880
+ }): SchemaNode;
2881
+ /**
2882
+ * Merges adjacent anonymous object members into a single anonymous object member.
2883
+ *
2884
+ * @example
2885
+ * ```ts
2886
+ * const merged = mergeAdjacentObjects([
2887
+ * createSchema({ type: 'object', properties: [createProperty({ name: 'a', schema: createSchema({ type: 'string' }) })] }),
2888
+ * createSchema({ type: 'object', properties: [createProperty({ name: 'b', schema: createSchema({ type: 'number' }) })] }),
2889
+ * ])
2890
+ * ```
2891
+ */
2892
+ declare function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode>;
2893
+ /**
2894
+ * Removes enum members that are covered by broader scalar primitives in the same union.
2895
+ *
2896
+ * @example
2897
+ * ```ts
2898
+ * const simplified = simplifyUnion([
2899
+ * createSchema({ type: 'enum', primitive: 'string', enumValues: ['active'] }),
2900
+ * createSchema({ type: 'string' }),
2901
+ * ])
2902
+ * // keeps only string member
2903
+ * ```
2904
+ */
2905
+ declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
2906
+ declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
2907
+ //#endregion
2908
+ //#region src/visitor.d.ts
2909
+ /**
2910
+ * Ordered mapping of `[NodeType, ParentType]` pairs.
2911
+ *
2912
+ * `ParentOf` uses this map to find parent types.
2913
+ */
2914
+ type ParentNodeMap = [[InputNode, undefined], [OutputNode, undefined], [OperationNode, InputNode], [SchemaNode, InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode], [PropertyNode, SchemaNode], [ParameterNode, OperationNode], [ResponseNode, OperationNode]];
2915
+ /**
2916
+ * Resolves the parent node type for a given AST node type.
2917
+ *
2918
+ * This is used by visitor context so `ctx.parent` is correctly typed
2919
+ * for each callback.
2920
+ *
2921
+ * @example
2922
+ * ```ts
2923
+ * type InputParent = ParentOf<InputNode>
2924
+ * // undefined
2925
+ * ```
2926
+ *
2927
+ * @example
2928
+ * ```ts
2929
+ * type PropertyParent = ParentOf<PropertyNode>
2930
+ * // SchemaNode
2931
+ * ```
2932
+ *
2933
+ * @example
2934
+ * ```ts
2935
+ * type SchemaParent = ParentOf<SchemaNode>
2936
+ * // InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode
2937
+ * ```
2938
+ */
2939
+ type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> = ParentNodeMap> = TEntries extends [infer TEntry extends [Node, unknown], ...infer TRest extends ReadonlyArray<[Node, unknown]>] ? T extends TEntry[0] ? TEntry[1] : ParentOf<T, TRest> : Node;
2940
+ /**
2941
+ * Traversal context passed as the second argument to every visitor callback.
2942
+ * `parent` is typed from the current node type.
2943
+ *
2944
+ * @example
2945
+ * ```ts
2946
+ * const visitor: Visitor = {
2947
+ * schema(node, { parent }) {
2948
+ * // parent type is narrowed by node kind
2949
+ * },
2950
+ * }
2951
+ * ```
2952
+ */
2953
+ type VisitorContext<T extends Node = Node> = {
2954
+ /**
2955
+ * Parent node of the currently visited node.
2956
+ * For `InputNode`, this is `undefined`.
2957
+ */
2958
+ parent?: ParentOf<T>;
2959
+ };
2960
+ /**
2961
+ * Synchronous visitor used by `transform`.
2962
+ *
2963
+ * @example
2964
+ * ```ts
2965
+ * const visitor: Visitor = {
2966
+ * operation(node) {
2967
+ * return { ...node, operationId: `x_${node.operationId}` }
2968
+ * },
2969
+ * }
2970
+ * ```
2971
+ */
2972
+ type Visitor = {
2973
+ input?(node: InputNode, context: VisitorContext<InputNode>): void | InputNode;
2974
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): void | OutputNode;
2975
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): void | OperationNode;
2976
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): void | SchemaNode;
2977
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): void | PropertyNode;
2978
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): void | ParameterNode;
2979
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): void | ResponseNode;
2980
+ };
2981
+ /**
2982
+ * Utility type for values that can be returned directly or asynchronously.
2983
+ */
2984
+ type MaybePromise<T> = T | Promise<T>;
2985
+ /**
2986
+ * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
2987
+ *
2988
+ * @example
2989
+ * ```ts
2990
+ * const visitor: AsyncVisitor = {
2991
+ * async operation(node) {
2992
+ * await Promise.resolve(node.operationId)
2993
+ * },
2994
+ * }
2995
+ * ```
31
2996
  */
32
- declare const isResponseNode: (node: unknown) => node is ResponseNode;
2997
+ type AsyncVisitor = {
2998
+ input?(node: InputNode, context: VisitorContext<InputNode>): MaybePromise<void | InputNode>;
2999
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): MaybePromise<void | OutputNode>;
3000
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<void | OperationNode>;
3001
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<void | SchemaNode>;
3002
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<void | PropertyNode>;
3003
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<void | ParameterNode>;
3004
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<void | ResponseNode>;
3005
+ };
3006
+ /**
3007
+ * Visitor used by `collect`.
3008
+ *
3009
+ * @example
3010
+ * ```ts
3011
+ * const visitor: CollectVisitor<string> = {
3012
+ * operation(node) {
3013
+ * return node.operationId
3014
+ * },
3015
+ * }
3016
+ * ```
3017
+ */
3018
+ type CollectVisitor<T> = {
3019
+ input?(node: InputNode, context: VisitorContext<InputNode>): T | undefined;
3020
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): T | undefined;
3021
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined;
3022
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined;
3023
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined;
3024
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | undefined;
3025
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | undefined;
3026
+ };
3027
+ /**
3028
+ * Options for `transform`.
3029
+ *
3030
+ * @example
3031
+ * ```ts
3032
+ * const options: TransformOptions = { depth: 'deep', schema: (node) => node }
3033
+ * ```
3034
+ *
3035
+ * @example
3036
+ * ```ts
3037
+ * // Only transform the current node, not nested children
3038
+ * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
3039
+ * ```
3040
+ */
3041
+ type TransformOptions = Visitor & {
3042
+ /**
3043
+ * Traversal depth (`'deep'` by default).
3044
+ * @default 'deep'
3045
+ */
3046
+ depth?: VisitorDepth;
3047
+ /**
3048
+ * Internal parent override used during recursion.
3049
+ */
3050
+ parent?: Node;
3051
+ };
3052
+ /**
3053
+ * Options for `walk`.
3054
+ *
3055
+ * @example
3056
+ * ```ts
3057
+ * const options: WalkOptions = { depth: 'deep', concurrency: 10, root: () => {} }
3058
+ * ```
3059
+ */
3060
+ type WalkOptions = AsyncVisitor & {
3061
+ /**
3062
+ * Traversal depth (`'deep'` by default).
3063
+ * @default 'deep'
3064
+ */
3065
+ depth?: VisitorDepth;
3066
+ /**
3067
+ * Maximum number of sibling nodes visited concurrently.
3068
+ * @default 30
3069
+ */
3070
+ concurrency?: number;
3071
+ };
3072
+ /**
3073
+ * Options for `collect`.
3074
+ *
3075
+ * @example
3076
+ * ```ts
3077
+ * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
3078
+ * ```
3079
+ */
3080
+ type CollectOptions<T> = CollectVisitor<T> & {
3081
+ /**
3082
+ * Traversal depth (`'deep'` by default).
3083
+ * @default 'deep'
3084
+ */
3085
+ depth?: VisitorDepth;
3086
+ /**
3087
+ * Internal parent override used during recursion.
3088
+ */
3089
+ parent?: Node;
3090
+ };
3091
+ /**
3092
+ * Depth-first traversal for side effects. Visitor return values are ignored.
3093
+ * Sibling nodes at each level are visited concurrently up to `options.concurrency`
3094
+ * (default: `WALK_CONCURRENCY`).
3095
+ *
3096
+ * @example
3097
+ * ```ts
3098
+ * await walk(root, {
3099
+ * operation(node) {
3100
+ * console.log(node.operationId)
3101
+ * },
3102
+ * })
3103
+ * ```
3104
+ *
3105
+ * @example
3106
+ * ```ts
3107
+ * // Visit only the current node
3108
+ * await walk(root, { depth: 'shallow', root: () => {} })
3109
+ * ```
3110
+ */
3111
+ declare function walk(node: Node, options: WalkOptions): Promise<void>;
3112
+ /**
3113
+ * Runs a depth-first immutable transform.
3114
+ *
3115
+ * If a visitor returns a node, it replaces the current node.
3116
+ * If it returns `undefined`, the current node stays the same.
3117
+ *
3118
+ * @example
3119
+ * ```ts
3120
+ * const next = transform(root, {
3121
+ * operation(node) {
3122
+ * return { ...node, operationId: `prefixed_${node.operationId}` }
3123
+ * },
3124
+ * })
3125
+ * ```
3126
+ *
3127
+ * @example
3128
+ * ```ts
3129
+ * // Shallow mode: only transform the input node
3130
+ * const next = transform(root, { depth: 'shallow', root: (node) => node })
3131
+ * ```
3132
+ */
3133
+ declare function transform(node: InputNode, options: TransformOptions): InputNode;
3134
+ declare function transform(node: OutputNode, options: TransformOptions): OutputNode;
3135
+ declare function transform(node: OperationNode, options: TransformOptions): OperationNode;
3136
+ declare function transform(node: SchemaNode, options: TransformOptions): SchemaNode;
3137
+ declare function transform(node: PropertyNode, options: TransformOptions): PropertyNode;
3138
+ declare function transform(node: ParameterNode, options: TransformOptions): ParameterNode;
3139
+ declare function transform(node: ResponseNode, options: TransformOptions): ResponseNode;
3140
+ declare function transform(node: Node, options: TransformOptions): Node;
3141
+ /**
3142
+ * Runs a depth-first synchronous collection pass.
3143
+ *
3144
+ * Non-`undefined` values returned by visitor callbacks are appended to the result.
3145
+ *
3146
+ * @example
3147
+ * ```ts
3148
+ * const ids = collect(root, {
3149
+ * operation(node) {
3150
+ * return node.operationId
3151
+ * },
3152
+ * })
3153
+ * ```
3154
+ *
3155
+ * @example
3156
+ * ```ts
3157
+ * // Collect from only the current node
3158
+ * const values = collect(root, { depth: 'shallow', root: () => 'root' })
3159
+ * ```
3160
+ */
3161
+ declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
33
3162
  //#endregion
34
3163
  //#region src/utils.d.ts
35
3164
  /**
36
- * Returns `true` when a schema node will be represented as a plain string in generated code.
3165
+ * Returns a merged schema view for a ref node, combining the resolved `node.schema`
3166
+ * (base from the referenced definition) with any usage-site sibling fields set directly
3167
+ * on the ref node (description, readOnly, nullable, deprecated, etc.).
3168
+ *
3169
+ * Usage-site fields take precedence over the resolved schema's own fields when both are defined.
3170
+ *
3171
+ * For non-ref nodes the node itself is returned unchanged.
3172
+ */
3173
+ declare function syncSchemaRef(node: SchemaNode): SchemaNode;
3174
+ /**
3175
+ * Returns `true` when a schema is emitted as a plain `string` type.
37
3176
  *
38
3177
  * - `string`, `uuid`, `email`, `url`, `datetime` are always plain strings.
39
3178
  * - `date` and `time` are plain strings when their `representation` is `'string'` rather than `'date'`.
3179
+ *
3180
+ * @example
3181
+ * ```ts
3182
+ * isStringType(createSchema({ type: 'uuid' })) // true
3183
+ * isStringType(createSchema({ type: 'date', representation: 'date' })) // false
3184
+ * ```
40
3185
  */
41
- declare function isPlainStringType(node: SchemaNode): boolean;
3186
+ declare function isStringType(node: SchemaNode): boolean;
42
3187
  /**
43
- * Transforms the `name` field of each parameter node according to the given casing strategy.
3188
+ * Applies casing rules to parameter names and returns a new parameter array.
44
3189
  *
45
- * The original `params` array is never mutated — a new array of cloned nodes is returned.
46
- * When no `casing` is provided the original array is returned as-is.
3190
+ * The input array is not mutated.
3191
+ * If `casing` is not set, the original array is returned unchanged.
47
3192
  *
48
3193
  * Use this before passing parameters to schema builders so that property keys
49
- * in the generated output match the desired casing while the original
50
- * `OperationNode.parameters` array remains untouched for other consumers.
3194
+ * in generated output match the desired casing while preserving
3195
+ * `OperationNode.parameters` for other consumers.
3196
+ *
3197
+ * @example
3198
+ * ```ts
3199
+ * const params = [createParameter({ name: 'pet_id', in: 'query', schema: createSchema({ type: 'string' }) })]
3200
+ * const cased = caseParams(params, 'camelcase')
3201
+ * // cased[0].name === 'petId'
3202
+ * ```
3203
+ */
3204
+ declare function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode>;
3205
+ /**
3206
+ * Creates a single-property object schema used as a discriminator literal.
3207
+ *
3208
+ * @example
3209
+ * ```ts
3210
+ * createDiscriminantNode({ propertyName: 'type', value: 'dog' })
3211
+ * // -> { type: 'object', properties: [{ name: 'type', required: true, schema: enum('dog') }] }
3212
+ * ```
3213
+ */
3214
+ declare function createDiscriminantNode({
3215
+ propertyName,
3216
+ value
3217
+ }: {
3218
+ propertyName: string;
3219
+ value: string;
3220
+ }): SchemaNode;
3221
+ /**
3222
+ * Resolver interface for {@link createOperationParams}.
3223
+ *
3224
+ * `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.
3225
+ */
3226
+ type OperationParamsResolver = {
3227
+ /**
3228
+ * Resolves the type name for an individual parameter.
3229
+ *
3230
+ * @example Individual path parameter name
3231
+ * `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`
3232
+ */
3233
+ resolveParamName(node: OperationNode, param: ParameterNode): string;
3234
+ /**
3235
+ * Resolves the request body type name.
3236
+ *
3237
+ * @example Request body type name
3238
+ * `resolver.resolveDataName(node) // → 'CreatePetData'`
3239
+ */
3240
+ resolveDataName(node: OperationNode): string;
3241
+ /**
3242
+ * Resolves the grouped path parameters type name.
3243
+ * When the return value equals `resolveParamName`, no indexed access is emitted.
3244
+ *
3245
+ * @example Grouped path params type name
3246
+ * `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`
3247
+ */
3248
+ resolvePathParamsName(node: OperationNode, param: ParameterNode): string;
3249
+ /**
3250
+ * Resolves the grouped query parameters type name.
3251
+ * When the return value equals `resolveParamName`, an inline struct type is emitted instead.
3252
+ *
3253
+ * @example Grouped query params type name
3254
+ * `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`
3255
+ */
3256
+ resolveQueryParamsName(node: OperationNode, param: ParameterNode): string;
3257
+ /**
3258
+ * Resolves the grouped header parameters type name.
3259
+ * When the return value equals `resolveParamName`, an inline struct type is emitted instead.
3260
+ *
3261
+ * @example Grouped header params type name
3262
+ * `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`
3263
+ */
3264
+ resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string;
3265
+ };
3266
+ /**
3267
+ * Options for {@link createOperationParams}.
3268
+ */
3269
+ type CreateOperationParamsOptions = {
3270
+ /**
3271
+ * How all operation parameters are grouped in the function signature.
3272
+ * - `'object'` wraps all params into a single destructured object `{ petId, data, params }`
3273
+ * - `'inline'` emits each param category as a separate top-level parameter
3274
+ */
3275
+ paramsType: 'object' | 'inline';
3276
+ /**
3277
+ * How path parameters are emitted when `paramsType` is `'inline'`.
3278
+ * - `'object'` groups them as `{ petId, storeId }: PathParams`
3279
+ * - `'inline'` spreads them as individual parameters `petId: string, storeId: string`
3280
+ * - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`
3281
+ */
3282
+ pathParamsType: 'object' | 'inline' | 'inlineSpread';
3283
+ /**
3284
+ * Converts parameter names to camelCase before output.
3285
+ */
3286
+ paramsCasing?: 'camelcase';
3287
+ /**
3288
+ * Resolver for parameter and request body type names.
3289
+ * Pass `ResolverTs` from `@kubb/plugin-ts` directly.
3290
+ * When omitted, falls back to the schema primitive or `'unknown'`.
3291
+ */
3292
+ resolver?: OperationParamsResolver;
3293
+ /**
3294
+ * Default value for the path parameters binding when `pathParamsType` is `'object'`.
3295
+ * Falls back to `'{}'` when all path params are optional.
3296
+ */
3297
+ pathParamsDefault?: string;
3298
+ /**
3299
+ * Extra parameters appended after the standard operation parameters.
3300
+ *
3301
+ * @example Plugin-specific trailing parameter
3302
+ * ```ts
3303
+ * extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]
3304
+ * ```
3305
+ */
3306
+ extraParams?: Array<FunctionParameterNode | ParameterGroupNode>;
3307
+ /**
3308
+ * Override the default parameter names used for body, query, header, and rest-path groups.
3309
+ *
3310
+ * Useful when targeting languages or frameworks with different naming conventions.
3311
+ *
3312
+ * @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }
3313
+ */
3314
+ paramNames?: {
3315
+ /**
3316
+ * Name for the request body parameter.
3317
+ * @default 'data'
3318
+ */
3319
+ data?: string;
3320
+ /**
3321
+ * Name for the query parameters group parameter.
3322
+ * @default 'params'
3323
+ */
3324
+ params?: string;
3325
+ /**
3326
+ * Name for the header parameters group parameter.
3327
+ * @default 'headers'
3328
+ */
3329
+ headers?: string;
3330
+ /**
3331
+ * Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.
3332
+ * @default 'pathParams'
3333
+ */
3334
+ path?: string;
3335
+ };
3336
+ /**
3337
+ * Applies a uniform transformation to every resolved type name before it is used
3338
+ * in a parameter node. Use this for framework-level type wrappers.
3339
+ *
3340
+ * @example Vue Query — wrap every parameter type with `MaybeRefOrGetter`
3341
+ * `typeWrapper: (t) => \`MaybeRefOrGetter<${t}>\``
3342
+ */
3343
+ typeWrapper?: (type: string) => string;
3344
+ };
3345
+ /**
3346
+ * Converts an {@link OperationNode} into a {@link FunctionParametersNode}.
3347
+ *
3348
+ * Centralizes the per-plugin `getParams()` pattern. Provide a `resolver` for
3349
+ * type resolution and `extraParams` for plugin-specific trailing parameters.
3350
+ *
3351
+ * @example
3352
+ * ```ts
3353
+ * const params = createOperationParams(node, {
3354
+ * paramsType: 'inline',
3355
+ * pathParamsType: 'inline',
3356
+ * resolver: tsResolver,
3357
+ * extraParams: [createFunctionParameter({ name: 'options', type: createParamsType({ variant: 'reference', name: 'Partial<RequestOptions>' }), default: '{}' })],
3358
+ * })
3359
+ * ```
3360
+ */
3361
+ declare function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
3362
+ /**
3363
+ * Recursively extracts all string content embedded in a {@link CodeNode} tree.
3364
+ *
3365
+ * Includes text node values, and string attribute fields (`params`, `generics`,
3366
+ * `returnType`, `type`) that may reference identifiers needing imports.
3367
+ * Used by `createFile` to build the full source string for import filtering.
3368
+ */
3369
+ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
3370
+ /**
3371
+ * Resolves the referenced schema name of a `ref` node, falling back through
3372
+ * `ref` → `name` → nested `schema.name`. Returns `undefined` for non-ref
3373
+ * nodes or when no name can be resolved.
3374
+ *
3375
+ * @example
3376
+ * ```ts
3377
+ * resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })
3378
+ * // => 'Pet'
3379
+ * ```
3380
+ */
3381
+ declare function resolveRefName(node: SchemaNode | undefined): string | undefined;
3382
+ /**
3383
+ * Recursively collects every named schema referenced (transitively) from
3384
+ * `node` via `ref` edges. Refs are followed by name only — the resolved
3385
+ * `node.schema` of a ref is not traversed inline.
3386
+ *
3387
+ * @example
3388
+ * ```ts
3389
+ * const refs = collectReferencedSchemaNames(petSchema)
3390
+ * // => Set { 'Cat', 'Dog' }
3391
+ * ```
3392
+ */
3393
+ declare function collectReferencedSchemaNames(node: SchemaNode | undefined, out?: Set<string>): Set<string>;
3394
+ /**
3395
+ * Identifies every named schema that participates in a circular dependency
3396
+ * chain — including direct self-loops (e.g. `TreeNode → TreeNode`) and indirect
3397
+ * cycles spanning multiple schemas (e.g. `Pet → Cat → Pet`).
3398
+ *
3399
+ * The returned set contains schema names. Plugins that translate schemas into
3400
+ * a host language can use this to wrap recursive positions in a deferred
3401
+ * construct (lazy getter, `z.lazy(() => …)`, etc.) and avoid runtime stack
3402
+ * overflows when the generated code is executed.
3403
+ *
3404
+ * Refs are followed by name only — `node.schema` (the resolved referent) is
3405
+ * not traversed inline, which keeps the algorithm linear in the size of the
3406
+ * schema graph.
3407
+ *
3408
+ * @example
3409
+ * ```ts
3410
+ * const circular = findCircularSchemas(inputNode.schemas)
3411
+ * if (circular.has('Pet')) {
3412
+ * // emit lazy wrapper for any property whose schema references Pet
3413
+ * }
3414
+ * ```
3415
+ */
3416
+ declare function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string>;
3417
+ /**
3418
+ * Returns true when `node` (or anything nested within it) carries a `ref`
3419
+ * whose resolved name belongs to `circularSchemas`.
3420
+ *
3421
+ * When `excludeName` is provided, refs to that name are ignored — useful
3422
+ * when self-references are already handled separately from cross-schema
3423
+ * cycles (e.g. the faker plugin emits `undefined as any` for direct
3424
+ * self-recursion but a lazy getter for indirect cycles).
3425
+ *
3426
+ * @example
3427
+ * ```ts
3428
+ * const circular = findCircularSchemas(schemas)
3429
+ * if (containsCircularRef(property.schema, { circularSchemas: circular, excludeName: 'Pet' })) {
3430
+ * // emit `get foo() { return fakeCat() }` instead of eager call
3431
+ * }
3432
+ * ```
51
3433
  */
52
- declare function applyParamsCasing(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode>;
3434
+ declare function containsCircularRef(node: SchemaNode | undefined, {
3435
+ circularSchemas,
3436
+ excludeName
3437
+ }: {
3438
+ circularSchemas: ReadonlySet<string>;
3439
+ excludeName?: string;
3440
+ }): boolean;
53
3441
  //#endregion
54
- export { applyParamsCasing, buildRefMap, collect, createOperation, createParameter, createProperty, createResponse, createRoot, createSchema, definePrinter, httpMethods, isOperationNode, isParameterNode, isPlainStringType, isPropertyNode, isResponseNode, isRootNode, isSchemaNode, mediaTypes, narrowSchema, nodeKinds, refMapToObject, resolveRef, schemaTypes, transform, walk };
3442
+ export { type ArraySchemaNode, type ArrowFunctionNode, AsyncVisitor, type BaseNode, type BreakNode, type CodeNode, CollectOptions, CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, InferSchema, InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, OperationParamsResolver, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, ParentOf, ParserOptions, type PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, type PropertyNode, RefMap, type RefSchemaNode, type ResponseNode, ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, UserFileNode, Visitor, VisitorContext, VisitorDepth, WalkOptions, caseParams, childName, collect, collectImports, collectReferencedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createText, createType, definePrinter, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
55
3443
  //# sourceMappingURL=index.d.ts.map