@kubb/ast 5.0.0-alpha.3 → 5.0.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2200 @@
1
+ import { t as __name } from "./chunk--u3MIqq1.js";
2
+
3
+ //#region src/constants.d.ts
4
+ /**
5
+ * Traversal depth used by AST visitor utilities.
6
+ */
7
+ type VisitorDepth = 'shallow' | 'deep';
8
+ /**
9
+ * Canonical schema type strings used by AST schema nodes.
10
+ *
11
+ * These values are used across the AST as stable discriminators
12
+ * (for example `schema.type === schemaTypes.object`).
13
+ *
14
+ * The map is grouped by intent:
15
+ * - primitives (`string`, `number`, `boolean`, ...)
16
+ * - structural/composite (`object`, `array`, `union`, ...)
17
+ * - special OpenAPI-oriented types (`ref`, `datetime`, `uuid`, ...)
18
+ */
19
+ declare const schemaTypes: {
20
+ /**
21
+ * Text value.
22
+ */
23
+ readonly string: "string";
24
+ /**
25
+ * Floating-point number (`float`, `double`).
26
+ */
27
+ readonly number: "number";
28
+ /**
29
+ * Whole number (`int32`). Use `bigint` for `int64`.
30
+ */
31
+ readonly integer: "integer";
32
+ /**
33
+ * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
34
+ */
35
+ readonly bigint: "bigint";
36
+ /**
37
+ * Boolean value
38
+ */
39
+ readonly boolean: "boolean";
40
+ /**
41
+ * Explicit null value.
42
+ */
43
+ readonly null: "null";
44
+ /**
45
+ * Any value (no type restriction).
46
+ */
47
+ readonly any: "any";
48
+ /**
49
+ * Unknown value (must be narrowed before usage).
50
+ */
51
+ readonly unknown: "unknown";
52
+ /**
53
+ * No return value (`void`).
54
+ */
55
+ readonly void: "void";
56
+ /**
57
+ * Object with named properties.
58
+ */
59
+ readonly object: "object";
60
+ /**
61
+ * Sequential list of items.
62
+ */
63
+ readonly array: "array";
64
+ /**
65
+ * Fixed-length list with position-specific items.
66
+ */
67
+ readonly tuple: "tuple";
68
+ /**
69
+ * "One of" multiple schema members.
70
+ */
71
+ readonly union: "union";
72
+ /**
73
+ * "All of" multiple schema members.
74
+ */
75
+ readonly intersection: "intersection";
76
+ /**
77
+ * Enum schema.
78
+ */
79
+ readonly enum: "enum";
80
+ /**
81
+ * Reference to another schema.
82
+ */
83
+ readonly ref: "ref";
84
+ /**
85
+ * Calendar date (for example `2026-03-24`).
86
+ */
87
+ readonly date: "date";
88
+ /**
89
+ * Date-time value (for example `2026-03-24T09:00:00Z`).
90
+ */
91
+ readonly datetime: "datetime";
92
+ /**
93
+ * Time-only value (for example `09:00:00`).
94
+ */
95
+ readonly time: "time";
96
+ /**
97
+ * UUID value.
98
+ */
99
+ readonly uuid: "uuid";
100
+ /**
101
+ * Email address value.
102
+ */
103
+ readonly email: "email";
104
+ /**
105
+ * URL value.
106
+ */
107
+ readonly url: "url";
108
+ /**
109
+ * IPv4 address value.
110
+ */
111
+ readonly ipv4: "ipv4";
112
+ /**
113
+ * IPv6 address value.
114
+ */
115
+ readonly ipv6: "ipv6";
116
+ /**
117
+ * Binary/blob value.
118
+ */
119
+ readonly blob: "blob";
120
+ /**
121
+ * Impossible value (`never`).
122
+ */
123
+ readonly never: "never";
124
+ };
125
+ type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean';
126
+ /**
127
+ * Returns `true` when `type` is a scalar primitive schema type.
128
+ */
129
+ declare function isScalarPrimitive(type: string): type is ScalarPrimitive;
130
+ declare const httpMethods: {
131
+ readonly get: "GET";
132
+ readonly post: "POST";
133
+ readonly put: "PUT";
134
+ readonly patch: "PATCH";
135
+ readonly delete: "DELETE";
136
+ readonly head: "HEAD";
137
+ readonly options: "OPTIONS";
138
+ readonly trace: "TRACE";
139
+ };
140
+ declare const mediaTypes: {
141
+ readonly applicationJson: "application/json";
142
+ readonly applicationXml: "application/xml";
143
+ readonly applicationFormUrlEncoded: "application/x-www-form-urlencoded";
144
+ readonly applicationOctetStream: "application/octet-stream";
145
+ readonly applicationPdf: "application/pdf";
146
+ readonly applicationZip: "application/zip";
147
+ readonly applicationGraphql: "application/graphql";
148
+ readonly multipartFormData: "multipart/form-data";
149
+ readonly textPlain: "text/plain";
150
+ readonly textHtml: "text/html";
151
+ readonly textCsv: "text/csv";
152
+ readonly textXml: "text/xml";
153
+ readonly imagePng: "image/png";
154
+ readonly imageJpeg: "image/jpeg";
155
+ readonly imageGif: "image/gif";
156
+ readonly imageWebp: "image/webp";
157
+ readonly imageSvgXml: "image/svg+xml";
158
+ readonly audioMpeg: "audio/mpeg";
159
+ readonly videoMp4: "video/mp4";
160
+ };
161
+ //#endregion
162
+ //#region src/nodes/base.d.ts
163
+ /**
164
+ * `kind` values used by AST nodes.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const kind: NodeKind = 'Schema'
169
+ * ```
170
+ */
171
+ type NodeKind = 'Root' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'FunctionParameter' | 'ParameterGroup' | 'FunctionParameters' | 'Type';
172
+ /**
173
+ * Base shape shared by all AST nodes.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const base: BaseNode = { kind: 'Root' }
178
+ * ```
179
+ */
180
+ type BaseNode = {
181
+ /**
182
+ * Node discriminator.
183
+ */
184
+ kind: NodeKind;
185
+ };
186
+ //#endregion
187
+ //#region src/nodes/function.d.ts
188
+ /**
189
+ * AST node representing a language-agnostic type expression produced during parameter resolution.
190
+ * Each language printer renders the variant into its own syntax.
191
+ *
192
+ * - `struct` — an inline anonymous type grouping named fields.
193
+ * TypeScript renders as `{ petId: string; name?: string }`, Python as a `TypedDict` reference.
194
+ * - `member` — a single named field accessed from a named group type.
195
+ * TypeScript renders as `PathParams['petId']`, C# as `PathParams.PetId`.
196
+ */
197
+ type TypeNode = BaseNode & {
198
+ /**
199
+ * Node kind.
200
+ */
201
+ kind: 'Type';
202
+ } & ({
203
+ /**
204
+ * Reference variant — a plain type name or identifier.
205
+ * TypeScript renders as-is, e.g. `string`, `QueryParams`, `Partial<Config>`.
206
+ */
207
+ variant: 'reference';
208
+ /**
209
+ * The full type name string, e.g. `'string'`, `'QueryParams'`, `'Partial<Config>'`.
210
+ */
211
+ name: string;
212
+ } | {
213
+ /**
214
+ * Struct variant — an inline anonymous type grouping named fields.
215
+ * TypeScript renders as `{ key: Type; other?: OtherType }`.
216
+ */
217
+ variant: 'struct';
218
+ /**
219
+ * Properties of the struct type.
220
+ */
221
+ properties: Array<{
222
+ name: string;
223
+ optional: boolean;
224
+ type: TypeNode;
225
+ }>;
226
+ } | {
227
+ /**
228
+ * Member variant — a single named field accessed from a group type.
229
+ * TypeScript renders as `Base['key']`.
230
+ */
231
+ variant: 'member';
232
+ /**
233
+ * Base type name, e.g. `'DeletePetPathParams'`.
234
+ */
235
+ base: string;
236
+ /**
237
+ * The field name to access, e.g. `'petId'`.
238
+ */
239
+ key: string;
240
+ });
241
+ /**
242
+ * AST node for one function parameter.
243
+ *
244
+ * @example Required parameter
245
+ * `name: Type`
246
+ *
247
+ * @example Optional parameter
248
+ * `name?: Type`
249
+ *
250
+ * @example Parameter with default value
251
+ * `name: Type = defaultValue`
252
+ *
253
+ * @example Rest parameter
254
+ * `...name: Type[]`
255
+ */
256
+ type FunctionParameterNode = BaseNode & {
257
+ /**
258
+ * Node kind.
259
+ */
260
+ kind: 'FunctionParameter';
261
+ /**
262
+ * Parameter name in the generated signature.
263
+ */
264
+ name: string;
265
+ /**
266
+ * Type annotation as a structured {@link TypeNode}.
267
+ * Omit for untyped output.
268
+ *
269
+ * @example Reference type node
270
+ * `{ kind: 'Type', variant: 'reference', name: 'string' }` → `petId: string`
271
+ *
272
+ * @example Struct type node
273
+ * `{ kind: 'Type', variant: 'struct', properties: [...] }` → `{ key: Type; other?: OtherType }`
274
+ *
275
+ * @example Member type node
276
+ * `{ kind: 'Type', variant: 'member', base: 'PathParams', key: 'petId' }` → `PathParams['petId']`
277
+ */
278
+ type?: TypeNode;
279
+ /**
280
+ * When `true` the parameter is emitted as a rest parameter.
281
+ *
282
+ * @example Rest parameter
283
+ * `...name: Type[]`
284
+ */
285
+ rest?: boolean;
286
+ }
287
+ /**
288
+ * Optional parameter — rendered with `?` and may be omitted by the caller.
289
+ * Cannot be combined with `default` because a defaulted parameter is already optional.
290
+ */
291
+ & ({
292
+ optional: true;
293
+ default?: never;
294
+ }
295
+ /**
296
+ * Required parameter, or a parameter with a default value.
297
+ *
298
+ * @example Required
299
+ * `name: Type`
300
+ *
301
+ * @example With default
302
+ * `name: Type = default`
303
+ */
304
+ | {
305
+ optional?: false;
306
+ default?: string;
307
+ });
308
+ /**
309
+ * AST node for a group of related function parameters treated as a single unit.
310
+ *
311
+ * Each language printer decides how to render this group:
312
+ * - TypeScript/JS: destructured object `{ key1, key2 }: { key1: Type1; key2: Type2 } = {}`
313
+ * - Python: keyword-only args or a typed dict parameter
314
+ * - C# / Kotlin: named record / data-class parameter
315
+ *
316
+ * When `inline` is `true`, the group is spread as individual top-level parameters
317
+ * rather than wrapped in a single grouped construct.
318
+ *
319
+ * @example Grouped destructuring
320
+ * `{ id, name }: { id: string; name: string } = {}`
321
+ *
322
+ * @example Inline (spread as individual parameters)
323
+ * `id: string, name: string`
324
+ */
325
+ type ParameterGroupNode = BaseNode & {
326
+ /**
327
+ * Node kind.
328
+ */
329
+ kind: 'ParameterGroup';
330
+ /**
331
+ * The individual parameters that form the group.
332
+ * Rendered as a destructured object or spread inline when `inline` is `true`.
333
+ */
334
+ properties: Array<FunctionParameterNode>;
335
+ /**
336
+ * Optional explicit type annotation for the whole group.
337
+ * When absent, printers auto-compute it from `properties`.
338
+ */
339
+ type?: TypeNode;
340
+ /**
341
+ * When `true`, `properties` are emitted as individual top-level parameters instead of
342
+ * being wrapped in a single grouped construct.
343
+ *
344
+ * @default false
345
+ */
346
+ inline?: boolean;
347
+ /**
348
+ * Whether the group as a whole is optional.
349
+ * If omitted, printers infer this from child properties.
350
+ */
351
+ optional?: boolean;
352
+ /**
353
+ * Default value for the group, written verbatim after `=`.
354
+ * Commonly `'{}'` to allow omitting the argument entirely.
355
+ */
356
+ default?: string;
357
+ };
358
+ /**
359
+ * AST node for a complete function parameter list.
360
+ *
361
+ * Printers are responsible for sorting (`required` → `optional` → `defaulted`).
362
+ * Nodes are plain immutable data.
363
+ *
364
+ * Renders differently depending on the output mode:
365
+ * - `declaration` → `(id: string, config: Config = {})` — function declaration parameters
366
+ * - `call` → `(id, { method, url })` — function call arguments
367
+ * - `keys` → `{ id, config }` — key names only (for destructuring)
368
+ * - `values` → `{ id: id, config: config }` — key → value pairs
369
+ */
370
+ type FunctionParametersNode = BaseNode & {
371
+ /**
372
+ * Node kind.
373
+ */
374
+ kind: 'FunctionParameters';
375
+ /**
376
+ * Ordered parameter nodes.
377
+ */
378
+ params: ReadonlyArray<FunctionParameterNode | ParameterGroupNode>;
379
+ };
380
+ /**
381
+ * The four function-signature AST node variants.
382
+ */
383
+ type FunctionNode = FunctionParameterNode | ParameterGroupNode | FunctionParametersNode | TypeNode;
384
+ /**
385
+ * Handler map keys — one per `FunctionNode` kind.
386
+ */
387
+ type FunctionNodeType = 'functionParameter' | 'parameterGroup' | 'functionParameters' | 'type';
388
+ //#endregion
389
+ //#region src/nodes/property.d.ts
390
+ /**
391
+ * AST node representing one named object property.
392
+ *
393
+ * @example
394
+ * ```ts
395
+ * const property: PropertyNode = {
396
+ * kind: 'Property',
397
+ * name: 'id',
398
+ * schema: createSchema({ type: 'integer' }),
399
+ * required: true,
400
+ * }
401
+ * ```
402
+ */
403
+ type PropertyNode = BaseNode & {
404
+ /**
405
+ * Node kind.
406
+ */
407
+ kind: 'Property';
408
+ /**
409
+ * Property key.
410
+ */
411
+ name: string;
412
+ /**
413
+ * Property schema.
414
+ */
415
+ schema: SchemaNode;
416
+ /**
417
+ * Whether the property is required.
418
+ */
419
+ required: boolean;
420
+ };
421
+ //#endregion
422
+ //#region src/nodes/schema.d.ts
423
+ type PrimitiveSchemaType =
424
+ /**
425
+ * Text value.
426
+ */
427
+ 'string'
428
+ /**
429
+ * Floating-point number.
430
+ */
431
+ | 'number'
432
+ /**
433
+ * Integer number.
434
+ */
435
+ | 'integer'
436
+ /**
437
+ * Big integer number.
438
+ */
439
+ | 'bigint'
440
+ /**
441
+ * Boolean value.
442
+ */
443
+ | 'boolean'
444
+ /**
445
+ * Null value.
446
+ */
447
+ | 'null'
448
+ /**
449
+ * Any value.
450
+ */
451
+ | 'any'
452
+ /**
453
+ * Unknown value.
454
+ */
455
+ | 'unknown'
456
+ /**
457
+ * No value (`void`).
458
+ */
459
+ | 'void'
460
+ /**
461
+ * Never value.
462
+ */
463
+ | 'never'
464
+ /**
465
+ * Object value.
466
+ */
467
+ | 'object'
468
+ /**
469
+ * Array value.
470
+ */
471
+ | 'array'
472
+ /**
473
+ * Date value.
474
+ */
475
+ | 'date';
476
+ /**
477
+ * Composite schema types.
478
+ */
479
+ type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum';
480
+ /**
481
+ * Schema types that need special handling in generators.
482
+ */
483
+ type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'ipv4' | 'ipv6' | 'blob';
484
+ /**
485
+ * All schema type strings.
486
+ */
487
+ type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType;
488
+ /**
489
+ * Scalar schema types without extra object/array/ref structure.
490
+ */
491
+ type ScalarSchemaType = Exclude<SchemaType, 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint' | 'url' | 'uuid' | 'email'>;
492
+ /**
493
+ * Fields shared by all schema nodes.
494
+ */
495
+ type SchemaNodeBase = BaseNode & {
496
+ /**
497
+ * Node kind.
498
+ */
499
+ kind: 'Schema';
500
+ /**
501
+ * Schema name for named definitions (for example, `"Pet"`).
502
+ * Inline schemas omit this field.
503
+ * `null` means kubb has processed this and determined there is no applicable name.
504
+ * `undefined` means the name has not been set yet.
505
+ */
506
+ name?: string | null;
507
+ /**
508
+ * Short schema title.
509
+ */
510
+ title?: string;
511
+ /**
512
+ * Schema description text.
513
+ */
514
+ description?: string;
515
+ /**
516
+ * Whether `null` is allowed.
517
+ */
518
+ nullable?: boolean;
519
+ /**
520
+ * Whether the field is optional.
521
+ */
522
+ optional?: boolean;
523
+ /**
524
+ * Both optional and nullable (`optional` + `nullable`).
525
+ */
526
+ nullish?: boolean;
527
+ /**
528
+ * Whether the schema is deprecated.
529
+ */
530
+ deprecated?: boolean;
531
+ /**
532
+ * Whether the schema is read-only.
533
+ */
534
+ readOnly?: boolean;
535
+ /**
536
+ * Whether the schema is write-only.
537
+ */
538
+ writeOnly?: boolean;
539
+ /**
540
+ * Default value.
541
+ */
542
+ default?: unknown;
543
+ /**
544
+ * Example value.
545
+ */
546
+ example?: unknown;
547
+ /**
548
+ * Base primitive type.
549
+ * For example, this is `'string'` for a `uuid` schema.
550
+ */
551
+ primitive?: PrimitiveSchemaType;
552
+ };
553
+ /**
554
+ * Object schema with ordered properties.
555
+ *
556
+ * @example
557
+ * ```ts
558
+ * const objectSchema: ObjectSchemaNode = {
559
+ * kind: 'Schema',
560
+ * type: 'object',
561
+ * properties: [],
562
+ * }
563
+ * ```
564
+ */
565
+ type ObjectSchemaNode = SchemaNodeBase & {
566
+ /**
567
+ * Schema type discriminator.
568
+ */
569
+ type: 'object';
570
+ /**
571
+ * Primitive type — always `'object'` for object schemas.
572
+ */
573
+ primitive: 'object';
574
+ /**
575
+ * Ordered object properties.
576
+ */
577
+ properties: Array<PropertyNode>;
578
+ /**
579
+ * Additional object properties behavior:
580
+ * - `true`: allow any value
581
+ * - `false`: reject unknown properties (maps to `.strict()` in Zod)
582
+ * - `SchemaNode`: allow values that match that schema
583
+ * - `undefined`: no additional properties constraint (open object)
584
+ */
585
+ additionalProperties?: SchemaNode | boolean;
586
+ /**
587
+ * Pattern-based property schemas.
588
+ */
589
+ patternProperties?: Record<string, SchemaNode>;
590
+ /**
591
+ * Minimum number of properties allowed.
592
+ */
593
+ minProperties?: number;
594
+ /**
595
+ * Maximum number of properties allowed.
596
+ */
597
+ maxProperties?: number;
598
+ };
599
+ /**
600
+ * Array-like schema (`array` or `tuple`).
601
+ *
602
+ * @example
603
+ * ```ts
604
+ * const arraySchema: ArraySchemaNode = {
605
+ * kind: 'Schema',
606
+ * type: 'array',
607
+ * items: [],
608
+ * }
609
+ * ```
610
+ */
611
+ type ArraySchemaNode = SchemaNodeBase & {
612
+ /**
613
+ * Schema type discriminator (`array` or `tuple`).
614
+ */
615
+ type: 'array' | 'tuple';
616
+ /**
617
+ * Item schemas.
618
+ */
619
+ items?: Array<SchemaNode>;
620
+ /**
621
+ * Tuple rest-item schema for elements beyond positional `items`.
622
+ */
623
+ rest?: SchemaNode;
624
+ /**
625
+ * Minimum item count (or tuple length).
626
+ */
627
+ min?: number;
628
+ /**
629
+ * Maximum item count (or tuple length).
630
+ */
631
+ max?: number;
632
+ /**
633
+ * Whether all items must be unique.
634
+ */
635
+ unique?: boolean;
636
+ };
637
+ /**
638
+ * Shared shape for union and intersection schemas.
639
+ */
640
+ type CompositeSchemaNodeBase = SchemaNodeBase & {
641
+ /**
642
+ * Member schemas.
643
+ */
644
+ members?: Array<SchemaNode>;
645
+ };
646
+ /**
647
+ * Union schema, often from `oneOf` or `anyOf`.
648
+ *
649
+ * @example
650
+ * ```ts
651
+ * const unionSchema: UnionSchemaNode = {
652
+ * kind: 'Schema',
653
+ * type: 'union',
654
+ * members: [],
655
+ * }
656
+ * ```
657
+ */
658
+ type UnionSchemaNode = CompositeSchemaNodeBase & {
659
+ /**
660
+ * Schema type discriminator.
661
+ */
662
+ type: 'union';
663
+ /**
664
+ * Discriminator property name from OpenAPI `discriminator.propertyName`.
665
+ */
666
+ discriminatorPropertyName?: string;
667
+ };
668
+ /**
669
+ * Intersection schema, often from `allOf`.
670
+ *
671
+ * @example
672
+ * ```ts
673
+ * const intersectionSchema: IntersectionSchemaNode = {
674
+ * kind: 'Schema',
675
+ * type: 'intersection',
676
+ * members: [],
677
+ * }
678
+ * ```
679
+ */
680
+ type IntersectionSchemaNode = CompositeSchemaNodeBase & {
681
+ /**
682
+ * Schema type discriminator.
683
+ */
684
+ type: 'intersection';
685
+ };
686
+ /**
687
+ * One named enum item.
688
+ */
689
+ type EnumValueNode = {
690
+ /**
691
+ * Enum item name.
692
+ */
693
+ name: string;
694
+ /**
695
+ * Enum item value.
696
+ */
697
+ value: string | number | boolean;
698
+ /**
699
+ * Primitive type of the enum value.
700
+ */
701
+ primitive: Extract<PrimitiveSchemaType, 'string' | 'number' | 'boolean'>;
702
+ };
703
+ /**
704
+ * Enum schema node.
705
+ *
706
+ * @example
707
+ * ```ts
708
+ * const enumSchema: EnumSchemaNode = {
709
+ * kind: 'Schema',
710
+ * type: 'enum',
711
+ * enumValues: ['a', 'b'],
712
+ * }
713
+ * ```
714
+ */
715
+ type EnumSchemaNode = SchemaNodeBase & {
716
+ /**
717
+ * Schema type discriminator.
718
+ */
719
+ type: 'enum';
720
+ /**
721
+ * Enum values in simple form.
722
+ */
723
+ enumValues?: Array<string | number | boolean | null>;
724
+ /**
725
+ * Enum values in named form.
726
+ * If present, this is used instead of `enumValues`.
727
+ */
728
+ namedEnumValues?: Array<EnumValueNode>;
729
+ };
730
+ /**
731
+ * Reference schema that points to another schema definition.
732
+ *
733
+ * @example
734
+ * ```ts
735
+ * const refSchema: RefSchemaNode = {
736
+ * kind: 'Schema',
737
+ * type: 'ref',
738
+ * ref: '#/components/schemas/Pet',
739
+ * }
740
+ * ```
741
+ */
742
+ type RefSchemaNode = SchemaNodeBase & {
743
+ /**
744
+ * Schema type discriminator.
745
+ */
746
+ type: 'ref';
747
+ /**
748
+ * Referenced schema name.
749
+ */
750
+ name?: string;
751
+ /**
752
+ * Original `$ref` path, for example, `#/components/schemas/Order`.
753
+ * Used to resolve names later.
754
+ */
755
+ ref?: string;
756
+ /**
757
+ * Pattern copied from a sibling `pattern` field.
758
+ */
759
+ pattern?: string;
760
+ /**
761
+ * The fully-parsed schema that this ref resolves to.
762
+ * Populated during OAS parsing when the referenced definition can be resolved.
763
+ * `undefined` when the ref cannot be resolved or is part of a circular chain.
764
+ *
765
+ * Useful for inspecting the referenced schema's structure (e.g. `primitive`, `properties`)
766
+ * without following the reference manually.
767
+ */
768
+ schema?: SchemaNode;
769
+ };
770
+ /**
771
+ * Datetime schema.
772
+ *
773
+ * @example
774
+ * ```ts
775
+ * const datetimeSchema: DatetimeSchemaNode = { kind: 'Schema', type: 'datetime' }
776
+ * ```
777
+ */
778
+ type DatetimeSchemaNode = SchemaNodeBase & {
779
+ /**
780
+ * Schema type discriminator.
781
+ */
782
+ type: 'datetime';
783
+ /**
784
+ * Whether the datetime includes a timezone offset (`dateType: 'stringOffset'`).
785
+ */
786
+ offset?: boolean;
787
+ /**
788
+ * Whether the datetime is local (no timezone, `dateType: 'stringLocal'`).
789
+ */
790
+ local?: boolean;
791
+ };
792
+ /**
793
+ * Shared base for `date` and `time` schemas.
794
+ */
795
+ type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
796
+ /**
797
+ * Schema type discriminator.
798
+ */
799
+ type: T;
800
+ /**
801
+ * Output representation in generated code.
802
+ */
803
+ representation: 'date' | 'string';
804
+ };
805
+ /**
806
+ * Date schema node.
807
+ *
808
+ * @example
809
+ * ```ts
810
+ * const dateSchema: DateSchemaNode = { kind: 'Schema', type: 'date', representation: 'string' }
811
+ * ```
812
+ */
813
+ type DateSchemaNode = TemporalSchemaNodeBase<'date'>;
814
+ /**
815
+ * Time schema node.
816
+ *
817
+ * @example
818
+ * ```ts
819
+ * const timeSchema: TimeSchemaNode = { kind: 'Schema', type: 'time', representation: 'string' }
820
+ * ```
821
+ */
822
+ type TimeSchemaNode = TemporalSchemaNodeBase<'time'>;
823
+ /**
824
+ * String schema node.
825
+ *
826
+ * @example
827
+ * ```ts
828
+ * const stringSchema: StringSchemaNode = { kind: 'Schema', type: 'string' }
829
+ * ```
830
+ */
831
+ type StringSchemaNode = SchemaNodeBase & {
832
+ /**
833
+ * Schema type discriminator.
834
+ */
835
+ type: 'string';
836
+ /**
837
+ * Minimum string length.
838
+ */
839
+ min?: number;
840
+ /**
841
+ * Maximum string length.
842
+ */
843
+ max?: number;
844
+ /**
845
+ * Regex pattern.
846
+ */
847
+ pattern?: string;
848
+ };
849
+ /**
850
+ * Numeric schema (`number`, `integer`, or `bigint`).
851
+ *
852
+ * @example
853
+ * ```ts
854
+ * const numberSchema: NumberSchemaNode = { kind: 'Schema', type: 'number' }
855
+ * ```
856
+ */
857
+ type NumberSchemaNode = SchemaNodeBase & {
858
+ /**
859
+ * Schema type discriminator.
860
+ */
861
+ type: 'number' | 'integer' | 'bigint';
862
+ /**
863
+ * Minimum value.
864
+ */
865
+ min?: number;
866
+ /**
867
+ * Maximum value.
868
+ */
869
+ max?: number;
870
+ /**
871
+ * Exclusive minimum value.
872
+ */
873
+ exclusiveMinimum?: number;
874
+ /**
875
+ * Exclusive maximum value.
876
+ */
877
+ exclusiveMaximum?: number;
878
+ /**
879
+ * The value must be a multiple of this number.
880
+ */
881
+ multipleOf?: number;
882
+ };
883
+ /**
884
+ * Scalar schema with no extra constraints.
885
+ *
886
+ * @example
887
+ * ```ts
888
+ * const anySchema: ScalarSchemaNode = { kind: 'Schema', type: 'any' }
889
+ * ```
890
+ */
891
+ type ScalarSchemaNode = SchemaNodeBase & {
892
+ /**
893
+ * Schema type discriminator.
894
+ */
895
+ type: ScalarSchemaType;
896
+ };
897
+ /**
898
+ * URL schema node.
899
+ * Can include an OpenAPI-style path template for template literal types.
900
+ *
901
+ * @example
902
+ * ```ts
903
+ * const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets/{petId}' }
904
+ * ```
905
+ */
906
+ type UrlSchemaNode = SchemaNodeBase & {
907
+ /**
908
+ * Schema type discriminator.
909
+ */
910
+ type: 'url';
911
+ /**
912
+ * OpenAPI-style path template, for example, `'/pets/{petId}'`.
913
+ */
914
+ path?: string;
915
+ /**
916
+ * Minimum string length.
917
+ */
918
+ min?: number;
919
+ /**
920
+ * Maximum string length.
921
+ */
922
+ max?: number;
923
+ };
924
+ /**
925
+ * Format-string schema for string-based formats that support length constraints.
926
+ *
927
+ * @example
928
+ * ```ts
929
+ * const uuidSchema: FormatStringSchemaNode = { kind: 'Schema', type: 'uuid', min: 36, max: 36 }
930
+ * ```
931
+ */
932
+ type FormatStringSchemaNode = SchemaNodeBase & {
933
+ /**
934
+ * Schema type discriminator.
935
+ */
936
+ type: 'uuid' | 'email';
937
+ /**
938
+ * Minimum string length.
939
+ */
940
+ min?: number;
941
+ /**
942
+ * Maximum string length.
943
+ */
944
+ max?: number;
945
+ };
946
+ /**
947
+ * IPv4 address schema node.
948
+ *
949
+ * @example
950
+ * ```ts
951
+ * const ipv4Schema: Ipv4SchemaNode = { kind: 'Schema', type: 'ipv4' }
952
+ * ```
953
+ */
954
+ type Ipv4SchemaNode = SchemaNodeBase & {
955
+ /**
956
+ * Schema type discriminator.
957
+ */
958
+ type: 'ipv4';
959
+ };
960
+ /**
961
+ * IPv6 address schema node.
962
+ *
963
+ * @example
964
+ * ```ts
965
+ * const ipv6Schema: Ipv6SchemaNode = { kind: 'Schema', type: 'ipv6' }
966
+ * ```
967
+ */
968
+ type Ipv6SchemaNode = SchemaNodeBase & {
969
+ /**
970
+ * Schema type discriminator.
971
+ */
972
+ type: 'ipv6';
973
+ };
974
+ /**
975
+ * Mapping from schema type literals to concrete schema node types.
976
+ * Used by `narrowSchema`.
977
+ */
978
+ type SchemaNodeByType = {
979
+ object: ObjectSchemaNode;
980
+ array: ArraySchemaNode;
981
+ tuple: ArraySchemaNode;
982
+ union: UnionSchemaNode;
983
+ intersection: IntersectionSchemaNode;
984
+ enum: EnumSchemaNode;
985
+ ref: RefSchemaNode;
986
+ datetime: DatetimeSchemaNode;
987
+ date: DateSchemaNode;
988
+ time: TimeSchemaNode;
989
+ string: StringSchemaNode;
990
+ number: NumberSchemaNode;
991
+ integer: NumberSchemaNode;
992
+ bigint: NumberSchemaNode;
993
+ boolean: ScalarSchemaNode;
994
+ null: ScalarSchemaNode;
995
+ any: ScalarSchemaNode;
996
+ unknown: ScalarSchemaNode;
997
+ void: ScalarSchemaNode;
998
+ never: ScalarSchemaNode;
999
+ uuid: FormatStringSchemaNode;
1000
+ email: FormatStringSchemaNode;
1001
+ url: UrlSchemaNode;
1002
+ ipv4: Ipv4SchemaNode;
1003
+ ipv6: Ipv6SchemaNode;
1004
+ blob: ScalarSchemaNode;
1005
+ };
1006
+ /**
1007
+ * Union of all schema node types.
1008
+ */
1009
+ type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | FormatStringSchemaNode | Ipv4SchemaNode | Ipv6SchemaNode | ScalarSchemaNode;
1010
+ //#endregion
1011
+ //#region src/nodes/parameter.d.ts
1012
+ type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
1013
+ /**
1014
+ * AST node representing one operation parameter.
1015
+ *
1016
+ * @example
1017
+ * ```ts
1018
+ * const param: ParameterNode = {
1019
+ * kind: 'Parameter',
1020
+ * name: 'petId',
1021
+ * in: 'path',
1022
+ * schema: createSchema({ type: 'string' }),
1023
+ * required: true,
1024
+ * }
1025
+ * ```
1026
+ */
1027
+ type ParameterNode = BaseNode & {
1028
+ /**
1029
+ * Node kind.
1030
+ */
1031
+ kind: 'Parameter';
1032
+ /**
1033
+ * Parameter name.
1034
+ */
1035
+ name: string;
1036
+ /**
1037
+ * Parameter location (`path`, `query`, `header`, or `cookie`).
1038
+ */
1039
+ in: ParameterLocation;
1040
+ /**
1041
+ * Parameter schema.
1042
+ */
1043
+ schema: SchemaNode;
1044
+ /**
1045
+ * Whether the parameter is required.
1046
+ */
1047
+ required: boolean;
1048
+ };
1049
+ //#endregion
1050
+ //#region src/nodes/http.d.ts
1051
+ /**
1052
+ * All supported HTTP status code literals as strings, as used in API specs
1053
+ * (for example, `"200"` and `"404"`).
1054
+ */
1055
+ 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';
1056
+ /**
1057
+ * Response status code literal used by operations.
1058
+ *
1059
+ * Includes specific HTTP status code strings and `"default"` for catch-all responses.
1060
+ *
1061
+ * @example
1062
+ * ```ts
1063
+ * const status: StatusCode = '200'
1064
+ * const fallback: StatusCode = 'default'
1065
+ * ```
1066
+ */
1067
+ type StatusCode = HttpStatusCode | 'default';
1068
+ /**
1069
+ * Supported media type strings used in request and response bodies.
1070
+ *
1071
+ * @example
1072
+ * ```ts
1073
+ * const mediaType: MediaType = 'application/json'
1074
+ * ```
1075
+ */
1076
+ 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';
1077
+ //#endregion
1078
+ //#region src/nodes/response.d.ts
1079
+ /**
1080
+ * AST node representing one operation response variant.
1081
+ *
1082
+ * @example
1083
+ * ```ts
1084
+ * const response: ResponseNode = {
1085
+ * kind: 'Response',
1086
+ * statusCode: '200',
1087
+ * schema: createSchema({ type: 'string' }),
1088
+ * }
1089
+ * ```
1090
+ */
1091
+ type ResponseNode = BaseNode & {
1092
+ /**
1093
+ * Node kind.
1094
+ */
1095
+ kind: 'Response';
1096
+ /**
1097
+ * HTTP status code or `'default'` for a fallback response.
1098
+ */
1099
+ statusCode: StatusCode;
1100
+ /**
1101
+ * Optional response description.
1102
+ */
1103
+ description?: string;
1104
+ /**
1105
+ * Response body schema.
1106
+ */
1107
+ schema: SchemaNode;
1108
+ /**
1109
+ * Response media type.
1110
+ */
1111
+ mediaType?: MediaType | null;
1112
+ /**
1113
+ * Property keys to exclude from the generated type via `Omit<Type, Keys>`.
1114
+ * Set when a referenced schema has `writeOnly` fields that should not appear in response types.
1115
+ */
1116
+ keysToOmit?: Array<string>;
1117
+ };
1118
+ //#endregion
1119
+ //#region src/nodes/operation.d.ts
1120
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
1121
+ /**
1122
+ * AST node representing one API operation.
1123
+ *
1124
+ * @example
1125
+ * ```ts
1126
+ * const operation: OperationNode = {
1127
+ * kind: 'Operation',
1128
+ * operationId: 'listPets',
1129
+ * method: 'GET',
1130
+ * path: '/pets',
1131
+ * tags: [],
1132
+ * parameters: [],
1133
+ * responses: [],
1134
+ * }
1135
+ * ```
1136
+ */
1137
+ type OperationNode = BaseNode & {
1138
+ /**
1139
+ * Node kind.
1140
+ */
1141
+ kind: 'Operation';
1142
+ /**
1143
+ * Operation identifier, usually from OpenAPI `operationId`.
1144
+ */
1145
+ operationId: string;
1146
+ /**
1147
+ * HTTP Method like 'GET'
1148
+ */
1149
+ method: HttpMethod;
1150
+ /**
1151
+ * OpenAPI-style path string, for example `/pets/{petId}`.
1152
+ * Path parameters retain the `{param}` notation from the original spec.
1153
+ */
1154
+ path: string;
1155
+ /**
1156
+ * Group labels for the operation.
1157
+ * Usually copied from OpenAPI `tags`.
1158
+ */
1159
+ tags: Array<string>;
1160
+ /**
1161
+ * Short one-line operation summary.
1162
+ */
1163
+ summary?: string;
1164
+ /**
1165
+ * Full operation description.
1166
+ */
1167
+ description?: string;
1168
+ /**
1169
+ * Marks the operation as deprecated.
1170
+ */
1171
+ deprecated?: boolean;
1172
+ /**
1173
+ * Parameters that could be used, we have QueryParams, PathParams, HeaderParams and CookieParams
1174
+ */
1175
+ parameters: Array<ParameterNode>;
1176
+ /**
1177
+ * Request body metadata for the operation.
1178
+ */
1179
+ requestBody?: {
1180
+ /**
1181
+ * Human-readable request body description.
1182
+ */
1183
+ description?: string;
1184
+ /**
1185
+ * Request body schema.
1186
+ * For OpenAPI, this is the schema from the first `content` entry.
1187
+ */
1188
+ schema?: SchemaNode;
1189
+ /**
1190
+ * Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
1191
+ * Set when a referenced schema has `readOnly` fields that should be omitted in request types.
1192
+ */
1193
+ keysToOmit?: Array<string>;
1194
+ /**
1195
+ * Whether the request body is required (`requestBody.required: true` in the spec).
1196
+ * When `false` or absent, the generated `data` parameter should be optional.
1197
+ */
1198
+ required?: boolean;
1199
+ /**
1200
+ * Media type of the request body (e.g. `'application/json'`, `'multipart/form-data'`).
1201
+ * Extracted from the first `content` entry of the OpenAPI `requestBody`.
1202
+ */
1203
+ contentType?: string;
1204
+ };
1205
+ /**
1206
+ * Operation responses.
1207
+ */
1208
+ responses: Array<ResponseNode>;
1209
+ };
1210
+ //#endregion
1211
+ //#region src/nodes/root.d.ts
1212
+ /**
1213
+ * Basic metadata for an API document.
1214
+ * Adapters fill fields that exist in their source format.
1215
+ *
1216
+ * @example
1217
+ * ```ts
1218
+ * const meta: RootMeta = { title: 'Pet API', version: '1.0.0' }
1219
+ * ```
1220
+ */
1221
+ type RootMeta = {
1222
+ /**
1223
+ * API title (from `info.title` in OAS/AsyncAPI).
1224
+ */
1225
+ title?: string;
1226
+ /**
1227
+ * API description (from `info.description` in OAS/AsyncAPI).
1228
+ */
1229
+ description?: string;
1230
+ /**
1231
+ * API version string (from `info.version` in OAS/AsyncAPI).
1232
+ */
1233
+ version?: string;
1234
+ /**
1235
+ * Resolved API base URL.
1236
+ * For OpenAPI and AsyncAPI, this comes from the selected server URL.
1237
+ */
1238
+ baseURL?: string;
1239
+ };
1240
+ /**
1241
+ * Root AST node that contains all schemas and operations for one API document.
1242
+ *
1243
+ * @example
1244
+ * ```ts
1245
+ * const root: RootNode = {
1246
+ * kind: 'Root',
1247
+ * schemas: [],
1248
+ * operations: [],
1249
+ * }
1250
+ * ```
1251
+ */
1252
+ type RootNode = BaseNode & {
1253
+ /**
1254
+ * Node kind.
1255
+ */
1256
+ kind: 'Root';
1257
+ /**
1258
+ * All schema nodes in the document.
1259
+ */
1260
+ schemas: Array<SchemaNode>;
1261
+ /**
1262
+ * All operation nodes in the document.
1263
+ */
1264
+ operations: Array<OperationNode>;
1265
+ /**
1266
+ * Optional document metadata populated by the adapter.
1267
+ */
1268
+ meta?: RootMeta;
1269
+ };
1270
+ //#endregion
1271
+ //#region src/nodes/index.d.ts
1272
+ /**
1273
+ * Union of all AST node types.
1274
+ *
1275
+ * This lets TypeScript narrow types in `switch (node.kind)` blocks.
1276
+ *
1277
+ * @example
1278
+ * ```ts
1279
+ * function getKind(node: Node): string {
1280
+ * switch (node.kind) {
1281
+ * case 'Root':
1282
+ * return 'root'
1283
+ * default:
1284
+ * return 'other'
1285
+ * }
1286
+ * }
1287
+ * ```
1288
+ */
1289
+ type Node = RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | FunctionNode;
1290
+ //#endregion
1291
+ //#region src/infer.d.ts
1292
+ /**
1293
+ * Shared parser options used by OAS-to-AST inference and parser flows.
1294
+ */
1295
+ type ParserOptions = {
1296
+ /**
1297
+ * How `format: 'date-time'` schemas are represented. `false` falls through to a plain string.
1298
+ */
1299
+ dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
1300
+ /**
1301
+ * Whether `type: 'integer'` and `format: 'int64'` produce `number` or `bigint` nodes.
1302
+ */
1303
+ integerType?: 'number' | 'bigint';
1304
+ /**
1305
+ * AST type used when no schema type can be inferred.
1306
+ */
1307
+ unknownType: 'any' | 'unknown' | 'void';
1308
+ /**
1309
+ * AST type used for completely empty schemas (`{}`).
1310
+ */
1311
+ emptySchemaType: 'any' | 'unknown' | 'void';
1312
+ /**
1313
+ * Suffix appended to derived enum names when building property schema names.
1314
+ */
1315
+ enumSuffix: 'enum' | (string & {});
1316
+ };
1317
+ /**
1318
+ * Maps each `dateType` option value to the AST node produced by `format: 'date-time'`.
1319
+ */
1320
+ type DateTimeNodeByDateType = {
1321
+ date: DateSchemaNode;
1322
+ string: DatetimeSchemaNode;
1323
+ stringOffset: DatetimeSchemaNode;
1324
+ stringLocal: DatetimeSchemaNode;
1325
+ false: StringSchemaNode;
1326
+ };
1327
+ /**
1328
+ * Resolves the AST node produced by `format: 'date-time'` based on the `dateType` option.
1329
+ */
1330
+ type ResolveDateTimeNode<TDateType extends ParserOptions['dateType']> = DateTimeNodeByDateType[TDateType extends keyof DateTimeNodeByDateType ? TDateType : 'string'];
1331
+ /**
1332
+ * Ordered list of `[schema-shape, SchemaNode]` pairs.
1333
+ * `InferSchemaNode` walks this tuple in order and returns the first matching node type.
1334
+ */
1335
+ type SchemaNodeMap<TDateType extends ParserOptions['dateType'] = 'string'> = [[{
1336
+ $ref: string;
1337
+ }, RefSchemaNode], [{
1338
+ allOf: ReadonlyArray<unknown>;
1339
+ properties: object;
1340
+ }, IntersectionSchemaNode], [{
1341
+ allOf: readonly [unknown, unknown, ...unknown[]];
1342
+ }, IntersectionSchemaNode], [{
1343
+ allOf: ReadonlyArray<unknown>;
1344
+ }, SchemaNode], [{
1345
+ oneOf: ReadonlyArray<unknown>;
1346
+ }, UnionSchemaNode], [{
1347
+ anyOf: ReadonlyArray<unknown>;
1348
+ }, UnionSchemaNode], [{
1349
+ const: null;
1350
+ }, ScalarSchemaNode], [{
1351
+ const: string | number | boolean;
1352
+ }, EnumSchemaNode], [{
1353
+ type: ReadonlyArray<string>;
1354
+ }, UnionSchemaNode], [{
1355
+ type: 'array';
1356
+ enum: ReadonlyArray<unknown>;
1357
+ }, ArraySchemaNode], [{
1358
+ enum: ReadonlyArray<unknown>;
1359
+ }, EnumSchemaNode], [{
1360
+ type: 'enum';
1361
+ }, EnumSchemaNode], [{
1362
+ type: 'union';
1363
+ }, UnionSchemaNode], [{
1364
+ type: 'intersection';
1365
+ }, IntersectionSchemaNode], [{
1366
+ type: 'tuple';
1367
+ }, ArraySchemaNode], [{
1368
+ type: 'ref';
1369
+ }, RefSchemaNode], [{
1370
+ type: 'datetime';
1371
+ }, DatetimeSchemaNode], [{
1372
+ type: 'date';
1373
+ }, DateSchemaNode], [{
1374
+ type: 'time';
1375
+ }, TimeSchemaNode], [{
1376
+ type: 'url';
1377
+ }, UrlSchemaNode], [{
1378
+ type: 'object';
1379
+ }, ObjectSchemaNode], [{
1380
+ additionalProperties: boolean | {};
1381
+ }, ObjectSchemaNode], [{
1382
+ type: 'array';
1383
+ }, ArraySchemaNode], [{
1384
+ items: object;
1385
+ }, ArraySchemaNode], [{
1386
+ prefixItems: ReadonlyArray<unknown>;
1387
+ }, ArraySchemaNode], [{
1388
+ type: string;
1389
+ format: 'date-time';
1390
+ }, ResolveDateTimeNode<TDateType>], [{
1391
+ type: string;
1392
+ format: 'date';
1393
+ }, DateSchemaNode], [{
1394
+ type: string;
1395
+ format: 'time';
1396
+ }, TimeSchemaNode], [{
1397
+ format: 'date-time';
1398
+ }, ResolveDateTimeNode<TDateType>], [{
1399
+ format: 'date';
1400
+ }, DateSchemaNode], [{
1401
+ format: 'time';
1402
+ }, TimeSchemaNode], [{
1403
+ type: 'string';
1404
+ }, StringSchemaNode], [{
1405
+ type: 'number';
1406
+ }, NumberSchemaNode], [{
1407
+ type: 'integer';
1408
+ }, NumberSchemaNode], [{
1409
+ type: 'bigint';
1410
+ }, NumberSchemaNode], [{
1411
+ type: string;
1412
+ }, ScalarSchemaNode], [{
1413
+ minLength: number;
1414
+ }, StringSchemaNode], [{
1415
+ maxLength: number;
1416
+ }, StringSchemaNode], [{
1417
+ pattern: string;
1418
+ }, StringSchemaNode], [{
1419
+ minimum: number;
1420
+ }, NumberSchemaNode], [{
1421
+ maximum: number;
1422
+ }, NumberSchemaNode]];
1423
+ /**
1424
+ * Infers the matching AST `SchemaNode` type from an input schema shape.
1425
+ */
1426
+ 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;
1427
+ /**
1428
+ * Backward-compatible alias for `InferSchemaNode`.
1429
+ */
1430
+ type InferSchema<TSchema extends object, TDateType extends ParserOptions['dateType'] = 'string', TEntries extends ReadonlyArray<[object, SchemaNode]> = SchemaNodeMap<TDateType>> = InferSchemaNode<TSchema, TDateType, TEntries>;
1431
+ //#endregion
1432
+ //#region src/factory.d.ts
1433
+ /**
1434
+ * Syncs property/parameter schema optionality flags from `required` and `schema.nullable`.
1435
+ *
1436
+ * - `optional` is set for non-required, non-nullable schemas.
1437
+ * - `nullish` is set for non-required, nullable schemas.
1438
+ */
1439
+ declare function syncOptionality(schema: SchemaNode, required: boolean): SchemaNode;
1440
+ /**
1441
+ * Distributive `Omit` that preserves each member of a union.
1442
+ *
1443
+ * @example
1444
+ * ```ts
1445
+ * type A = { kind: 'a'; keep: string; drop: number }
1446
+ * type B = { kind: 'b'; keep: boolean; drop: number }
1447
+ * type Result = DistributiveOmit<A | B, 'drop'>
1448
+ * // -> { kind: 'a'; keep: string } | { kind: 'b'; keep: boolean }
1449
+ * ```
1450
+ */
1451
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
1452
+ type CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties' | 'primitive'> & {
1453
+ properties?: Array<PropertyNode>;
1454
+ primitive?: 'object';
1455
+ };
1456
+ type CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>;
1457
+ type CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {
1458
+ kind: 'Schema';
1459
+ };
1460
+ /**
1461
+ * Creates a `RootNode` with stable defaults for `schemas` and `operations`.
1462
+ *
1463
+ * @example
1464
+ * ```ts
1465
+ * const root = createRoot()
1466
+ * // { kind: 'Root', schemas: [], operations: [] }
1467
+ * ```
1468
+ *
1469
+ * @example
1470
+ * ```ts
1471
+ * const root = createRoot({ schemas: [petSchema] })
1472
+ * // keeps default operations: []
1473
+ * ```
1474
+ */
1475
+ declare function createRoot(overrides?: Partial<Omit<RootNode, 'kind'>>): RootNode;
1476
+ /**
1477
+ * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.
1478
+ *
1479
+ * @example
1480
+ * ```ts
1481
+ * const operation = createOperation({
1482
+ * operationId: 'getPetById',
1483
+ * method: 'GET',
1484
+ * path: '/pet/{petId}',
1485
+ * })
1486
+ * // tags, parameters, and responses are []
1487
+ * ```
1488
+ *
1489
+ * @example
1490
+ * ```ts
1491
+ * const operation = createOperation({
1492
+ * operationId: 'findPets',
1493
+ * method: 'GET',
1494
+ * path: '/pet/findByStatus',
1495
+ * tags: ['pet'],
1496
+ * })
1497
+ * ```
1498
+ */
1499
+ declare function createOperation(props: Pick<OperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<OperationNode, 'kind' | 'operationId' | 'method' | 'path'>>): OperationNode;
1500
+ /**
1501
+ * Creates a `SchemaNode`, narrowed to the variant of `props.type`.
1502
+ * For object schemas, `properties` defaults to an empty array.
1503
+ * `primitive` is automatically inferred from `type` when not explicitly provided.
1504
+ *
1505
+ * @example
1506
+ * ```ts
1507
+ * const scalar = createSchema({ type: 'string' })
1508
+ * // { kind: 'Schema', type: 'string', primitive: 'string' }
1509
+ * ```
1510
+ *
1511
+ * @example
1512
+ * ```ts
1513
+ * const uuid = createSchema({ type: 'uuid' })
1514
+ * // { kind: 'Schema', type: 'uuid', primitive: 'string' }
1515
+ * ```
1516
+ *
1517
+ * @example
1518
+ * ```ts
1519
+ * const object = createSchema({ type: 'object' })
1520
+ * // { kind: 'Schema', type: 'object', primitive: 'object', properties: [] }
1521
+ * ```
1522
+ *
1523
+ * @example
1524
+ * ```ts
1525
+ * const enumSchema = createSchema({
1526
+ * type: 'enum',
1527
+ * primitive: 'string',
1528
+ * enumValues: ['available', 'pending'],
1529
+ * })
1530
+ * ```
1531
+ */
1532
+ declare function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>;
1533
+ declare function createSchema(props: CreateSchemaInput): SchemaNode;
1534
+ /**
1535
+ * Creates a `PropertyNode`.
1536
+ *
1537
+ * `required` defaults to `false`.
1538
+ * `schema.optional` and `schema.nullish` are derived from `required` and `schema.nullable`.
1539
+ *
1540
+ * @example
1541
+ * ```ts
1542
+ * const property = createProperty({
1543
+ * name: 'status',
1544
+ * schema: createSchema({ type: 'string' }),
1545
+ * })
1546
+ * // required=false, schema.optional=true
1547
+ * ```
1548
+ *
1549
+ * @example
1550
+ * ```ts
1551
+ * const property = createProperty({
1552
+ * name: 'status',
1553
+ * required: true,
1554
+ * schema: createSchema({ type: 'string', nullable: true }),
1555
+ * })
1556
+ * // required=true, no optional/nullish
1557
+ * ```
1558
+ */
1559
+ declare function createProperty(props: Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>): PropertyNode;
1560
+ /**
1561
+ * Creates a `ParameterNode`.
1562
+ *
1563
+ * `required` defaults to `false`.
1564
+ * Nested schema flags are set from `required` and `schema.nullable`.
1565
+ *
1566
+ * @example
1567
+ * ```ts
1568
+ * const param = createParameter({
1569
+ * name: 'petId',
1570
+ * in: 'path',
1571
+ * required: true,
1572
+ * schema: createSchema({ type: 'string' }),
1573
+ * })
1574
+ * ```
1575
+ *
1576
+ * @example
1577
+ * ```ts
1578
+ * const param = createParameter({
1579
+ * name: 'status',
1580
+ * in: 'query',
1581
+ * schema: createSchema({ type: 'string', nullable: true }),
1582
+ * })
1583
+ * // required=false, schema.nullish=true
1584
+ * ```
1585
+ */
1586
+ declare function createParameter(props: Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>): ParameterNode;
1587
+ /**
1588
+ * Creates a `ResponseNode`.
1589
+ *
1590
+ * @example
1591
+ * ```ts
1592
+ * const response = createResponse({
1593
+ * statusCode: '200',
1594
+ * description: 'Success',
1595
+ * schema: createSchema({ type: 'object', properties: [] }),
1596
+ * })
1597
+ * ```
1598
+ */
1599
+ declare function createResponse(props: Pick<ResponseNode, 'statusCode' | 'schema'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'schema'>>): ResponseNode;
1600
+ /**
1601
+ * Creates a `FunctionParameterNode`.
1602
+ *
1603
+ * `optional` defaults to `false`.
1604
+ *
1605
+ * @example Required typed param
1606
+ * ```ts
1607
+ * createFunctionParameter({ name: 'petId', type: createTypeNode({ variant: 'reference', name: 'string' }) })
1608
+ * // → petId: string
1609
+ * ```
1610
+ *
1611
+ * @example Optional param
1612
+ * ```ts
1613
+ * createFunctionParameter({ name: 'params', type: createTypeNode({ variant: 'reference', name: 'QueryParams' }), optional: true })
1614
+ * // → params?: QueryParams
1615
+ * ```
1616
+ *
1617
+ * @example Param with default (implicitly optional; cannot combine with `optional: true`)
1618
+ * ```ts
1619
+ * createFunctionParameter({ name: 'config', type: createTypeNode({ variant: 'reference', name: 'RequestConfig' }), default: '{}' })
1620
+ * // → config: RequestConfig = {}
1621
+ * ```
1622
+ */
1623
+ declare function createFunctionParameter(props: {
1624
+ name: string;
1625
+ type?: TypeNode;
1626
+ rest?: boolean;
1627
+ } & ({
1628
+ optional: true;
1629
+ default?: never;
1630
+ } | {
1631
+ optional?: false;
1632
+ default?: string;
1633
+ })): FunctionParameterNode;
1634
+ /**
1635
+ * Creates a {@link TypeNode} representing a language-agnostic structured type expression.
1636
+ *
1637
+ * Use `variant: 'struct'` for inline anonymous types and `variant: 'member'` for a single
1638
+ * named field accessed from a group type. Each language's printer renders the variant
1639
+ * into its own syntax (TypeScript, Python, C#, Kotlin, …).
1640
+ *
1641
+ * @example Reference type (TypeScript: `QueryParams`)
1642
+ * ```ts
1643
+ * createTypeNode({ variant: 'reference', name: 'QueryParams' })
1644
+ * ```
1645
+ *
1646
+ * @example Struct type (TypeScript: `{ petId: string }`)
1647
+ * ```ts
1648
+ * createTypeNode({ variant: 'struct', properties: [{ name: 'petId', optional: false, type: createTypeNode({ variant: 'reference', name: 'string' }) }] })
1649
+ * ```
1650
+ *
1651
+ * @example Member type (TypeScript: `DeletePetPathParams['petId']`)
1652
+ * ```ts
1653
+ * createTypeNode({ variant: 'member', base: 'DeletePetPathParams', key: 'petId' })
1654
+ * ```
1655
+ */
1656
+ declare function createTypeNode(props: {
1657
+ variant: 'reference';
1658
+ name: string;
1659
+ } | {
1660
+ variant: 'struct';
1661
+ properties: Array<{
1662
+ name: string;
1663
+ optional: boolean;
1664
+ type: TypeNode;
1665
+ }>;
1666
+ } | {
1667
+ variant: 'member';
1668
+ base: string;
1669
+ key: string;
1670
+ }): TypeNode;
1671
+ /**
1672
+ * Creates a `ParameterGroupNode` representing a group of related parameters treated as a unit.
1673
+ *
1674
+ * @example Grouped param (TypeScript declaration)
1675
+ * ```ts
1676
+ * createParameterGroup({
1677
+ * properties: [
1678
+ * createFunctionParameter({ name: 'id', type: createTypeNode({ variant: 'reference', name: 'string' }), optional: false }),
1679
+ * createFunctionParameter({ name: 'name', type: createTypeNode({ variant: 'reference', name: 'string' }), optional: true }),
1680
+ * ],
1681
+ * default: '{}',
1682
+ * })
1683
+ * // declaration → { id, name? }: { id: string; name?: string } = {}
1684
+ * // call → { id, name }
1685
+ * ```
1686
+ *
1687
+ * @example Inline (spread) — children emitted as individual top-level parameters
1688
+ * ```ts
1689
+ * createParameterGroup({
1690
+ * properties: [createFunctionParameter({ name: 'petId', type: createTypeNode({ variant: 'reference', name: 'string' }), optional: false })],
1691
+ * inline: true,
1692
+ * })
1693
+ * // declaration → petId: string
1694
+ * // call → petId
1695
+ * ```
1696
+ */
1697
+ declare function createParameterGroup(props: Pick<ParameterGroupNode, 'properties'> & Partial<Omit<ParameterGroupNode, 'kind' | 'properties'>>): ParameterGroupNode;
1698
+ /**
1699
+ * Creates a `FunctionParametersNode` from an ordered list of parameters.
1700
+ *
1701
+ * @example
1702
+ * ```ts
1703
+ * createFunctionParameters({
1704
+ * params: [
1705
+ * createFunctionParameter({ name: 'petId', type: createTypeNode({ variant: 'reference', name: 'string' }), optional: false }),
1706
+ * createFunctionParameter({ name: 'config', type: createTypeNode({ variant: 'reference', name: 'RequestConfig' }), optional: false, default: '{}' }),
1707
+ * ],
1708
+ * })
1709
+ * ```
1710
+ *
1711
+ * @example
1712
+ * ```ts
1713
+ * const empty = createFunctionParameters()
1714
+ * // { kind: 'FunctionParameters', params: [] }
1715
+ * ```
1716
+ */
1717
+ declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
1718
+ //#endregion
1719
+ //#region src/printer.d.ts
1720
+ /**
1721
+ * Runtime context passed as `this` to printer handlers.
1722
+ *
1723
+ * `this.transform` dispatches to node-level handlers from `nodes`.
1724
+ *
1725
+ * @example
1726
+ * ```ts
1727
+ * const context: PrinterHandlerContext<string, {}> = {
1728
+ * options: {},
1729
+ * transform: () => 'value',
1730
+ * }
1731
+ * ```
1732
+ */
1733
+ type PrinterHandlerContext<TOutput, TOptions extends object> = {
1734
+ /**
1735
+ * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
1736
+ * Use `this.transform` inside `nodes` handlers and inside the `print` override.
1737
+ */
1738
+ transform: (node: SchemaNode) => TOutput | null | undefined;
1739
+ /**
1740
+ * Options for this printer instance.
1741
+ */
1742
+ options: TOptions;
1743
+ };
1744
+ /**
1745
+ * Handler for one schema node type.
1746
+ *
1747
+ * Use a regular function (not an arrow function) if you need `this`.
1748
+ *
1749
+ * @example
1750
+ * ```ts
1751
+ * const handler: PrinterHandler<string, {}, 'string'> = function () {
1752
+ * return 'string'
1753
+ * }
1754
+ * ```
1755
+ */
1756
+ type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null | undefined;
1757
+ /**
1758
+ * Partial map of per-node-type handler overrides for a printer.
1759
+ *
1760
+ * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
1761
+ * Supply only the handlers you want to replace; the printer's built-in
1762
+ * defaults fill in the rest.
1763
+ *
1764
+ * @example
1765
+ * ```ts
1766
+ * pluginZod({
1767
+ * printer: {
1768
+ * nodes: {
1769
+ * date(): string {
1770
+ * return 'z.string().date()'
1771
+ * },
1772
+ * } satisfies PrinterPartial<string, PrinterZodOptions>,
1773
+ * },
1774
+ * })
1775
+ * ```
1776
+ */
1777
+ type PrinterPartial<TOutput, TOptions extends object> = Partial<{ [K in SchemaType]: PrinterHandler<TOutput, TOptions, K> }>;
1778
+ /**
1779
+ * Generic shape used by `definePrinter`.
1780
+ *
1781
+ * - `TName` — unique string identifier (e.g. `'zod'`, `'ts'`)
1782
+ * - `TOptions` — options passed to and stored on the printer instance
1783
+ * - `TOutput` — the type emitted by node handlers
1784
+ * - `TPrintOutput` — type returned by public `print` (defaults to `TOutput`)
1785
+ *
1786
+ * @example
1787
+ * ```ts
1788
+ * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>
1789
+ * ```
1790
+ */
1791
+ type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
1792
+ name: TName;
1793
+ options: TOptions;
1794
+ output: TOutput;
1795
+ printOutput: TPrintOutput;
1796
+ };
1797
+ /**
1798
+ * Printer instance returned by a printer factory.
1799
+ *
1800
+ * @example
1801
+ * ```ts
1802
+ * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})
1803
+ * ```
1804
+ */
1805
+ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
1806
+ /**
1807
+ * Unique identifier supplied at creation time.
1808
+ */
1809
+ name: T['name'];
1810
+ /**
1811
+ * Options for this printer instance.
1812
+ */
1813
+ options: T['options'];
1814
+ /**
1815
+ * Node-level dispatcher — converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
1816
+ * Always dispatches through the `nodes` map; never calls the `print` override.
1817
+ * Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
1818
+ */
1819
+ transform: (node: SchemaNode) => T['output'] | null | undefined;
1820
+ /**
1821
+ * Public printer. If the builder provides a root-level `print`, this calls that
1822
+ * higher-level function (which may produce full declarations).
1823
+ * Otherwise, falls back to the node-level dispatcher.
1824
+ */
1825
+ print: (node: SchemaNode) => T['printOutput'] | null | undefined;
1826
+ };
1827
+ /**
1828
+ * Builder function passed to `definePrinter`.
1829
+ *
1830
+ * It receives resolved options and returns:
1831
+ * - `name`
1832
+ * - `options`
1833
+ * - `nodes` handlers
1834
+ * - optional top-level `print` override
1835
+ *
1836
+ * @example
1837
+ * ```ts
1838
+ * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })
1839
+ * ```
1840
+ */
1841
+ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
1842
+ name: T['name'];
1843
+ /**
1844
+ * Options to store on the printer.
1845
+ */
1846
+ options: T['options'];
1847
+ nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
1848
+ /**
1849
+ * Optional root-level print override. When provided, becomes the public `printer.print`.
1850
+ * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
1851
+ * not the override itself — so recursion is safe.
1852
+ */
1853
+ print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null;
1854
+ };
1855
+ /**
1856
+ * Creates a schema printer factory.
1857
+ *
1858
+ * This function wraps a builder and makes options optional at call sites.
1859
+ *
1860
+ * The builder receives resolved options and returns:
1861
+ * - `name` — a unique identifier for the printer
1862
+ * - `options` — options stored on the returned printer instance
1863
+ * - `nodes` — a map of `SchemaType` → handler functions that convert a `SchemaNode` to `TOutput`
1864
+ * - `print` _(optional)_ — top-level override exposed as `printer.print`
1865
+ * - Inside this function, use `this.transform(node)` to dispatch to the `nodes` map
1866
+ * - This keeps recursion safe and avoids self-calls
1867
+ *
1868
+ * When no `print` override is provided, `printer.print` falls back to `printer.transform` (the node-level dispatcher).
1869
+ *
1870
+ * @example Basic usage — Zod schema printer
1871
+ * ```ts
1872
+ * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
1873
+ *
1874
+ * export const zodPrinter = definePrinter<PrinterZod>((options) => ({
1875
+ * name: 'zod',
1876
+ * options: { strict: options.strict ?? true },
1877
+ * nodes: {
1878
+ * string: () => 'z.string()',
1879
+ * object(node) {
1880
+ * const props = node.properties.map(p => `${p.name}: ${this.transform(p.schema)}`).join(', ')
1881
+ * return `z.object({ ${props} })`
1882
+ * },
1883
+ * },
1884
+ * }))
1885
+ * ```
1886
+ */
1887
+ declare function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
1888
+ /**
1889
+ * Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.
1890
+ **
1891
+ * @example
1892
+ * ```ts
1893
+ * export const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>(
1894
+ * (node) => kindToHandlerKey[node.kind],
1895
+ * )
1896
+ * ```
1897
+ */
1898
+ 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"]) => {
1899
+ name: T["name"];
1900
+ options: T["options"];
1901
+ nodes: Partial<{ [K in TKey]: (this: {
1902
+ transform: (node: TNode) => T["output"] | null | undefined;
1903
+ options: T["options"];
1904
+ }, node: TNodeByKey[K]) => T["output"] | null | undefined }>;
1905
+ print?: (this: {
1906
+ transform: (node: TNode) => T["output"] | null | undefined;
1907
+ options: T["options"];
1908
+ }, node: TNode) => T["printOutput"] | null | undefined;
1909
+ }) => (options?: T["options"]) => {
1910
+ name: T["name"];
1911
+ options: T["options"];
1912
+ transform: (node: TNode) => T["output"] | null | undefined;
1913
+ print: (node: TNode) => T["printOutput"] | null | undefined;
1914
+ };
1915
+ //#endregion
1916
+ //#region src/refs.d.ts
1917
+ /**
1918
+ * Lookup map from schema name to `SchemaNode`.
1919
+ */
1920
+ type RefMap = Map<string, SchemaNode>;
1921
+ /**
1922
+ * Returns the last path segment of a reference string.
1923
+ *
1924
+ * Example: `#/components/schemas/Pet` becomes `Pet`.
1925
+ *
1926
+ * @example
1927
+ * ```ts
1928
+ * extractRefName('#/components/schemas/Pet') // 'Pet'
1929
+ * ```
1930
+ */
1931
+ declare function extractRefName(ref: string): string;
1932
+ //#endregion
1933
+ //#region src/visitor.d.ts
1934
+ /**
1935
+ * Ordered mapping of `[NodeType, ParentType]` pairs.
1936
+ *
1937
+ * `ParentOf` uses this map to find parent types.
1938
+ */
1939
+ type ParentNodeMap = [[RootNode, undefined], [OperationNode, RootNode], [SchemaNode, RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode], [PropertyNode, SchemaNode], [ParameterNode, OperationNode], [ResponseNode, OperationNode]];
1940
+ /**
1941
+ * Resolves the parent node type for a given AST node type.
1942
+ *
1943
+ * This is used by visitor context so `ctx.parent` is correctly typed
1944
+ * for each callback.
1945
+ *
1946
+ * @example
1947
+ * ```ts
1948
+ * type RootParent = ParentOf<RootNode>
1949
+ * // undefined
1950
+ * ```
1951
+ *
1952
+ * @example
1953
+ * ```ts
1954
+ * type PropertyParent = ParentOf<PropertyNode>
1955
+ * // SchemaNode
1956
+ * ```
1957
+ *
1958
+ * @example
1959
+ * ```ts
1960
+ * type SchemaParent = ParentOf<SchemaNode>
1961
+ * // RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode
1962
+ * ```
1963
+ */
1964
+ 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;
1965
+ /**
1966
+ * Traversal context passed as the second argument to every visitor callback.
1967
+ * `parent` is typed from the current node type.
1968
+ *
1969
+ * @example
1970
+ * ```ts
1971
+ * const visitor: Visitor = {
1972
+ * schema(node, { parent }) {
1973
+ * // parent type is narrowed by node kind
1974
+ * },
1975
+ * }
1976
+ * ```
1977
+ */
1978
+ type VisitorContext<T extends Node = Node> = {
1979
+ /**
1980
+ * Parent node of the currently visited node.
1981
+ * For `RootNode`, this is `undefined`.
1982
+ */
1983
+ parent?: ParentOf<T>;
1984
+ };
1985
+ /**
1986
+ * Synchronous visitor used by `transform`.
1987
+ *
1988
+ * @example
1989
+ * ```ts
1990
+ * const visitor: Visitor = {
1991
+ * operation(node) {
1992
+ * return { ...node, operationId: `x_${node.operationId}` }
1993
+ * },
1994
+ * }
1995
+ * ```
1996
+ */
1997
+ type Visitor = {
1998
+ root?(node: RootNode, context: VisitorContext<RootNode>): void | RootNode;
1999
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): void | OperationNode;
2000
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): void | SchemaNode;
2001
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): void | PropertyNode;
2002
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): void | ParameterNode;
2003
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): void | ResponseNode;
2004
+ };
2005
+ /**
2006
+ * Utility type for values that can be returned directly or asynchronously.
2007
+ */
2008
+ type MaybePromise<T> = T | Promise<T>;
2009
+ /**
2010
+ * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
2011
+ *
2012
+ * @example
2013
+ * ```ts
2014
+ * const visitor: AsyncVisitor = {
2015
+ * async operation(node) {
2016
+ * await Promise.resolve(node.operationId)
2017
+ * },
2018
+ * }
2019
+ * ```
2020
+ */
2021
+ type AsyncVisitor = {
2022
+ root?(node: RootNode, context: VisitorContext<RootNode>): MaybePromise<void | RootNode>;
2023
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<void | OperationNode>;
2024
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<void | SchemaNode>;
2025
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<void | PropertyNode>;
2026
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<void | ParameterNode>;
2027
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<void | ResponseNode>;
2028
+ };
2029
+ /**
2030
+ * Visitor used by `collect`.
2031
+ *
2032
+ * @example
2033
+ * ```ts
2034
+ * const visitor: CollectVisitor<string> = {
2035
+ * operation(node) {
2036
+ * return node.operationId
2037
+ * },
2038
+ * }
2039
+ * ```
2040
+ */
2041
+ type CollectVisitor<T> = {
2042
+ root?(node: RootNode, context: VisitorContext<RootNode>): T | undefined;
2043
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined;
2044
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined;
2045
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined;
2046
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | undefined;
2047
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | undefined;
2048
+ };
2049
+ /**
2050
+ * Options for `transform`.
2051
+ *
2052
+ * @example
2053
+ * ```ts
2054
+ * const options: TransformOptions = { depth: 'deep', schema: (node) => node }
2055
+ * ```
2056
+ *
2057
+ * @example
2058
+ * ```ts
2059
+ * // Only transform the current node, not nested children
2060
+ * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
2061
+ * ```
2062
+ */
2063
+ type TransformOptions = Visitor & {
2064
+ /**
2065
+ * Traversal depth (`'deep'` by default).
2066
+ * @default 'deep'
2067
+ */
2068
+ depth?: VisitorDepth;
2069
+ /**
2070
+ * Internal parent override used during recursion.
2071
+ */
2072
+ parent?: Node;
2073
+ };
2074
+ /**
2075
+ * Options for `walk`.
2076
+ *
2077
+ * @example
2078
+ * ```ts
2079
+ * const options: WalkOptions = { depth: 'deep', concurrency: 10, root: () => {} }
2080
+ * ```
2081
+ */
2082
+ type WalkOptions = AsyncVisitor & {
2083
+ /**
2084
+ * Traversal depth (`'deep'` by default).
2085
+ * @default 'deep'
2086
+ */
2087
+ depth?: VisitorDepth;
2088
+ /**
2089
+ * Maximum number of sibling nodes visited concurrently.
2090
+ * @default 30
2091
+ */
2092
+ concurrency?: number;
2093
+ };
2094
+ /**
2095
+ * Options for `collect`.
2096
+ *
2097
+ * @example
2098
+ * ```ts
2099
+ * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
2100
+ * ```
2101
+ */
2102
+ type CollectOptions<T> = CollectVisitor<T> & {
2103
+ /**
2104
+ * Traversal depth (`'deep'` by default).
2105
+ * @default 'deep'
2106
+ */
2107
+ depth?: VisitorDepth;
2108
+ /**
2109
+ * Internal parent override used during recursion.
2110
+ */
2111
+ parent?: Node;
2112
+ };
2113
+ /**
2114
+ * Depth-first traversal for side effects. Visitor return values are ignored.
2115
+ * Sibling nodes at each level are visited concurrently up to `options.concurrency`
2116
+ * (default: `WALK_CONCURRENCY`).
2117
+ *
2118
+ * @example
2119
+ * ```ts
2120
+ * await walk(root, {
2121
+ * operation(node) {
2122
+ * console.log(node.operationId)
2123
+ * },
2124
+ * })
2125
+ * ```
2126
+ *
2127
+ * @example
2128
+ * ```ts
2129
+ * // Visit only the current node
2130
+ * await walk(root, { depth: 'shallow', root: () => {} })
2131
+ * ```
2132
+ */
2133
+ declare function walk(node: Node, options: WalkOptions): Promise<void>;
2134
+ /**
2135
+ * Runs a depth-first immutable transform.
2136
+ *
2137
+ * If a visitor returns a node, it replaces the current node.
2138
+ * If it returns `undefined`, the current node stays the same.
2139
+ *
2140
+ * @example
2141
+ * ```ts
2142
+ * const next = transform(root, {
2143
+ * operation(node) {
2144
+ * return { ...node, operationId: `prefixed_${node.operationId}` }
2145
+ * },
2146
+ * })
2147
+ * ```
2148
+ *
2149
+ * @example
2150
+ * ```ts
2151
+ * // Shallow mode: only transform the input node
2152
+ * const next = transform(root, { depth: 'shallow', root: (node) => node })
2153
+ * ```
2154
+ */
2155
+ declare function transform(node: RootNode, options: TransformOptions): RootNode;
2156
+ declare function transform(node: OperationNode, options: TransformOptions): OperationNode;
2157
+ declare function transform(node: SchemaNode, options: TransformOptions): SchemaNode;
2158
+ declare function transform(node: PropertyNode, options: TransformOptions): PropertyNode;
2159
+ declare function transform(node: ParameterNode, options: TransformOptions): ParameterNode;
2160
+ declare function transform(node: ResponseNode, options: TransformOptions): ResponseNode;
2161
+ declare function transform(node: Node, options: TransformOptions): Node;
2162
+ /**
2163
+ * Composes multiple visitors into one visitor, applied left to right.
2164
+ *
2165
+ * For each node kind, output from one visitor is input to the next.
2166
+ * If a visitor returns `undefined`, the previous node value is kept.
2167
+ *
2168
+ * @example
2169
+ * ```ts
2170
+ * const visitor = composeTransformers(
2171
+ * { operation: (node) => ({ ...node, operationId: `a_${node.operationId}` }) },
2172
+ * { operation: (node) => ({ ...node, operationId: `b_${node.operationId}` }) },
2173
+ * )
2174
+ * ```
2175
+ */
2176
+ declare function composeTransformers(...visitors: Array<Visitor>): Visitor;
2177
+ /**
2178
+ * Runs a depth-first synchronous collection pass.
2179
+ *
2180
+ * Non-`undefined` values returned by visitor callbacks are appended to the result.
2181
+ *
2182
+ * @example
2183
+ * ```ts
2184
+ * const ids = collect(root, {
2185
+ * operation(node) {
2186
+ * return node.operationId
2187
+ * },
2188
+ * })
2189
+ * ```
2190
+ *
2191
+ * @example
2192
+ * ```ts
2193
+ * // Collect from only the current node
2194
+ * const values = collect(root, { depth: 'shallow', root: () => 'root' })
2195
+ * ```
2196
+ */
2197
+ declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
2198
+ //#endregion
2199
+ export { IntersectionSchemaNode as $, createTypeNode as A, schemaTypes as At, ResponseNode as B, createOperation as C, BaseNode as Ct, createResponse as D, httpMethods as Dt, createProperty as E, VisitorDepth as Et, Node as F, ParameterNode as G, MediaType as H, RootMeta as I, DateSchemaNode as J, ArraySchemaNode as K, RootNode as L, InferSchema as M, InferSchemaNode as N, createRoot as O, isScalarPrimitive as Ot, ParserOptions as P, FormatStringSchemaNode as Q, HttpMethod as R, createFunctionParameters as S, TypeNode as St, createParameterGroup as T, ScalarPrimitive as Tt, StatusCode as U, HttpStatusCode as V, ParameterLocation as W, EnumSchemaNode as X, DatetimeSchemaNode as Y, EnumValueNode as Z, PrinterPartial as _, FunctionNode as _t, TransformOptions as a, RefSchemaNode as at, DistributiveOmit as b, FunctionParametersNode as bt, WalkOptions as c, SchemaNode as ct, transform as d, SpecialSchemaType as dt, Ipv4SchemaNode as et, walk as f, StringSchemaNode as ft, PrinterFactoryOptions as g, PropertyNode as gt, Printer as h, UrlSchemaNode as ht, ParentOf as i, PrimitiveSchemaType as it, syncOptionality as j, createSchema as k, mediaTypes as kt, collect as l, SchemaNodeByType as lt, extractRefName as m, UnionSchemaNode as mt, CollectOptions as n, NumberSchemaNode as nt, Visitor as o, ScalarSchemaNode as ot, RefMap as p, TimeSchemaNode as pt, ComplexSchemaType as q, CollectVisitor as r, ObjectSchemaNode as rt, VisitorContext as s, ScalarSchemaType as st, AsyncVisitor as t, Ipv6SchemaNode as tt, composeTransformers as u, SchemaType as ut, createPrinterFactory as v, FunctionNodeType as vt, createParameter as w, NodeKind as wt, createFunctionParameter as x, ParameterGroupNode as xt, definePrinter as y, FunctionParameterNode as yt, OperationNode as z };
2200
+ //# sourceMappingURL=visitor-z-5U8NoF.d.ts.map