@kubb/ast 5.10.2 → 5.10.3
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.cts +2686 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/dist/rolldown-runtime-CNktS9qV.js +0 -17
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2686 @@
|
|
|
1
|
+
//#endregion
|
|
2
|
+
//#region src/constants.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Traversal depth for AST visitor utilities.
|
|
5
|
+
*
|
|
6
|
+
* - `'shallow'` recurses through every node except nested `Schema` subtrees, which it treats as
|
|
7
|
+
* leaves: a schema node itself is visited, but its children are not.
|
|
8
|
+
* - `'deep'` recursively visits all descendant nodes, including schema subtrees.
|
|
9
|
+
*/
|
|
10
|
+
type VisitorDepth = 'shallow' | 'deep';
|
|
11
|
+
/**
|
|
12
|
+
* Schema type discriminators used by all AST schema nodes.
|
|
13
|
+
*
|
|
14
|
+
* Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
|
|
15
|
+
*/
|
|
16
|
+
export declare const schemaTypes: {
|
|
17
|
+
/**
|
|
18
|
+
* Text value.
|
|
19
|
+
*/
|
|
20
|
+
readonly string: "string";
|
|
21
|
+
/**
|
|
22
|
+
* Floating-point number (`float`, `double`).
|
|
23
|
+
*/
|
|
24
|
+
readonly number: "number";
|
|
25
|
+
/**
|
|
26
|
+
* Whole number (`int32`). Use `bigint` for `int64`.
|
|
27
|
+
*/
|
|
28
|
+
readonly integer: "integer";
|
|
29
|
+
/**
|
|
30
|
+
* 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
|
|
31
|
+
*/
|
|
32
|
+
readonly bigint: "bigint";
|
|
33
|
+
/**
|
|
34
|
+
* Boolean value.
|
|
35
|
+
*/
|
|
36
|
+
readonly boolean: "boolean";
|
|
37
|
+
/**
|
|
38
|
+
* Explicit null value.
|
|
39
|
+
*/
|
|
40
|
+
readonly null: "null";
|
|
41
|
+
/**
|
|
42
|
+
* Any value (no type restriction).
|
|
43
|
+
*/
|
|
44
|
+
readonly any: "any";
|
|
45
|
+
/**
|
|
46
|
+
* Unknown value (must be narrowed before usage).
|
|
47
|
+
*/
|
|
48
|
+
readonly unknown: "unknown";
|
|
49
|
+
/**
|
|
50
|
+
* No return value (`void`).
|
|
51
|
+
*/
|
|
52
|
+
readonly void: "void";
|
|
53
|
+
/**
|
|
54
|
+
* Object with named properties.
|
|
55
|
+
*/
|
|
56
|
+
readonly object: "object";
|
|
57
|
+
/**
|
|
58
|
+
* Sequential list of items.
|
|
59
|
+
*/
|
|
60
|
+
readonly array: "array";
|
|
61
|
+
/**
|
|
62
|
+
* Fixed-length list with position-specific items.
|
|
63
|
+
*/
|
|
64
|
+
readonly tuple: "tuple";
|
|
65
|
+
/**
|
|
66
|
+
* "One of" multiple schema members.
|
|
67
|
+
*/
|
|
68
|
+
readonly union: "union";
|
|
69
|
+
/**
|
|
70
|
+
* "All of" multiple schema members.
|
|
71
|
+
*/
|
|
72
|
+
readonly intersection: "intersection";
|
|
73
|
+
/** "Not" a single schema member. */
|
|
74
|
+
readonly not: "not";
|
|
75
|
+
/**
|
|
76
|
+
* Enum schema.
|
|
77
|
+
*/
|
|
78
|
+
readonly enum: "enum";
|
|
79
|
+
/**
|
|
80
|
+
* Reference to another schema.
|
|
81
|
+
*/
|
|
82
|
+
readonly ref: "ref";
|
|
83
|
+
/**
|
|
84
|
+
* Calendar date (for example `2026-03-24`).
|
|
85
|
+
*/
|
|
86
|
+
readonly date: "date";
|
|
87
|
+
/**
|
|
88
|
+
* Date-time value (for example `2026-03-24T09:00:00Z`).
|
|
89
|
+
*/
|
|
90
|
+
readonly datetime: "datetime";
|
|
91
|
+
/**
|
|
92
|
+
* Time-only value (for example `09:00:00`).
|
|
93
|
+
*/
|
|
94
|
+
readonly time: "time";
|
|
95
|
+
/**
|
|
96
|
+
* UUID value.
|
|
97
|
+
*/
|
|
98
|
+
readonly uuid: "uuid";
|
|
99
|
+
/**
|
|
100
|
+
* Email address value.
|
|
101
|
+
*/
|
|
102
|
+
readonly email: "email";
|
|
103
|
+
/**
|
|
104
|
+
* URL value.
|
|
105
|
+
*/
|
|
106
|
+
readonly url: "url";
|
|
107
|
+
/**
|
|
108
|
+
* IPv4 address value.
|
|
109
|
+
*/
|
|
110
|
+
readonly ipv4: "ipv4";
|
|
111
|
+
/**
|
|
112
|
+
* IPv6 address value.
|
|
113
|
+
*/
|
|
114
|
+
readonly ipv6: "ipv6";
|
|
115
|
+
/**
|
|
116
|
+
* Binary/blob value.
|
|
117
|
+
*/
|
|
118
|
+
readonly blob: "blob";
|
|
119
|
+
/**
|
|
120
|
+
* Impossible value (`never`).
|
|
121
|
+
*/
|
|
122
|
+
readonly never: "never";
|
|
123
|
+
};
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/nodes/base.d.ts
|
|
126
|
+
/**
|
|
127
|
+
* `kind` values used by AST nodes.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const kind: NodeKind = 'Schema'
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
type NodeKind = 'Input' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'RequestBody' | 'Content' | 'Type' | 'File' | 'Import' | 'Export' | 'Source' | 'Const' | 'Function' | 'ArrowFunction' | 'Text' | 'Break' | 'Jsx';
|
|
135
|
+
/**
|
|
136
|
+
* Base shape shared by all AST nodes.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* const base: BaseNode = { kind: 'Input' }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
type BaseNode = {
|
|
144
|
+
/**
|
|
145
|
+
* Node discriminator.
|
|
146
|
+
*/
|
|
147
|
+
kind: NodeKind;
|
|
148
|
+
};
|
|
149
|
+
/** `Omit` applied to each member of a union, so the union survives. */
|
|
150
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/nodes/property.d.ts
|
|
153
|
+
/**
|
|
154
|
+
* AST node representing one named object property.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const property: PropertyNode = {
|
|
159
|
+
* kind: 'Property',
|
|
160
|
+
* name: 'id',
|
|
161
|
+
* schema: createSchema({ type: 'integer' }),
|
|
162
|
+
* required: true,
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
type PropertyNode = BaseNode & {
|
|
167
|
+
kind: 'Property';
|
|
168
|
+
/**
|
|
169
|
+
* Property key.
|
|
170
|
+
*/
|
|
171
|
+
name: string;
|
|
172
|
+
/**
|
|
173
|
+
* Property schema.
|
|
174
|
+
*/
|
|
175
|
+
schema: SchemaNode;
|
|
176
|
+
/**
|
|
177
|
+
* Whether the property is required.
|
|
178
|
+
*/
|
|
179
|
+
required: boolean;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Loosely-typed property accepted by `createProperty`, with `required` optional.
|
|
183
|
+
*/
|
|
184
|
+
type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>;
|
|
185
|
+
/**
|
|
186
|
+
* Creates a `PropertyNode`. `required` defaults to `false`, and the schema's
|
|
187
|
+
* `optional`/`nullish` flags are derived from it.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* const property = createProperty({
|
|
192
|
+
* name: 'status',
|
|
193
|
+
* required: true,
|
|
194
|
+
* schema: createSchema({ type: 'string', nullable: true }),
|
|
195
|
+
* })
|
|
196
|
+
* // required=true, no optional/nullish
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function createProperty(input: UserPropertyNode): PropertyNode;
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/nodes/schema.d.ts
|
|
202
|
+
type PrimitiveSchemaType =
|
|
203
|
+
/**
|
|
204
|
+
* Text value.
|
|
205
|
+
*/
|
|
206
|
+
'string' |
|
|
207
|
+
/**
|
|
208
|
+
* Floating-point number.
|
|
209
|
+
*/
|
|
210
|
+
'number' |
|
|
211
|
+
/**
|
|
212
|
+
* Integer number.
|
|
213
|
+
*/
|
|
214
|
+
'integer' |
|
|
215
|
+
/**
|
|
216
|
+
* Big integer number.
|
|
217
|
+
*/
|
|
218
|
+
'bigint' |
|
|
219
|
+
/**
|
|
220
|
+
* Boolean value.
|
|
221
|
+
*/
|
|
222
|
+
'boolean' |
|
|
223
|
+
/**
|
|
224
|
+
* Null value.
|
|
225
|
+
*/
|
|
226
|
+
'null' |
|
|
227
|
+
/**
|
|
228
|
+
* Any value.
|
|
229
|
+
*/
|
|
230
|
+
'any' |
|
|
231
|
+
/**
|
|
232
|
+
* Unknown value.
|
|
233
|
+
*/
|
|
234
|
+
'unknown' |
|
|
235
|
+
/**
|
|
236
|
+
* No value (`void`).
|
|
237
|
+
*/
|
|
238
|
+
'void' |
|
|
239
|
+
/**
|
|
240
|
+
* Never value.
|
|
241
|
+
*/
|
|
242
|
+
'never' |
|
|
243
|
+
/**
|
|
244
|
+
* Object value.
|
|
245
|
+
*/
|
|
246
|
+
'object' |
|
|
247
|
+
/**
|
|
248
|
+
* Array value.
|
|
249
|
+
*/
|
|
250
|
+
'array' |
|
|
251
|
+
/**
|
|
252
|
+
* Date value.
|
|
253
|
+
*/
|
|
254
|
+
'date';
|
|
255
|
+
/**
|
|
256
|
+
* All schema type strings, one per key of {@link SchemaNodeByType}.
|
|
257
|
+
*/
|
|
258
|
+
type SchemaType = keyof SchemaNodeByType;
|
|
259
|
+
/**
|
|
260
|
+
* Scalar schema types without extra object/array/ref structure or constraints.
|
|
261
|
+
*/
|
|
262
|
+
type ScalarSchemaType = 'boolean' | 'null' | 'any' | 'unknown' | 'void' | 'never' | 'blob' | 'ipv4' | 'ipv6';
|
|
263
|
+
/**
|
|
264
|
+
* Fields shared by all schema nodes.
|
|
265
|
+
*/
|
|
266
|
+
type SchemaNodeBase = BaseNode & {
|
|
267
|
+
/**
|
|
268
|
+
* Node kind.
|
|
269
|
+
*/
|
|
270
|
+
kind: 'Schema';
|
|
271
|
+
/**
|
|
272
|
+
* Schema name for named definitions (for example, `"Pet"`).
|
|
273
|
+
* Inline schemas omit this field.
|
|
274
|
+
* `null` means Kubb has processed this and determined there is no applicable name.
|
|
275
|
+
* `undefined` means the name has not been set yet.
|
|
276
|
+
*/
|
|
277
|
+
name?: string | null;
|
|
278
|
+
/**
|
|
279
|
+
* Short schema title.
|
|
280
|
+
*/
|
|
281
|
+
title?: string;
|
|
282
|
+
/**
|
|
283
|
+
* Schema description text.
|
|
284
|
+
*/
|
|
285
|
+
description?: string;
|
|
286
|
+
/**
|
|
287
|
+
* Whether `null` is allowed.
|
|
288
|
+
*/
|
|
289
|
+
nullable?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Whether the field is optional.
|
|
292
|
+
*/
|
|
293
|
+
optional?: boolean;
|
|
294
|
+
/**
|
|
295
|
+
* Both optional and nullable (`optional` + `nullable`).
|
|
296
|
+
*/
|
|
297
|
+
nullish?: boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Whether the schema is deprecated.
|
|
300
|
+
*/
|
|
301
|
+
deprecated?: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* Whether the schema is read-only.
|
|
304
|
+
*/
|
|
305
|
+
readOnly?: boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Whether the schema is write-only.
|
|
308
|
+
*/
|
|
309
|
+
writeOnly?: boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Default value.
|
|
312
|
+
*/
|
|
313
|
+
default?: unknown;
|
|
314
|
+
/**
|
|
315
|
+
* Example values from an `examples` array.
|
|
316
|
+
*/
|
|
317
|
+
examples?: Array<unknown>;
|
|
318
|
+
/**
|
|
319
|
+
* Base primitive type.
|
|
320
|
+
* For example, this is `'string'` for a `uuid` schema.
|
|
321
|
+
*/
|
|
322
|
+
primitive?: PrimitiveSchemaType;
|
|
323
|
+
/**
|
|
324
|
+
* Schema `format` value.
|
|
325
|
+
*/
|
|
326
|
+
format?: string;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Object schema with ordered properties.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* const objectSchema: ObjectSchemaNode = {
|
|
334
|
+
* kind: 'Schema',
|
|
335
|
+
* type: 'object',
|
|
336
|
+
* properties: [],
|
|
337
|
+
* }
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
type ObjectSchemaNode = SchemaNodeBase & {
|
|
341
|
+
/**
|
|
342
|
+
* Schema type discriminator.
|
|
343
|
+
*/
|
|
344
|
+
type: 'object';
|
|
345
|
+
/**
|
|
346
|
+
* Primitive type, always `'object'` for object schemas.
|
|
347
|
+
*/
|
|
348
|
+
primitive: 'object';
|
|
349
|
+
/**
|
|
350
|
+
* Ordered object properties.
|
|
351
|
+
*/
|
|
352
|
+
properties: Array<PropertyNode>;
|
|
353
|
+
/**
|
|
354
|
+
* Additional object properties behavior:
|
|
355
|
+
* - `true`: allow any value
|
|
356
|
+
* - `false`: reject unknown properties
|
|
357
|
+
* - `SchemaNode`: allow values that match that schema
|
|
358
|
+
* - `undefined`: no additional properties constraint (open object)
|
|
359
|
+
*/
|
|
360
|
+
additionalProperties?: SchemaNode | boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Pattern-based property schemas.
|
|
363
|
+
*/
|
|
364
|
+
patternProperties?: Record<string, SchemaNode>;
|
|
365
|
+
/**
|
|
366
|
+
* Minimum number of properties allowed.
|
|
367
|
+
*/
|
|
368
|
+
minProperties?: number;
|
|
369
|
+
/**
|
|
370
|
+
* Maximum number of properties allowed.
|
|
371
|
+
*/
|
|
372
|
+
maxProperties?: number;
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Array-like schema (`array` or `tuple`).
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```ts
|
|
379
|
+
* const arraySchema: ArraySchemaNode = {
|
|
380
|
+
* kind: 'Schema',
|
|
381
|
+
* type: 'array',
|
|
382
|
+
* items: [],
|
|
383
|
+
* }
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
type ArraySchemaNode = SchemaNodeBase & {
|
|
387
|
+
/**
|
|
388
|
+
* Schema type discriminator (`array` or `tuple`).
|
|
389
|
+
*/
|
|
390
|
+
type: 'array' | 'tuple';
|
|
391
|
+
/**
|
|
392
|
+
* Item schemas.
|
|
393
|
+
*/
|
|
394
|
+
items?: Array<SchemaNode>;
|
|
395
|
+
/**
|
|
396
|
+
* Tuple rest-item schema for elements beyond positional `items`.
|
|
397
|
+
*/
|
|
398
|
+
rest?: SchemaNode;
|
|
399
|
+
/**
|
|
400
|
+
* Minimum item count (or tuple length).
|
|
401
|
+
*/
|
|
402
|
+
min?: number;
|
|
403
|
+
/**
|
|
404
|
+
* Maximum item count (or tuple length).
|
|
405
|
+
*/
|
|
406
|
+
max?: number;
|
|
407
|
+
/**
|
|
408
|
+
* Whether all items must be unique.
|
|
409
|
+
*/
|
|
410
|
+
unique?: boolean;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Shared shape for union and intersection schemas.
|
|
414
|
+
*/
|
|
415
|
+
type CompositeSchemaNodeBase = SchemaNodeBase & {
|
|
416
|
+
/**
|
|
417
|
+
* Member schemas.
|
|
418
|
+
*/
|
|
419
|
+
members?: Array<SchemaNode>;
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* Union schema, often from `oneOf` or `anyOf`.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* const unionSchema: UnionSchemaNode = {
|
|
427
|
+
* kind: 'Schema',
|
|
428
|
+
* type: 'union',
|
|
429
|
+
* members: [],
|
|
430
|
+
* }
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
type UnionSchemaNode = CompositeSchemaNodeBase & {
|
|
434
|
+
/**
|
|
435
|
+
* Schema type discriminator.
|
|
436
|
+
*/
|
|
437
|
+
type: 'union';
|
|
438
|
+
/**
|
|
439
|
+
* Discriminator property name for a polymorphic union.
|
|
440
|
+
*/
|
|
441
|
+
discriminatorPropertyName?: string;
|
|
442
|
+
/**
|
|
443
|
+
* How many union members must be valid.
|
|
444
|
+
* - `'one'`: exactly one member, from `oneOf`
|
|
445
|
+
* - `'any'`: any number of members, from `anyOf`
|
|
446
|
+
*/
|
|
447
|
+
strategy?: 'one' | 'any';
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Intersection schema, often from `allOf`.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```ts
|
|
454
|
+
* const intersectionSchema: IntersectionSchemaNode = {
|
|
455
|
+
* kind: 'Schema',
|
|
456
|
+
* type: 'intersection',
|
|
457
|
+
* members: [],
|
|
458
|
+
* }
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
type IntersectionSchemaNode = CompositeSchemaNodeBase & {
|
|
462
|
+
/**
|
|
463
|
+
* Schema type discriminator.
|
|
464
|
+
*/
|
|
465
|
+
type: 'intersection';
|
|
466
|
+
};
|
|
467
|
+
/** Negation from `not`: the value must not match its single member. Printers that cannot express it return `null`. */
|
|
468
|
+
type NotSchemaNode = CompositeSchemaNodeBase & {
|
|
469
|
+
/** Schema type discriminator. */
|
|
470
|
+
type: 'not';
|
|
471
|
+
};
|
|
472
|
+
/**
|
|
473
|
+
* One named enum item.
|
|
474
|
+
*/
|
|
475
|
+
type EnumValueNode = {
|
|
476
|
+
/**
|
|
477
|
+
* Enum item name.
|
|
478
|
+
*/
|
|
479
|
+
name: string;
|
|
480
|
+
/**
|
|
481
|
+
* Enum item value.
|
|
482
|
+
*/
|
|
483
|
+
value: string | number | boolean;
|
|
484
|
+
/**
|
|
485
|
+
* Primitive type of the enum value.
|
|
486
|
+
*/
|
|
487
|
+
primitive: Extract<PrimitiveSchemaType, 'string' | 'number' | 'boolean'>;
|
|
488
|
+
/**
|
|
489
|
+
* Label for the enum item, taken from the `x-enumDescriptions` or
|
|
490
|
+
* `x-enum-descriptions` vendor extension. `@kubb/plugin-ts` renders it as
|
|
491
|
+
* JSDoc on the matching enum member.
|
|
492
|
+
*/
|
|
493
|
+
description?: string;
|
|
494
|
+
};
|
|
495
|
+
/**
|
|
496
|
+
* Enum schema node.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* const enumSchema: EnumSchemaNode = {
|
|
501
|
+
* kind: 'Schema',
|
|
502
|
+
* type: 'enum',
|
|
503
|
+
* enumValues: ['a', 'b'],
|
|
504
|
+
* }
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
type EnumSchemaNode = SchemaNodeBase & {
|
|
508
|
+
/**
|
|
509
|
+
* Schema type discriminator.
|
|
510
|
+
*/
|
|
511
|
+
type: 'enum';
|
|
512
|
+
/**
|
|
513
|
+
* Enum values in simple form.
|
|
514
|
+
*/
|
|
515
|
+
enumValues?: Array<string | number | boolean | null>;
|
|
516
|
+
/**
|
|
517
|
+
* Enum values in named form.
|
|
518
|
+
* If present, this is used instead of `enumValues`.
|
|
519
|
+
*/
|
|
520
|
+
namedEnumValues?: Array<EnumValueNode>;
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Reference schema that points to another schema definition.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```ts
|
|
527
|
+
* const refSchema: RefSchemaNode = {
|
|
528
|
+
* kind: 'Schema',
|
|
529
|
+
* type: 'ref',
|
|
530
|
+
* ref: '#/components/schemas/Pet',
|
|
531
|
+
* }
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
type RefSchemaNode = SchemaNodeBase & {
|
|
535
|
+
/**
|
|
536
|
+
* Schema type discriminator.
|
|
537
|
+
*/
|
|
538
|
+
type: 'ref';
|
|
539
|
+
/**
|
|
540
|
+
* Referenced schema name.
|
|
541
|
+
* `null` means Kubb has processed this and determined there is no applicable name.
|
|
542
|
+
*/
|
|
543
|
+
name?: string | null;
|
|
544
|
+
/**
|
|
545
|
+
* Original `$ref` path, for example, `#/components/schemas/Order`.
|
|
546
|
+
* Used to resolve names later.
|
|
547
|
+
*/
|
|
548
|
+
ref?: string;
|
|
549
|
+
/**
|
|
550
|
+
* Emitted name of the referenced schema when it differs from the pointer's last segment,
|
|
551
|
+
* for example after a collision rename (`Order` becomes `OrderSchema`) or a macro rename.
|
|
552
|
+
* Resolve display and import names through `resolveRefName`, which prefers this field and
|
|
553
|
+
* falls back to the pointer segment, then `name`.
|
|
554
|
+
*/
|
|
555
|
+
targetName?: string;
|
|
556
|
+
/**
|
|
557
|
+
* Pattern copied from a sibling `pattern` field.
|
|
558
|
+
*/
|
|
559
|
+
pattern?: string;
|
|
560
|
+
/**
|
|
561
|
+
* The fully-parsed schema this ref resolves to, so its structure (`primitive`, `properties`)
|
|
562
|
+
* can be read without following the reference. Populated during parsing when the
|
|
563
|
+
* definition resolves, `null` when it can't or the ref is circular, and `undefined` when
|
|
564
|
+
* resolution has not been attempted.
|
|
565
|
+
*/
|
|
566
|
+
schema?: SchemaNode | null;
|
|
567
|
+
};
|
|
568
|
+
/**
|
|
569
|
+
* Datetime schema.
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```ts
|
|
573
|
+
* const datetimeSchema: DatetimeSchemaNode = { kind: 'Schema', type: 'datetime' }
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
type DatetimeSchemaNode = SchemaNodeBase & {
|
|
577
|
+
/**
|
|
578
|
+
* Schema type discriminator.
|
|
579
|
+
*/
|
|
580
|
+
type: 'datetime';
|
|
581
|
+
/**
|
|
582
|
+
* Whether the datetime includes a timezone offset (`dateType: 'stringOffset'`).
|
|
583
|
+
*/
|
|
584
|
+
offset?: boolean;
|
|
585
|
+
/**
|
|
586
|
+
* Whether the datetime is local (no timezone, `dateType: 'stringLocal'`).
|
|
587
|
+
*/
|
|
588
|
+
local?: boolean;
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* Shared base for `date` and `time` schemas.
|
|
592
|
+
*/
|
|
593
|
+
type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
|
|
594
|
+
/**
|
|
595
|
+
* Schema type discriminator.
|
|
596
|
+
*/
|
|
597
|
+
type: T;
|
|
598
|
+
/**
|
|
599
|
+
* Output representation in generated code.
|
|
600
|
+
*/
|
|
601
|
+
representation: 'date' | 'string';
|
|
602
|
+
};
|
|
603
|
+
/**
|
|
604
|
+
* Date schema node.
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* ```ts
|
|
608
|
+
* const dateSchema: DateSchemaNode = { kind: 'Schema', type: 'date', representation: 'string' }
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
type DateSchemaNode = TemporalSchemaNodeBase<'date'>;
|
|
612
|
+
/**
|
|
613
|
+
* Time schema node.
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```ts
|
|
617
|
+
* const timeSchema: TimeSchemaNode = { kind: 'Schema', type: 'time', representation: 'string' }
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
type TimeSchemaNode = TemporalSchemaNodeBase<'time'>;
|
|
621
|
+
/**
|
|
622
|
+
* String schema node.
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```ts
|
|
626
|
+
* const stringSchema: StringSchemaNode = { kind: 'Schema', type: 'string' }
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
type StringSchemaNode = SchemaNodeBase & {
|
|
630
|
+
/**
|
|
631
|
+
* Schema type discriminator.
|
|
632
|
+
*/
|
|
633
|
+
type: 'string';
|
|
634
|
+
/**
|
|
635
|
+
* Minimum string length.
|
|
636
|
+
*/
|
|
637
|
+
min?: number;
|
|
638
|
+
/**
|
|
639
|
+
* Maximum string length.
|
|
640
|
+
*/
|
|
641
|
+
max?: number;
|
|
642
|
+
/**
|
|
643
|
+
* Regex pattern.
|
|
644
|
+
*/
|
|
645
|
+
pattern?: string;
|
|
646
|
+
};
|
|
647
|
+
/**
|
|
648
|
+
* Numeric schema (`number`, `integer`, or `bigint`).
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* ```ts
|
|
652
|
+
* const numberSchema: NumberSchemaNode = { kind: 'Schema', type: 'number' }
|
|
653
|
+
* ```
|
|
654
|
+
*/
|
|
655
|
+
type NumberSchemaNode = SchemaNodeBase & {
|
|
656
|
+
/**
|
|
657
|
+
* Schema type discriminator.
|
|
658
|
+
*/
|
|
659
|
+
type: 'number' | 'integer' | 'bigint';
|
|
660
|
+
/**
|
|
661
|
+
* Minimum value.
|
|
662
|
+
*/
|
|
663
|
+
min?: number;
|
|
664
|
+
/**
|
|
665
|
+
* Maximum value.
|
|
666
|
+
*/
|
|
667
|
+
max?: number;
|
|
668
|
+
/**
|
|
669
|
+
* Exclusive minimum value.
|
|
670
|
+
*/
|
|
671
|
+
exclusiveMinimum?: number;
|
|
672
|
+
/**
|
|
673
|
+
* Exclusive maximum value.
|
|
674
|
+
*/
|
|
675
|
+
exclusiveMaximum?: number;
|
|
676
|
+
/**
|
|
677
|
+
* The value must be a multiple of this number.
|
|
678
|
+
*/
|
|
679
|
+
multipleOf?: number;
|
|
680
|
+
};
|
|
681
|
+
/**
|
|
682
|
+
* Scalar schema with no extra constraints.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* const anySchema: ScalarSchemaNode = { kind: 'Schema', type: 'any' }
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
type ScalarSchemaNode = SchemaNodeBase & {
|
|
690
|
+
/**
|
|
691
|
+
* Schema type discriminator.
|
|
692
|
+
*/
|
|
693
|
+
type: ScalarSchemaType;
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* URL schema node.
|
|
697
|
+
* Can include a path template for template literal types.
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets/{petId}' }
|
|
702
|
+
* ```
|
|
703
|
+
*/
|
|
704
|
+
type UrlSchemaNode = SchemaNodeBase & {
|
|
705
|
+
/**
|
|
706
|
+
* Schema type discriminator.
|
|
707
|
+
*/
|
|
708
|
+
type: 'url';
|
|
709
|
+
/**
|
|
710
|
+
* Path template, for example, `'/pets/{petId}'`.
|
|
711
|
+
*/
|
|
712
|
+
path?: string;
|
|
713
|
+
/**
|
|
714
|
+
* Minimum string length.
|
|
715
|
+
*/
|
|
716
|
+
min?: number;
|
|
717
|
+
/**
|
|
718
|
+
* Maximum string length.
|
|
719
|
+
*/
|
|
720
|
+
max?: number;
|
|
721
|
+
};
|
|
722
|
+
/**
|
|
723
|
+
* Format-string schema for string-based formats that support length constraints.
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* ```ts
|
|
727
|
+
* const uuidSchema: FormatStringSchemaNode = { kind: 'Schema', type: 'uuid', min: 36, max: 36 }
|
|
728
|
+
* ```
|
|
729
|
+
*/
|
|
730
|
+
type FormatStringSchemaNode = SchemaNodeBase & {
|
|
731
|
+
/**
|
|
732
|
+
* Schema type discriminator.
|
|
733
|
+
*/
|
|
734
|
+
type: 'uuid' | 'email';
|
|
735
|
+
/**
|
|
736
|
+
* Minimum string length.
|
|
737
|
+
*/
|
|
738
|
+
min?: number;
|
|
739
|
+
/**
|
|
740
|
+
* Maximum string length.
|
|
741
|
+
*/
|
|
742
|
+
max?: number;
|
|
743
|
+
};
|
|
744
|
+
/**
|
|
745
|
+
* Mapping from schema type literals to concrete schema node types.
|
|
746
|
+
* Used by `narrowSchema`.
|
|
747
|
+
*/
|
|
748
|
+
type SchemaNodeByType = {
|
|
749
|
+
object: ObjectSchemaNode;
|
|
750
|
+
array: ArraySchemaNode;
|
|
751
|
+
tuple: ArraySchemaNode;
|
|
752
|
+
union: UnionSchemaNode;
|
|
753
|
+
intersection: IntersectionSchemaNode;
|
|
754
|
+
not: NotSchemaNode;
|
|
755
|
+
enum: EnumSchemaNode;
|
|
756
|
+
ref: RefSchemaNode;
|
|
757
|
+
datetime: DatetimeSchemaNode;
|
|
758
|
+
date: DateSchemaNode;
|
|
759
|
+
time: TimeSchemaNode;
|
|
760
|
+
string: StringSchemaNode;
|
|
761
|
+
number: NumberSchemaNode;
|
|
762
|
+
integer: NumberSchemaNode;
|
|
763
|
+
bigint: NumberSchemaNode;
|
|
764
|
+
boolean: ScalarSchemaNode;
|
|
765
|
+
null: ScalarSchemaNode;
|
|
766
|
+
any: ScalarSchemaNode;
|
|
767
|
+
unknown: ScalarSchemaNode;
|
|
768
|
+
void: ScalarSchemaNode;
|
|
769
|
+
never: ScalarSchemaNode;
|
|
770
|
+
uuid: FormatStringSchemaNode;
|
|
771
|
+
email: FormatStringSchemaNode;
|
|
772
|
+
url: UrlSchemaNode;
|
|
773
|
+
ipv4: ScalarSchemaNode;
|
|
774
|
+
ipv6: ScalarSchemaNode;
|
|
775
|
+
blob: ScalarSchemaNode;
|
|
776
|
+
};
|
|
777
|
+
/**
|
|
778
|
+
* Union of all schema node types.
|
|
779
|
+
*/
|
|
780
|
+
type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | NotSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | FormatStringSchemaNode | ScalarSchemaNode;
|
|
781
|
+
type CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties' | 'primitive'> & {
|
|
782
|
+
properties?: Array<PropertyNode>;
|
|
783
|
+
primitive?: 'object';
|
|
784
|
+
};
|
|
785
|
+
type CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>;
|
|
786
|
+
type CreateSchemaOutput<T extends CreateSchemaInput> = SchemaNodeByType[T['type']] & {
|
|
787
|
+
kind: 'Schema';
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* Creates a `SchemaNode`, narrowed to the variant of `props.type`. Object schemas default
|
|
791
|
+
* `properties` to an empty array, and `primitive` is inferred from `type` when not explicitly provided.
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* ```ts
|
|
795
|
+
* const scalar = createSchema({ type: 'string' })
|
|
796
|
+
* // { kind: 'Schema', type: 'string', primitive: 'string' }
|
|
797
|
+
* ```
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```ts
|
|
801
|
+
* const object = createSchema({ type: 'object' })
|
|
802
|
+
* // { kind: 'Schema', type: 'object', primitive: 'object', properties: [] }
|
|
803
|
+
* ```
|
|
804
|
+
*/
|
|
805
|
+
declare function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>;
|
|
806
|
+
declare function createSchema(props: CreateSchemaInput): SchemaNode;
|
|
807
|
+
//#endregion
|
|
808
|
+
//#region src/nodes/parameter.d.ts
|
|
809
|
+
type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
|
|
810
|
+
/**
|
|
811
|
+
* Parameter serialization style, controlling how a parameter value is rendered into the request.
|
|
812
|
+
*/
|
|
813
|
+
type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
|
|
814
|
+
/**
|
|
815
|
+
* AST node representing one operation parameter.
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* ```ts
|
|
819
|
+
* const param: ParameterNode = {
|
|
820
|
+
* kind: 'Parameter',
|
|
821
|
+
* name: 'petId',
|
|
822
|
+
* in: 'path',
|
|
823
|
+
* schema: createSchema({ type: 'string' }),
|
|
824
|
+
* required: true,
|
|
825
|
+
* }
|
|
826
|
+
* ```
|
|
827
|
+
*/
|
|
828
|
+
type ParameterNode = BaseNode & {
|
|
829
|
+
kind: 'Parameter';
|
|
830
|
+
/**
|
|
831
|
+
* Parameter name.
|
|
832
|
+
*/
|
|
833
|
+
name: string;
|
|
834
|
+
/**
|
|
835
|
+
* Parameter location (`path`, `query`, `header`, or `cookie`).
|
|
836
|
+
*/
|
|
837
|
+
in: ParameterLocation;
|
|
838
|
+
/**
|
|
839
|
+
* Parameter schema.
|
|
840
|
+
*/
|
|
841
|
+
schema: SchemaNode;
|
|
842
|
+
/**
|
|
843
|
+
* Whether the parameter is required.
|
|
844
|
+
*/
|
|
845
|
+
required: boolean;
|
|
846
|
+
/**
|
|
847
|
+
* Serialization style. Absent when the source omits it, leaving consumers to apply the
|
|
848
|
+
* per-location default.
|
|
849
|
+
*/
|
|
850
|
+
style?: ParameterStyle;
|
|
851
|
+
/**
|
|
852
|
+
* Whether array and object values expand into separate values. Absent when the source omits it,
|
|
853
|
+
* leaving consumers to apply the default for the style.
|
|
854
|
+
*/
|
|
855
|
+
explode?: boolean;
|
|
856
|
+
/**
|
|
857
|
+
* Whether reserved characters (RFC 3986 `:/?#[]@!$&'()*+,;=`) are sent as-is instead of
|
|
858
|
+
* percent-encoded. Only applies to query parameters. Absent when the source omits it.
|
|
859
|
+
*/
|
|
860
|
+
allowReserved?: boolean;
|
|
861
|
+
};
|
|
862
|
+
type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>;
|
|
863
|
+
/**
|
|
864
|
+
* Creates a `ParameterNode`. `required` defaults to `false`, and the schema's
|
|
865
|
+
* `optional`/`nullish` flags are derived from it.
|
|
866
|
+
*
|
|
867
|
+
* @example
|
|
868
|
+
* ```ts
|
|
869
|
+
* const param = createParameter({
|
|
870
|
+
* name: 'petId',
|
|
871
|
+
* in: 'path',
|
|
872
|
+
* required: true,
|
|
873
|
+
* schema: createSchema({ type: 'string' }),
|
|
874
|
+
* })
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
declare function createParameter(input: UserParameterNode): ParameterNode;
|
|
878
|
+
//#endregion
|
|
879
|
+
//#region src/nodes/content.d.ts
|
|
880
|
+
/**
|
|
881
|
+
* AST node representing one content-type entry of a request body or response.
|
|
882
|
+
*
|
|
883
|
+
* There is one entry per content type declared in the spec (e.g. `application/json`,
|
|
884
|
+
* `multipart/form-data`), and each entry holds its own body schema.
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* ```ts
|
|
888
|
+
* const content: ContentNode = {
|
|
889
|
+
* kind: 'Content',
|
|
890
|
+
* contentType: 'application/json',
|
|
891
|
+
* schema: createSchema({ type: 'string' }),
|
|
892
|
+
* }
|
|
893
|
+
* ```
|
|
894
|
+
*/
|
|
895
|
+
type ContentNode = BaseNode & {
|
|
896
|
+
/**
|
|
897
|
+
* Node kind.
|
|
898
|
+
*/
|
|
899
|
+
kind: 'Content';
|
|
900
|
+
/**
|
|
901
|
+
* The content type for this entry (e.g. `'application/json'`).
|
|
902
|
+
*/
|
|
903
|
+
contentType: string;
|
|
904
|
+
/**
|
|
905
|
+
* Body schema for this content type.
|
|
906
|
+
*/
|
|
907
|
+
schema?: SchemaNode;
|
|
908
|
+
/**
|
|
909
|
+
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
910
|
+
* Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.
|
|
911
|
+
*/
|
|
912
|
+
keysToOmit?: Array<string> | null;
|
|
913
|
+
};
|
|
914
|
+
/**
|
|
915
|
+
* Creates a `ContentNode` for a single request-body or response content type.
|
|
916
|
+
*/
|
|
917
|
+
declare const createContent: (input: Omit<ContentNode, "kind">) => ContentNode;
|
|
918
|
+
//#endregion
|
|
919
|
+
//#region src/nodes/requestBody.d.ts
|
|
920
|
+
/**
|
|
921
|
+
* AST node representing an operation request body.
|
|
922
|
+
*
|
|
923
|
+
* Body schemas live exclusively inside the `content` array (one entry per content type),
|
|
924
|
+
* mirroring {@link ResponseNode}.
|
|
925
|
+
*
|
|
926
|
+
* @example
|
|
927
|
+
* ```ts
|
|
928
|
+
* const requestBody: RequestBodyNode = {
|
|
929
|
+
* kind: 'RequestBody',
|
|
930
|
+
* required: true,
|
|
931
|
+
* content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
|
|
932
|
+
* }
|
|
933
|
+
* ```
|
|
934
|
+
*/
|
|
935
|
+
type RequestBodyNode = BaseNode & {
|
|
936
|
+
kind: 'RequestBody';
|
|
937
|
+
/**
|
|
938
|
+
* Request body description carried over from the spec.
|
|
939
|
+
*/
|
|
940
|
+
description?: string;
|
|
941
|
+
/**
|
|
942
|
+
* Whether the request body is required (`requestBody.required: true` in the spec).
|
|
943
|
+
* When `false` or absent, the generated `data` parameter should be optional.
|
|
944
|
+
*/
|
|
945
|
+
required?: boolean;
|
|
946
|
+
/**
|
|
947
|
+
* Content type entries for this request body.
|
|
948
|
+
*
|
|
949
|
+
* When the adapter `contentType` option is set, this array contains exactly one entry for
|
|
950
|
+
* that content type. Otherwise it contains one entry per content type declared in the spec,
|
|
951
|
+
* so plugins can generate code for every variant (for example, separate hooks for
|
|
952
|
+
* `application/json` and `multipart/form-data`).
|
|
953
|
+
*/
|
|
954
|
+
content?: Array<ContentNode>;
|
|
955
|
+
};
|
|
956
|
+
/**
|
|
957
|
+
* Creates a `RequestBodyNode`.
|
|
958
|
+
*/
|
|
959
|
+
declare const createRequestBody: (input: Omit<RequestBodyNode, "kind">) => RequestBodyNode;
|
|
960
|
+
//#endregion
|
|
961
|
+
//#region src/nodes/response.d.ts
|
|
962
|
+
type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
963
|
+
/**
|
|
964
|
+
* Response status code literal used by operations.
|
|
965
|
+
*
|
|
966
|
+
* Includes three-digit HTTP status code strings and `"default"` for catch-all responses.
|
|
967
|
+
*
|
|
968
|
+
* @example
|
|
969
|
+
* ```ts
|
|
970
|
+
* const status: StatusCode = '200'
|
|
971
|
+
* const fallback: StatusCode = 'default'
|
|
972
|
+
* ```
|
|
973
|
+
*/
|
|
974
|
+
type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | 'default';
|
|
975
|
+
/**
|
|
976
|
+
* AST node representing one operation response variant.
|
|
977
|
+
*
|
|
978
|
+
* Mirrors {@link OperationNode.requestBody}: the response body schemas live exclusively inside
|
|
979
|
+
* the `content` array (one entry per content type), so the same schema is never duplicated at the
|
|
980
|
+
* node root and inside `content`.
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* ```ts
|
|
984
|
+
* const response: ResponseNode = {
|
|
985
|
+
* kind: 'Response',
|
|
986
|
+
* statusCode: '200',
|
|
987
|
+
* content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
|
|
988
|
+
* }
|
|
989
|
+
* ```
|
|
990
|
+
*/
|
|
991
|
+
type ResponseNode = BaseNode & {
|
|
992
|
+
/**
|
|
993
|
+
* Node kind.
|
|
994
|
+
*/
|
|
995
|
+
kind: 'Response';
|
|
996
|
+
/**
|
|
997
|
+
* HTTP status code or `'default'` for a fallback response.
|
|
998
|
+
*/
|
|
999
|
+
statusCode: StatusCode;
|
|
1000
|
+
/**
|
|
1001
|
+
* Optional response description.
|
|
1002
|
+
*/
|
|
1003
|
+
description?: string;
|
|
1004
|
+
/**
|
|
1005
|
+
* All available content type entries for this response.
|
|
1006
|
+
*
|
|
1007
|
+
* When the adapter `contentType` option is set, this array contains exactly one entry for that
|
|
1008
|
+
* content type. Otherwise it contains one entry per content type declared in the spec, so that
|
|
1009
|
+
* plugins can generate a union of response types (e.g. `application/json` and `application/xml`).
|
|
1010
|
+
* Body-less responses keep a single entry whose `schema` is the empty/`void` placeholder.
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```ts
|
|
1014
|
+
* // spec response declares both application/json and application/xml
|
|
1015
|
+
* response.content[0].contentType // 'application/json'
|
|
1016
|
+
* response.content[1].contentType // 'application/xml'
|
|
1017
|
+
* ```
|
|
1018
|
+
*/
|
|
1019
|
+
content?: Array<ContentNode>;
|
|
1020
|
+
};
|
|
1021
|
+
type ResponseInput = Pick<ResponseNode, 'statusCode'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {
|
|
1022
|
+
content?: Array<ContentNode>;
|
|
1023
|
+
schema?: SchemaNode;
|
|
1024
|
+
mediaType?: string | null;
|
|
1025
|
+
keysToOmit?: Array<string> | null;
|
|
1026
|
+
};
|
|
1027
|
+
/**
|
|
1028
|
+
* Creates a `ResponseNode`. A single legacy `schema` (with optional `mediaType`/`keysToOmit`)
|
|
1029
|
+
* is normalized into one `content` entry.
|
|
1030
|
+
*
|
|
1031
|
+
* @example
|
|
1032
|
+
* ```ts
|
|
1033
|
+
* const response = createResponse({
|
|
1034
|
+
* statusCode: '200',
|
|
1035
|
+
* content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })],
|
|
1036
|
+
* })
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
1039
|
+
declare function createResponse(props: ResponseInput): ResponseNode;
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/nodes/operation.d.ts
|
|
1042
|
+
/**
|
|
1043
|
+
* HTTP method an operation responds to. `QUERY` is the safe, idempotent method with a request body
|
|
1044
|
+
* from RFC 10008, declared with the `query` field of an OpenAPI 3.2 path item.
|
|
1045
|
+
*/
|
|
1046
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'QUERY';
|
|
1047
|
+
/**
|
|
1048
|
+
* Fields shared by every operation, regardless of transport.
|
|
1049
|
+
*/
|
|
1050
|
+
type OperationNodeBase = BaseNode & {
|
|
1051
|
+
/**
|
|
1052
|
+
* Node kind.
|
|
1053
|
+
*/
|
|
1054
|
+
kind: 'Operation';
|
|
1055
|
+
/**
|
|
1056
|
+
* Stable identifier for the operation.
|
|
1057
|
+
*/
|
|
1058
|
+
operationId: string;
|
|
1059
|
+
/**
|
|
1060
|
+
* Group labels for the operation.
|
|
1061
|
+
*/
|
|
1062
|
+
tags: Array<string>;
|
|
1063
|
+
/**
|
|
1064
|
+
* Short one-line operation summary.
|
|
1065
|
+
*/
|
|
1066
|
+
summary?: string;
|
|
1067
|
+
/**
|
|
1068
|
+
* Full operation description.
|
|
1069
|
+
*/
|
|
1070
|
+
description?: string;
|
|
1071
|
+
/**
|
|
1072
|
+
* Marks the operation as deprecated.
|
|
1073
|
+
*/
|
|
1074
|
+
deprecated?: boolean;
|
|
1075
|
+
/**
|
|
1076
|
+
* Query, path, header, and cookie parameters for the operation.
|
|
1077
|
+
*/
|
|
1078
|
+
parameters: Array<ParameterNode>;
|
|
1079
|
+
/**
|
|
1080
|
+
* Request body for the operation.
|
|
1081
|
+
*/
|
|
1082
|
+
requestBody?: RequestBodyNode;
|
|
1083
|
+
/**
|
|
1084
|
+
* Operation responses.
|
|
1085
|
+
*/
|
|
1086
|
+
responses: Array<ResponseNode>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Vendor extensions (`x-*` keys) from the source operation, copied as-is. Absent when the source has none.
|
|
1089
|
+
*/
|
|
1090
|
+
extensions?: Record<string, unknown>;
|
|
1091
|
+
};
|
|
1092
|
+
/**
|
|
1093
|
+
* Operation served over HTTP. `method` and `path` are guaranteed.
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* ```ts
|
|
1097
|
+
* const operation: HttpOperationNode = {
|
|
1098
|
+
* kind: 'Operation',
|
|
1099
|
+
* operationId: 'listPets',
|
|
1100
|
+
* protocol: 'http',
|
|
1101
|
+
* method: 'GET',
|
|
1102
|
+
* path: '/pets',
|
|
1103
|
+
* tags: [],
|
|
1104
|
+
* parameters: [],
|
|
1105
|
+
* responses: [],
|
|
1106
|
+
* }
|
|
1107
|
+
* ```
|
|
1108
|
+
*/
|
|
1109
|
+
type HttpOperationNode = OperationNodeBase & {
|
|
1110
|
+
/**
|
|
1111
|
+
* Transport the operation belongs to.
|
|
1112
|
+
*/
|
|
1113
|
+
protocol?: 'http';
|
|
1114
|
+
/**
|
|
1115
|
+
* HTTP method like `'GET'`.
|
|
1116
|
+
*/
|
|
1117
|
+
method: HttpMethod;
|
|
1118
|
+
/**
|
|
1119
|
+
* Path string, for example `/pets/{petId}`, with `{param}` notation preserved.
|
|
1120
|
+
*/
|
|
1121
|
+
path: string;
|
|
1122
|
+
};
|
|
1123
|
+
/**
|
|
1124
|
+
* Operation for a non-HTTP transport. HTTP-only fields are forbidden.
|
|
1125
|
+
*/
|
|
1126
|
+
type GenericOperationNode = OperationNodeBase & {
|
|
1127
|
+
protocol?: never;
|
|
1128
|
+
method?: never;
|
|
1129
|
+
path?: never;
|
|
1130
|
+
};
|
|
1131
|
+
/**
|
|
1132
|
+
* AST node representing one API operation.
|
|
1133
|
+
*
|
|
1134
|
+
* Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees
|
|
1135
|
+
* `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with
|
|
1136
|
+
* `isHttpOperationNode(node)` or `node.protocol === 'http'` before reading `method`/`path`.
|
|
1137
|
+
*/
|
|
1138
|
+
type OperationNode = HttpOperationNode | GenericOperationNode;
|
|
1139
|
+
/**
|
|
1140
|
+
* Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.
|
|
1141
|
+
* HTTP operations (those carrying both `method` and `path`) are tagged with `protocol: 'http'`,
|
|
1142
|
+
* and the request body is normalized into a `RequestBodyNode`.
|
|
1143
|
+
*
|
|
1144
|
+
* @example
|
|
1145
|
+
* ```ts
|
|
1146
|
+
* const operation = createOperation({ operationId: 'getPetById', method: 'GET', path: '/pet/{petId}' })
|
|
1147
|
+
* // tags, parameters, and responses are []
|
|
1148
|
+
* ```
|
|
1149
|
+
*/
|
|
1150
|
+
declare function createOperation(props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {
|
|
1151
|
+
requestBody?: Omit<RequestBodyNode, 'kind'>;
|
|
1152
|
+
}): HttpOperationNode;
|
|
1153
|
+
declare function createOperation(props: Pick<GenericOperationNode, 'operationId'> & Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {
|
|
1154
|
+
requestBody?: Omit<RequestBodyNode, 'kind'>;
|
|
1155
|
+
}): GenericOperationNode;
|
|
1156
|
+
//#endregion
|
|
1157
|
+
//#region src/guards.d.ts
|
|
1158
|
+
/**
|
|
1159
|
+
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
1160
|
+
*
|
|
1161
|
+
* @example
|
|
1162
|
+
* ```ts
|
|
1163
|
+
* const schema = createSchema({ type: 'string' })
|
|
1164
|
+
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
|
|
1165
|
+
* ```
|
|
1166
|
+
*/
|
|
1167
|
+
export declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null;
|
|
1168
|
+
/**
|
|
1169
|
+
* Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
|
|
1170
|
+
*
|
|
1171
|
+
* @example
|
|
1172
|
+
* ```ts
|
|
1173
|
+
* if (isHttpOperationNode(node)) {
|
|
1174
|
+
* console.log(node.method, node.path)
|
|
1175
|
+
* }
|
|
1176
|
+
* ```
|
|
1177
|
+
*/
|
|
1178
|
+
export declare function isHttpOperationNode(node: OperationNode): node is HttpOperationNode;
|
|
1179
|
+
//#endregion
|
|
1180
|
+
//#region src/nodes/code.d.ts
|
|
1181
|
+
/**
|
|
1182
|
+
* JSDoc documentation metadata attached to code declarations.
|
|
1183
|
+
*/
|
|
1184
|
+
type JSDocNode = {
|
|
1185
|
+
/**
|
|
1186
|
+
* JSDoc comment lines. `undefined` entries are filtered out during rendering.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```ts
|
|
1190
|
+
* ['@description A pet resource', '@deprecated']
|
|
1191
|
+
* ```
|
|
1192
|
+
*/
|
|
1193
|
+
comments?: Array<string | undefined>;
|
|
1194
|
+
};
|
|
1195
|
+
/**
|
|
1196
|
+
* AST node representing a TypeScript `const` declaration.
|
|
1197
|
+
*
|
|
1198
|
+
* Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
|
|
1199
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
1200
|
+
*
|
|
1201
|
+
* @example
|
|
1202
|
+
* ```ts
|
|
1203
|
+
* createConst({ name: 'pet', export: true, asConst: true })
|
|
1204
|
+
* // export const pet = ... as const
|
|
1205
|
+
* ```
|
|
1206
|
+
*/
|
|
1207
|
+
type ConstNode = BaseNode & {
|
|
1208
|
+
kind: 'Const';
|
|
1209
|
+
/**
|
|
1210
|
+
* Name of the constant declaration.
|
|
1211
|
+
*/
|
|
1212
|
+
name: string;
|
|
1213
|
+
/**
|
|
1214
|
+
* Whether the declaration should be exported.
|
|
1215
|
+
*/
|
|
1216
|
+
export?: boolean | null;
|
|
1217
|
+
/**
|
|
1218
|
+
* Explicit type annotation.
|
|
1219
|
+
*
|
|
1220
|
+
* @example Type reference
|
|
1221
|
+
* `'Pet'`
|
|
1222
|
+
*/
|
|
1223
|
+
type?: string | null;
|
|
1224
|
+
/**
|
|
1225
|
+
* JSDoc documentation metadata.
|
|
1226
|
+
*/
|
|
1227
|
+
JSDoc?: JSDocNode | null;
|
|
1228
|
+
/**
|
|
1229
|
+
* Whether to append `as const` to the declaration.
|
|
1230
|
+
*/
|
|
1231
|
+
asConst?: boolean | null;
|
|
1232
|
+
/**
|
|
1233
|
+
* Child nodes representing the value of the constant (children of the `Const` component).
|
|
1234
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
1235
|
+
*/
|
|
1236
|
+
nodes?: Array<CodeNode>;
|
|
1237
|
+
};
|
|
1238
|
+
/**
|
|
1239
|
+
* AST node representing a TypeScript `type` alias declaration.
|
|
1240
|
+
*
|
|
1241
|
+
* Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
|
|
1242
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
1243
|
+
*
|
|
1244
|
+
* @example
|
|
1245
|
+
* ```ts
|
|
1246
|
+
* createType({ name: 'Pet', export: true })
|
|
1247
|
+
* // export type Pet = ...
|
|
1248
|
+
* ```
|
|
1249
|
+
*/
|
|
1250
|
+
type TypeNode = BaseNode & {
|
|
1251
|
+
kind: 'Type';
|
|
1252
|
+
/**
|
|
1253
|
+
* Name of the type alias.
|
|
1254
|
+
*/
|
|
1255
|
+
name: string;
|
|
1256
|
+
/**
|
|
1257
|
+
* Whether the declaration should be exported.
|
|
1258
|
+
*/
|
|
1259
|
+
export?: boolean | null;
|
|
1260
|
+
/**
|
|
1261
|
+
* JSDoc documentation metadata.
|
|
1262
|
+
*/
|
|
1263
|
+
JSDoc?: JSDocNode | null;
|
|
1264
|
+
/**
|
|
1265
|
+
* Child nodes representing the type body (children of the `Type` component).
|
|
1266
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
1267
|
+
*/
|
|
1268
|
+
nodes?: Array<CodeNode>;
|
|
1269
|
+
};
|
|
1270
|
+
/**
|
|
1271
|
+
* AST node representing a TypeScript `function` declaration.
|
|
1272
|
+
*
|
|
1273
|
+
* Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
|
|
1274
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
1275
|
+
*
|
|
1276
|
+
* @example
|
|
1277
|
+
* ```ts
|
|
1278
|
+
* createFunction({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
|
|
1279
|
+
* // export async function getPet(): Promise<Pet> { ... }
|
|
1280
|
+
* ```
|
|
1281
|
+
*/
|
|
1282
|
+
type FunctionNode = BaseNode & {
|
|
1283
|
+
kind: 'Function';
|
|
1284
|
+
/**
|
|
1285
|
+
* Name of the function.
|
|
1286
|
+
*/
|
|
1287
|
+
name: string;
|
|
1288
|
+
/**
|
|
1289
|
+
* Whether the function is a default export.
|
|
1290
|
+
*/
|
|
1291
|
+
default?: boolean | null;
|
|
1292
|
+
/**
|
|
1293
|
+
* Function parameter list as a pre-rendered string, written verbatim between the parentheses.
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* `'id: string, config: Config = {}'`
|
|
1297
|
+
*/
|
|
1298
|
+
params?: string | null;
|
|
1299
|
+
/**
|
|
1300
|
+
* Whether the function should be exported.
|
|
1301
|
+
*/
|
|
1302
|
+
export?: boolean | null;
|
|
1303
|
+
/**
|
|
1304
|
+
* Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
1305
|
+
*/
|
|
1306
|
+
async?: boolean | null;
|
|
1307
|
+
/**
|
|
1308
|
+
* TypeScript generic type parameters.
|
|
1309
|
+
*
|
|
1310
|
+
* @example Constrained generics
|
|
1311
|
+
* `['T', 'U extends string']`
|
|
1312
|
+
*/
|
|
1313
|
+
generics?: string | Array<string> | null;
|
|
1314
|
+
/**
|
|
1315
|
+
* Return type annotation.
|
|
1316
|
+
*
|
|
1317
|
+
* @example Type reference
|
|
1318
|
+
* `'Pet'`
|
|
1319
|
+
*/
|
|
1320
|
+
returnType?: string | null;
|
|
1321
|
+
/**
|
|
1322
|
+
* JSDoc documentation metadata.
|
|
1323
|
+
*/
|
|
1324
|
+
JSDoc?: JSDocNode | null;
|
|
1325
|
+
/**
|
|
1326
|
+
* Child nodes representing the function body (children of the `Function` component).
|
|
1327
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
1328
|
+
*/
|
|
1329
|
+
nodes?: Array<CodeNode>;
|
|
1330
|
+
};
|
|
1331
|
+
/**
|
|
1332
|
+
* AST node representing a TypeScript arrow function (`const name = () => { ... }`).
|
|
1333
|
+
*
|
|
1334
|
+
* Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
|
|
1335
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
1336
|
+
*
|
|
1337
|
+
* @example
|
|
1338
|
+
* ```ts
|
|
1339
|
+
* createArrowFunction({ name: 'getPet', export: true, singleLine: true })
|
|
1340
|
+
* // export const getPet = () => ...
|
|
1341
|
+
* ```
|
|
1342
|
+
*/
|
|
1343
|
+
type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {
|
|
1344
|
+
kind: 'ArrowFunction';
|
|
1345
|
+
/**
|
|
1346
|
+
* Render the arrow function body as a single-line expression.
|
|
1347
|
+
*/
|
|
1348
|
+
singleLine?: boolean | null;
|
|
1349
|
+
};
|
|
1350
|
+
/**
|
|
1351
|
+
* AST node representing a raw text/string fragment in the source output.
|
|
1352
|
+
*
|
|
1353
|
+
* Used instead of bare `string` values so that all entries in `nodes` arrays
|
|
1354
|
+
* are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
|
|
1355
|
+
*
|
|
1356
|
+
* @example
|
|
1357
|
+
* ```ts
|
|
1358
|
+
* createText('return fetch(id)')
|
|
1359
|
+
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
1360
|
+
* ```
|
|
1361
|
+
*/
|
|
1362
|
+
type TextNode = BaseNode & {
|
|
1363
|
+
kind: 'Text';
|
|
1364
|
+
/**
|
|
1365
|
+
* The raw string content.
|
|
1366
|
+
*/
|
|
1367
|
+
value: string;
|
|
1368
|
+
};
|
|
1369
|
+
/**
|
|
1370
|
+
* AST node representing a blank line in the source output.
|
|
1371
|
+
*
|
|
1372
|
+
* Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two
|
|
1373
|
+
* statements into one blank line. Consecutive breaks, and breaks at the start or end of
|
|
1374
|
+
* the list, are folded away, so a `Break` never produces more than one blank line.
|
|
1375
|
+
*
|
|
1376
|
+
* @example
|
|
1377
|
+
* ```ts
|
|
1378
|
+
* createBreak()
|
|
1379
|
+
* // { kind: 'Break' }
|
|
1380
|
+
* ```
|
|
1381
|
+
*/
|
|
1382
|
+
type BreakNode = BaseNode & {
|
|
1383
|
+
kind: 'Break';
|
|
1384
|
+
};
|
|
1385
|
+
/**
|
|
1386
|
+
* AST node representing a raw JSX fragment in the source output.
|
|
1387
|
+
*
|
|
1388
|
+
* Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
|
|
1389
|
+
* (including fragments `<>…</>`) directly in generated code.
|
|
1390
|
+
*
|
|
1391
|
+
* @example
|
|
1392
|
+
* ```ts
|
|
1393
|
+
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
1394
|
+
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
1395
|
+
* ```
|
|
1396
|
+
*/
|
|
1397
|
+
type JsxNode = BaseNode & {
|
|
1398
|
+
kind: 'Jsx';
|
|
1399
|
+
/**
|
|
1400
|
+
* The raw JSX string content.
|
|
1401
|
+
*/
|
|
1402
|
+
value: string;
|
|
1403
|
+
};
|
|
1404
|
+
/**
|
|
1405
|
+
* Union of all code-generation AST nodes.
|
|
1406
|
+
*
|
|
1407
|
+
* These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
|
|
1408
|
+
* structured children in {@link SourceNode.nodes}.
|
|
1409
|
+
*/
|
|
1410
|
+
type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
|
|
1411
|
+
/**
|
|
1412
|
+
* Creates a `ConstNode` representing a TypeScript `const` declaration.
|
|
1413
|
+
*
|
|
1414
|
+
* @example Exported constant with type and `as const`
|
|
1415
|
+
* ```ts
|
|
1416
|
+
* createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
|
|
1417
|
+
* // export const pets: Pet[] = ... as const
|
|
1418
|
+
* ```
|
|
1419
|
+
*/
|
|
1420
|
+
declare const createConst: (input: Omit<ConstNode, "kind">) => ConstNode;
|
|
1421
|
+
/**
|
|
1422
|
+
* Creates a `TypeNode` representing a TypeScript `type` alias declaration.
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* ```ts
|
|
1426
|
+
* createType({ name: 'Pet', export: true })
|
|
1427
|
+
* // export type Pet = ...
|
|
1428
|
+
* ```
|
|
1429
|
+
*/
|
|
1430
|
+
declare const createType: (input: Omit<TypeNode, "kind">) => TypeNode;
|
|
1431
|
+
/**
|
|
1432
|
+
* Creates a `FunctionNode` representing a TypeScript `function` declaration.
|
|
1433
|
+
*
|
|
1434
|
+
* @example
|
|
1435
|
+
* ```ts
|
|
1436
|
+
* createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
|
|
1437
|
+
* // export async function fetchPet(): Promise<Pet> { ... }
|
|
1438
|
+
* ```
|
|
1439
|
+
*/
|
|
1440
|
+
declare const createFunction: (input: Omit<FunctionNode, "kind">) => FunctionNode;
|
|
1441
|
+
/**
|
|
1442
|
+
* Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
|
|
1443
|
+
*
|
|
1444
|
+
* @example
|
|
1445
|
+
* ```ts
|
|
1446
|
+
* createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
|
|
1447
|
+
* // export const double = (n: number) => ...
|
|
1448
|
+
* ```
|
|
1449
|
+
*/
|
|
1450
|
+
declare const createArrowFunction: (input: Omit<ArrowFunctionNode, "kind">) => ArrowFunctionNode;
|
|
1451
|
+
/**
|
|
1452
|
+
* Creates a {@link TextNode} representing a raw string fragment in the source output.
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```ts
|
|
1456
|
+
* createText('return fetch(id)')
|
|
1457
|
+
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
1458
|
+
* ```
|
|
1459
|
+
*/
|
|
1460
|
+
declare function createText(value: string): TextNode;
|
|
1461
|
+
/**
|
|
1462
|
+
* Creates a {@link BreakNode} representing a line break in the source output.
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```ts
|
|
1466
|
+
* createBreak()
|
|
1467
|
+
* // { kind: 'Break' }
|
|
1468
|
+
* ```
|
|
1469
|
+
*/
|
|
1470
|
+
declare function createBreak(): BreakNode;
|
|
1471
|
+
/**
|
|
1472
|
+
* Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
|
|
1473
|
+
*
|
|
1474
|
+
* @example
|
|
1475
|
+
* ```ts
|
|
1476
|
+
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
1477
|
+
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
1478
|
+
* ```
|
|
1479
|
+
*/
|
|
1480
|
+
declare function createJsx(value: string): JsxNode;
|
|
1481
|
+
//#endregion
|
|
1482
|
+
//#region src/nodes/file.d.ts
|
|
1483
|
+
/**
|
|
1484
|
+
* Supported file extensions.
|
|
1485
|
+
*/
|
|
1486
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
1487
|
+
type ImportName = string | Array<string | {
|
|
1488
|
+
propertyName: string;
|
|
1489
|
+
name?: string;
|
|
1490
|
+
}>;
|
|
1491
|
+
/**
|
|
1492
|
+
* Represents a language-agnostic import/dependency declaration.
|
|
1493
|
+
*
|
|
1494
|
+
* @example Named import (TypeScript: `import { useState } from 'react'`)
|
|
1495
|
+
* ```ts
|
|
1496
|
+
* createImport({ name: ['useState'], path: 'react' })
|
|
1497
|
+
* ```
|
|
1498
|
+
*
|
|
1499
|
+
* @example Default import (TypeScript: `import React from 'react'`)
|
|
1500
|
+
* ```ts
|
|
1501
|
+
* createImport({ name: 'React', path: 'react' })
|
|
1502
|
+
* ```
|
|
1503
|
+
*
|
|
1504
|
+
* @example Type-only import (TypeScript: `import type { FC } from 'react'`)
|
|
1505
|
+
* ```ts
|
|
1506
|
+
* createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
|
|
1507
|
+
* ```
|
|
1508
|
+
*
|
|
1509
|
+
* @example Namespace import (TypeScript: `import * as React from 'react'`)
|
|
1510
|
+
* ```ts
|
|
1511
|
+
* createImport({ name: 'React', path: 'react', isNameSpace: true })
|
|
1512
|
+
* ```
|
|
1513
|
+
*/
|
|
1514
|
+
type ImportNode = BaseNode & {
|
|
1515
|
+
kind: 'Import';
|
|
1516
|
+
/**
|
|
1517
|
+
* Import name(s) to be used.
|
|
1518
|
+
*
|
|
1519
|
+
* @example Named imports
|
|
1520
|
+
* `['useState']`
|
|
1521
|
+
*
|
|
1522
|
+
* @example Default import
|
|
1523
|
+
* `'React'`
|
|
1524
|
+
*/
|
|
1525
|
+
name: ImportName;
|
|
1526
|
+
/**
|
|
1527
|
+
* Path for the import.
|
|
1528
|
+
*
|
|
1529
|
+
* @example
|
|
1530
|
+
* `'@kubb/core'`
|
|
1531
|
+
*/
|
|
1532
|
+
path: string;
|
|
1533
|
+
/**
|
|
1534
|
+
* Add a type-only import prefix.
|
|
1535
|
+
* - `true` generates `import type { Type } from './path'`
|
|
1536
|
+
* - `false` generates `import { Type } from './path'`
|
|
1537
|
+
*/
|
|
1538
|
+
isTypeOnly?: boolean | null;
|
|
1539
|
+
/**
|
|
1540
|
+
* Import the entire module as a namespace.
|
|
1541
|
+
* - `true` generates `import * as Name from './path'`
|
|
1542
|
+
* - `false` generates a standard import
|
|
1543
|
+
*/
|
|
1544
|
+
isNameSpace?: boolean | null;
|
|
1545
|
+
/**
|
|
1546
|
+
* When set, the import path is resolved relative to this root.
|
|
1547
|
+
*/
|
|
1548
|
+
root?: string | null;
|
|
1549
|
+
};
|
|
1550
|
+
/**
|
|
1551
|
+
* Represents a language-agnostic export/public API declaration.
|
|
1552
|
+
*
|
|
1553
|
+
* @example Named export (TypeScript: `export { Pets } from './Pets'`)
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* createExport({ name: ['Pets'], path: './Pets' })
|
|
1556
|
+
* ```
|
|
1557
|
+
*
|
|
1558
|
+
* @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
|
|
1559
|
+
* ```ts
|
|
1560
|
+
* createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
|
|
1561
|
+
* ```
|
|
1562
|
+
*
|
|
1563
|
+
* @example Wildcard export (TypeScript: `export * from './utils'`)
|
|
1564
|
+
* ```ts
|
|
1565
|
+
* createExport({ path: './utils' })
|
|
1566
|
+
* ```
|
|
1567
|
+
*
|
|
1568
|
+
* @example Namespace alias (TypeScript: `export * as utils from './utils'`)
|
|
1569
|
+
* ```ts
|
|
1570
|
+
* createExport({ name: 'utils', path: './utils', asAlias: true })
|
|
1571
|
+
* ```
|
|
1572
|
+
*/
|
|
1573
|
+
type ExportNode = BaseNode & {
|
|
1574
|
+
kind: 'Export';
|
|
1575
|
+
/**
|
|
1576
|
+
* Export name(s) to be used. When omitted, generates a wildcard export.
|
|
1577
|
+
*
|
|
1578
|
+
* @example Named exports
|
|
1579
|
+
* `['useState']`
|
|
1580
|
+
*
|
|
1581
|
+
* @example Single export
|
|
1582
|
+
* `'React'`
|
|
1583
|
+
*/
|
|
1584
|
+
name?: string | Array<string> | null;
|
|
1585
|
+
/**
|
|
1586
|
+
* Path for the export.
|
|
1587
|
+
*
|
|
1588
|
+
* @example
|
|
1589
|
+
* `'@kubb/core'`
|
|
1590
|
+
*/
|
|
1591
|
+
path: string;
|
|
1592
|
+
/**
|
|
1593
|
+
* Add a type-only export prefix.
|
|
1594
|
+
* - `true` generates `export type { Type } from './path'`
|
|
1595
|
+
* - `false` generates `export { Type } from './path'`
|
|
1596
|
+
*/
|
|
1597
|
+
isTypeOnly?: boolean | null;
|
|
1598
|
+
/**
|
|
1599
|
+
* Export as an aliased namespace.
|
|
1600
|
+
* - `true` generates `export * as aliasName from './path'`
|
|
1601
|
+
* - `false` generates a standard export
|
|
1602
|
+
*/
|
|
1603
|
+
asAlias?: boolean | null;
|
|
1604
|
+
};
|
|
1605
|
+
/**
|
|
1606
|
+
* Represents a fragment of source code within a file.
|
|
1607
|
+
*
|
|
1608
|
+
* @example Named exportable source
|
|
1609
|
+
* ```ts
|
|
1610
|
+
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
|
|
1611
|
+
* ```
|
|
1612
|
+
*
|
|
1613
|
+
* @example Inline unnamed code block
|
|
1614
|
+
* ```ts
|
|
1615
|
+
* createSource({ nodes: [createText('const x = 1')] })
|
|
1616
|
+
* ```
|
|
1617
|
+
*/
|
|
1618
|
+
type SourceNode = BaseNode & {
|
|
1619
|
+
kind: 'Source';
|
|
1620
|
+
/**
|
|
1621
|
+
* Optional name identifying this source (used for deduplication and barrel generation).
|
|
1622
|
+
*/
|
|
1623
|
+
name?: string | null;
|
|
1624
|
+
/**
|
|
1625
|
+
* Mark this source as a type-only export.
|
|
1626
|
+
*/
|
|
1627
|
+
isTypeOnly?: boolean | null;
|
|
1628
|
+
/**
|
|
1629
|
+
* Include the `export` keyword in the generated source.
|
|
1630
|
+
*/
|
|
1631
|
+
isExportable?: boolean | null;
|
|
1632
|
+
/**
|
|
1633
|
+
* Include this source in barrel/index file generation.
|
|
1634
|
+
*/
|
|
1635
|
+
isIndexable?: boolean | null;
|
|
1636
|
+
/**
|
|
1637
|
+
* Child nodes that make up this source fragment, in DOM order.
|
|
1638
|
+
* Use a {@link TextNode} for raw string content.
|
|
1639
|
+
*/
|
|
1640
|
+
nodes?: Array<CodeNode>;
|
|
1641
|
+
};
|
|
1642
|
+
/**
|
|
1643
|
+
* Represents a fully resolved file in the AST.
|
|
1644
|
+
*
|
|
1645
|
+
* Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input
|
|
1646
|
+
* and deduplicates `imports`, `exports`, and `sources`.
|
|
1647
|
+
*
|
|
1648
|
+
* @example
|
|
1649
|
+
* ```ts
|
|
1650
|
+
* const file = createFile({
|
|
1651
|
+
* baseName: 'petStore.ts',
|
|
1652
|
+
* path: 'src/models/petStore.ts',
|
|
1653
|
+
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],
|
|
1654
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
1655
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
1656
|
+
* })
|
|
1657
|
+
* // file.id = SHA256 hash of the path
|
|
1658
|
+
* // file.name = 'petStore'
|
|
1659
|
+
* // file.extname = '.ts'
|
|
1660
|
+
* ```
|
|
1661
|
+
*/
|
|
1662
|
+
type FileNode<TMeta extends object = object> = BaseNode & {
|
|
1663
|
+
kind: 'File';
|
|
1664
|
+
/**
|
|
1665
|
+
* Unique identifier derived from a SHA256 hash of the file path. `createFile`
|
|
1666
|
+
* computes it, so callers do not need to provide it.
|
|
1667
|
+
*/
|
|
1668
|
+
id: string;
|
|
1669
|
+
/**
|
|
1670
|
+
* File name without extension, derived from `baseName`.
|
|
1671
|
+
*
|
|
1672
|
+
* @see https://nodejs.org/api/path.html#pathformatpathobject
|
|
1673
|
+
*/
|
|
1674
|
+
name: string;
|
|
1675
|
+
/**
|
|
1676
|
+
* File base name, including extension, shaped like `${name}${extname}`.
|
|
1677
|
+
*
|
|
1678
|
+
* @see https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
1679
|
+
*/
|
|
1680
|
+
baseName: `${string}.${string}`;
|
|
1681
|
+
/**
|
|
1682
|
+
* Full qualified path to the file.
|
|
1683
|
+
*/
|
|
1684
|
+
path: string;
|
|
1685
|
+
/**
|
|
1686
|
+
* File extension extracted from `baseName`.
|
|
1687
|
+
*/
|
|
1688
|
+
extname: Extname;
|
|
1689
|
+
/**
|
|
1690
|
+
* Deduplicated list of source code fragments.
|
|
1691
|
+
*/
|
|
1692
|
+
sources: Array<SourceNode>;
|
|
1693
|
+
/**
|
|
1694
|
+
* Deduplicated list of import declarations.
|
|
1695
|
+
*/
|
|
1696
|
+
imports: Array<ImportNode>;
|
|
1697
|
+
/**
|
|
1698
|
+
* Deduplicated list of export declarations.
|
|
1699
|
+
*/
|
|
1700
|
+
exports: Array<ExportNode>;
|
|
1701
|
+
/**
|
|
1702
|
+
* Optional metadata attached to this file, read by plugins during barrel generation.
|
|
1703
|
+
*/
|
|
1704
|
+
meta?: TMeta;
|
|
1705
|
+
/**
|
|
1706
|
+
* Optional banner prepended to the generated file content.
|
|
1707
|
+
* Accepts `null` so `resolver.default.banner()` results can be passed directly.
|
|
1708
|
+
*/
|
|
1709
|
+
banner?: string | null;
|
|
1710
|
+
/**
|
|
1711
|
+
* Optional footer appended to the generated file content.
|
|
1712
|
+
* Accepts `null` so `resolver.default.footer()` results can be passed directly.
|
|
1713
|
+
*/
|
|
1714
|
+
footer?: string | null;
|
|
1715
|
+
/**
|
|
1716
|
+
* Absolute on-disk path to copy into the output, through the parser's `copy` hook when it has one.
|
|
1717
|
+
*
|
|
1718
|
+
* Use to emit a real source file shipped inside a package (a template) into the generated
|
|
1719
|
+
* folder. When set, `copy` provides the file content and any `sources` nodes are ignored for
|
|
1720
|
+
* output; `sources` may still carry `name`/`isExportable`/`isIndexable` so barrel generation
|
|
1721
|
+
* treats the file the same as a rendered one.
|
|
1722
|
+
*/
|
|
1723
|
+
copy?: string | null;
|
|
1724
|
+
};
|
|
1725
|
+
/**
|
|
1726
|
+
* Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
|
|
1727
|
+
*
|
|
1728
|
+
* @example Named import
|
|
1729
|
+
* ```ts
|
|
1730
|
+
* createImport({ name: ['useState'], path: 'react' })
|
|
1731
|
+
* // import { useState } from 'react'
|
|
1732
|
+
* ```
|
|
1733
|
+
*/
|
|
1734
|
+
declare const createImport: (input: Omit<ImportNode, "kind">) => ImportNode;
|
|
1735
|
+
/**
|
|
1736
|
+
* Creates an `ExportNode` representing a language-agnostic export/public API declaration.
|
|
1737
|
+
*
|
|
1738
|
+
* @example Named export
|
|
1739
|
+
* ```ts
|
|
1740
|
+
* createExport({ name: ['Pet'], path: './Pet' })
|
|
1741
|
+
* // export { Pet } from './Pet'
|
|
1742
|
+
* ```
|
|
1743
|
+
*/
|
|
1744
|
+
declare const createExport: (input: Omit<ExportNode, "kind">) => ExportNode;
|
|
1745
|
+
/**
|
|
1746
|
+
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
1747
|
+
*
|
|
1748
|
+
* @example
|
|
1749
|
+
* ```ts
|
|
1750
|
+
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
|
|
1751
|
+
* ```
|
|
1752
|
+
*/
|
|
1753
|
+
declare const createSource: (input: Omit<SourceNode, "kind">) => SourceNode;
|
|
1754
|
+
/**
|
|
1755
|
+
* Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed
|
|
1756
|
+
* and `imports`/`exports`/`sources` are deduplicated.
|
|
1757
|
+
*/
|
|
1758
|
+
type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> & Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>;
|
|
1759
|
+
/**
|
|
1760
|
+
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
1761
|
+
*
|
|
1762
|
+
* Computes:
|
|
1763
|
+
* - `id` SHA256 hash of the file path
|
|
1764
|
+
* - `name` `baseName` without extension
|
|
1765
|
+
* - `extname` extension extracted from `baseName`
|
|
1766
|
+
*
|
|
1767
|
+
* Deduplicates:
|
|
1768
|
+
* - `sources` via `combineSources`
|
|
1769
|
+
* - `exports` via `combineExports`
|
|
1770
|
+
* - `imports` via `combineImports` (also filters unused imports)
|
|
1771
|
+
*
|
|
1772
|
+
* @throws {Error} when `baseName` has no extension.
|
|
1773
|
+
*
|
|
1774
|
+
* @example
|
|
1775
|
+
* ```ts
|
|
1776
|
+
* const file = createFile({
|
|
1777
|
+
* baseName: 'petStore.ts',
|
|
1778
|
+
* path: 'src/models/petStore.ts',
|
|
1779
|
+
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
1780
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
1781
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
1782
|
+
* })
|
|
1783
|
+
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
1784
|
+
* // file.name = 'petStore'
|
|
1785
|
+
* // file.extname = '.ts'
|
|
1786
|
+
* ```
|
|
1787
|
+
*
|
|
1788
|
+
* @example Copy a real file into the output
|
|
1789
|
+
* ```ts
|
|
1790
|
+
* const file = createFile({
|
|
1791
|
+
* baseName: 'client.ts',
|
|
1792
|
+
* path: 'src/gen/client.ts',
|
|
1793
|
+
* copy: '/abs/path/to/templates/client.ts',
|
|
1794
|
+
* })
|
|
1795
|
+
* ```
|
|
1796
|
+
*/
|
|
1797
|
+
declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
|
|
1798
|
+
//#endregion
|
|
1799
|
+
//#region src/nodes/input.d.ts
|
|
1800
|
+
/**
|
|
1801
|
+
* A server from the source document, with `{variable}` placeholders filled from their defaults.
|
|
1802
|
+
*/
|
|
1803
|
+
/**
|
|
1804
|
+
* A variable declared by a server URL template.
|
|
1805
|
+
*/
|
|
1806
|
+
type InputServerVariable = {
|
|
1807
|
+
default?: string;
|
|
1808
|
+
enum?: Array<string>;
|
|
1809
|
+
description?: string;
|
|
1810
|
+
};
|
|
1811
|
+
type InputServer = {
|
|
1812
|
+
url: string;
|
|
1813
|
+
description?: string;
|
|
1814
|
+
/**
|
|
1815
|
+
* Variables of the source URL template, copied as-is. `url` already has their defaults filled in, so
|
|
1816
|
+
* this tells a templated server apart from a literal one. Absent when the server declares none.
|
|
1817
|
+
*/
|
|
1818
|
+
variables?: Record<string, InputServerVariable>;
|
|
1819
|
+
};
|
|
1820
|
+
/**
|
|
1821
|
+
* An authentication scheme from the source document, keyed by `name`. `parameterName` is the header, query, or cookie name of an `apiKey`.
|
|
1822
|
+
*/
|
|
1823
|
+
type InputSecurityScheme = {
|
|
1824
|
+
name: string;
|
|
1825
|
+
type: string;
|
|
1826
|
+
description?: string;
|
|
1827
|
+
scheme?: string;
|
|
1828
|
+
bearerFormat?: string;
|
|
1829
|
+
in?: string;
|
|
1830
|
+
parameterName?: string;
|
|
1831
|
+
};
|
|
1832
|
+
/**
|
|
1833
|
+
* Metadata for an API document, populated by the adapter and available to every generator.
|
|
1834
|
+
*
|
|
1835
|
+
* All fields are plain JSON-serializable values, no `Set`, no `Map`, no class instances.
|
|
1836
|
+
* Computed fields (`circularNames`, `enumNames`) are pre-calculated once during the adapter
|
|
1837
|
+
* pre-scan so generators never need to iterate the full schema list themselves.
|
|
1838
|
+
*
|
|
1839
|
+
* @example
|
|
1840
|
+
* ```ts
|
|
1841
|
+
* const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://api.example.com/v2', circularNames: [], enumNames: [] }
|
|
1842
|
+
* ```
|
|
1843
|
+
*/
|
|
1844
|
+
type InputMeta = {
|
|
1845
|
+
/**
|
|
1846
|
+
* API title from `info.title` in the source document.
|
|
1847
|
+
*/
|
|
1848
|
+
title?: string;
|
|
1849
|
+
/**
|
|
1850
|
+
* API description from `info.description` in the source document.
|
|
1851
|
+
*/
|
|
1852
|
+
description?: string;
|
|
1853
|
+
/**
|
|
1854
|
+
* API version string from `info.version` in the source document.
|
|
1855
|
+
*/
|
|
1856
|
+
version?: string;
|
|
1857
|
+
/**
|
|
1858
|
+
* Resolved base URL from the first matching server entry in the source document.
|
|
1859
|
+
*/
|
|
1860
|
+
baseURL?: string | null;
|
|
1861
|
+
servers?: Array<InputServer>;
|
|
1862
|
+
securitySchemes?: Array<InputSecurityScheme>;
|
|
1863
|
+
/**
|
|
1864
|
+
* Vendor extensions (`x-*` keys) from the document root, copied as-is. Absent when the root has none.
|
|
1865
|
+
*/
|
|
1866
|
+
extensions?: Record<string, unknown>;
|
|
1867
|
+
/**
|
|
1868
|
+
* Names of schemas that participate in a circular reference chain.
|
|
1869
|
+
* Computed once during the adapter pre-scan, so a generator never has to
|
|
1870
|
+
* call `findCircularSchemas` itself.
|
|
1871
|
+
*
|
|
1872
|
+
* Convert to a `Set` once at the start of a generator, not per-schema,
|
|
1873
|
+
* so lookups stay O(1) without repeated allocations.
|
|
1874
|
+
*
|
|
1875
|
+
* @example Wrap a circular schema in z.lazy()
|
|
1876
|
+
* ```ts
|
|
1877
|
+
* const circular = new Set(meta.circularNames)
|
|
1878
|
+
* if (circular.has(schema.name)) { ... }
|
|
1879
|
+
* ```
|
|
1880
|
+
*/
|
|
1881
|
+
circularNames: ReadonlyArray<string>;
|
|
1882
|
+
/**
|
|
1883
|
+
* Names of schemas whose type is `enum`.
|
|
1884
|
+
* Computed once during the adapter pre-scan, so a generator never has to
|
|
1885
|
+
* filter the schema list itself.
|
|
1886
|
+
*
|
|
1887
|
+
* Convert to a `Set` once at the start of a generator when you need repeated
|
|
1888
|
+
* membership checks, so each check stays O(1) instead of an array scan.
|
|
1889
|
+
*
|
|
1890
|
+
* @example Check if a referenced schema is an enum
|
|
1891
|
+
* `const enums = new Set(meta.enumNames)`
|
|
1892
|
+
* `const isEnum = enums.has(schemaName)`
|
|
1893
|
+
*/
|
|
1894
|
+
enumNames: ReadonlyArray<string>;
|
|
1895
|
+
};
|
|
1896
|
+
/**
|
|
1897
|
+
* Input AST node that contains all schemas and operations for one API document.
|
|
1898
|
+
* Produced by the adapter and consumed by all Kubb plugins.
|
|
1899
|
+
*
|
|
1900
|
+
* @example
|
|
1901
|
+
* ```ts
|
|
1902
|
+
* const input: InputNode = {
|
|
1903
|
+
* kind: 'Input',
|
|
1904
|
+
* schemas: [],
|
|
1905
|
+
* operations: [],
|
|
1906
|
+
* meta: { circularNames: [], enumNames: [] },
|
|
1907
|
+
* }
|
|
1908
|
+
* ```
|
|
1909
|
+
*/
|
|
1910
|
+
type InputNode = BaseNode & {
|
|
1911
|
+
/**
|
|
1912
|
+
* Node kind.
|
|
1913
|
+
*/
|
|
1914
|
+
kind: 'Input';
|
|
1915
|
+
/**
|
|
1916
|
+
* All schema nodes in the document.
|
|
1917
|
+
*/
|
|
1918
|
+
schemas: Array<SchemaNode>;
|
|
1919
|
+
/**
|
|
1920
|
+
* All operation nodes in the document.
|
|
1921
|
+
*/
|
|
1922
|
+
operations: Array<OperationNode>;
|
|
1923
|
+
/**
|
|
1924
|
+
* Document metadata populated by the adapter.
|
|
1925
|
+
*/
|
|
1926
|
+
meta: InputMeta;
|
|
1927
|
+
};
|
|
1928
|
+
/**
|
|
1929
|
+
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to empty
|
|
1930
|
+
* name lists. Every call allocates fresh defaults so no two inputs share them.
|
|
1931
|
+
*
|
|
1932
|
+
* @example
|
|
1933
|
+
* ```ts
|
|
1934
|
+
* const input = createInput()
|
|
1935
|
+
* // { kind: 'Input', schemas: [], operations: [] }
|
|
1936
|
+
* ```
|
|
1937
|
+
*/
|
|
1938
|
+
declare function createInput(overrides?: Partial<Omit<InputNode, 'kind'>>): InputNode;
|
|
1939
|
+
declare namespace index_d_exports$1 {
|
|
1940
|
+
export { Node, UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Union of all AST node types.
|
|
1944
|
+
*
|
|
1945
|
+
* This lets TypeScript narrow types in `switch (node.kind)` blocks.
|
|
1946
|
+
*
|
|
1947
|
+
* @example
|
|
1948
|
+
* ```ts
|
|
1949
|
+
* function getKind(node: Node): string {
|
|
1950
|
+
* switch (node.kind) {
|
|
1951
|
+
* case 'Input':
|
|
1952
|
+
* return 'input'
|
|
1953
|
+
* default:
|
|
1954
|
+
* return 'other'
|
|
1955
|
+
* }
|
|
1956
|
+
* }
|
|
1957
|
+
* ```
|
|
1958
|
+
*/
|
|
1959
|
+
type Node = InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | RequestBodyNode | ContentNode | FileNode | ImportNode | ExportNode | SourceNode | ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
|
|
1960
|
+
//#endregion
|
|
1961
|
+
//#region src/visitor.d.ts
|
|
1962
|
+
/**
|
|
1963
|
+
* Ordered mapping of `[NodeType, ParentType]` pairs.
|
|
1964
|
+
*
|
|
1965
|
+
* `ParentOf` uses this map to find parent types.
|
|
1966
|
+
*/
|
|
1967
|
+
type ParentNodeMap = [[InputNode, undefined], [OperationNode, InputNode], [RequestBodyNode, OperationNode], [ContentNode, RequestBodyNode | ResponseNode], [SchemaNode, InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode], [PropertyNode, SchemaNode], [ParameterNode, OperationNode], [ResponseNode, OperationNode]];
|
|
1968
|
+
/**
|
|
1969
|
+
* Resolves the parent node type for a given AST node type.
|
|
1970
|
+
*
|
|
1971
|
+
* Visitor context relies on this so `ctx.parent` is typed for each callback.
|
|
1972
|
+
*
|
|
1973
|
+
* @example
|
|
1974
|
+
* ```ts
|
|
1975
|
+
* type InputParent = ParentOf<InputNode>
|
|
1976
|
+
* // undefined
|
|
1977
|
+
* ```
|
|
1978
|
+
*
|
|
1979
|
+
* @example
|
|
1980
|
+
* ```ts
|
|
1981
|
+
* type PropertyParent = ParentOf<PropertyNode>
|
|
1982
|
+
* // SchemaNode
|
|
1983
|
+
* ```
|
|
1984
|
+
*
|
|
1985
|
+
* @example
|
|
1986
|
+
* ```ts
|
|
1987
|
+
* type SchemaParent = ParentOf<SchemaNode>
|
|
1988
|
+
* // InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode
|
|
1989
|
+
* ```
|
|
1990
|
+
*/
|
|
1991
|
+
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;
|
|
1992
|
+
/**
|
|
1993
|
+
* Traversal context passed as the second argument to every visitor callback.
|
|
1994
|
+
* `parent` is typed from the current node type.
|
|
1995
|
+
*
|
|
1996
|
+
* @example
|
|
1997
|
+
* ```ts
|
|
1998
|
+
* const visitor: Visitor = {
|
|
1999
|
+
* schema(node, { parent }) {
|
|
2000
|
+
* // parent type is narrowed by node kind
|
|
2001
|
+
* },
|
|
2002
|
+
* }
|
|
2003
|
+
* ```
|
|
2004
|
+
*/
|
|
2005
|
+
type VisitorContext<T extends Node = Node> = {
|
|
2006
|
+
/**
|
|
2007
|
+
* Parent node of the currently visited node.
|
|
2008
|
+
* For `InputNode`, this is `undefined`.
|
|
2009
|
+
*/
|
|
2010
|
+
parent?: ParentOf<T>;
|
|
2011
|
+
};
|
|
2012
|
+
/**
|
|
2013
|
+
* Synchronous visitor consumed by `transform`. Each optional callback runs
|
|
2014
|
+
* for the matching node type. Return a new node to replace it, or `undefined`
|
|
2015
|
+
* to leave it untouched.
|
|
2016
|
+
*
|
|
2017
|
+
* Plugins typically expose `transformer` so users can supply a `Visitor` that
|
|
2018
|
+
* rewrites the AST before printing.
|
|
2019
|
+
*
|
|
2020
|
+
* @example Prefix every operationId
|
|
2021
|
+
* ```ts
|
|
2022
|
+
* const visitor: Visitor = {
|
|
2023
|
+
* operation(node) {
|
|
2024
|
+
* return { ...node, operationId: `api_${node.operationId}` }
|
|
2025
|
+
* },
|
|
2026
|
+
* }
|
|
2027
|
+
* ```
|
|
2028
|
+
*
|
|
2029
|
+
* @example Strip schema descriptions
|
|
2030
|
+
* ```ts
|
|
2031
|
+
* const visitor: Visitor = {
|
|
2032
|
+
* schema(node) {
|
|
2033
|
+
* return { ...node, description: undefined }
|
|
2034
|
+
* },
|
|
2035
|
+
* }
|
|
2036
|
+
* ```
|
|
2037
|
+
*/
|
|
2038
|
+
type Visitor = {
|
|
2039
|
+
input?(node: InputNode, context: VisitorContext<InputNode>): undefined | null | InputNode;
|
|
2040
|
+
operation?(node: OperationNode, context: VisitorContext<OperationNode>): undefined | null | OperationNode;
|
|
2041
|
+
schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): undefined | null | SchemaNode;
|
|
2042
|
+
property?(node: PropertyNode, context: VisitorContext<PropertyNode>): undefined | null | PropertyNode;
|
|
2043
|
+
parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): undefined | null | ParameterNode;
|
|
2044
|
+
response?(node: ResponseNode, context: VisitorContext<ResponseNode>): undefined | null | ResponseNode;
|
|
2045
|
+
};
|
|
2046
|
+
/**
|
|
2047
|
+
* The callbacks of {@link Visitor} with every return type replaced by `TResult`. `collect` uses it
|
|
2048
|
+
* so a visitor can yield values instead of replacement nodes.
|
|
2049
|
+
*
|
|
2050
|
+
* @example
|
|
2051
|
+
* ```ts
|
|
2052
|
+
* const visitor: VisitorOf<string> = {
|
|
2053
|
+
* operation(node) {
|
|
2054
|
+
* return node.operationId
|
|
2055
|
+
* },
|
|
2056
|
+
* }
|
|
2057
|
+
* ```
|
|
2058
|
+
*/
|
|
2059
|
+
type VisitorOf<TResult> = { [K in keyof Visitor]?: (node: Parameters<NonNullable<Visitor[K]>>[0], context: Parameters<NonNullable<Visitor[K]>>[1]) => TResult | null | undefined; };
|
|
2060
|
+
type TraversalOptions = {
|
|
2061
|
+
/**
|
|
2062
|
+
* Traversal depth.
|
|
2063
|
+
* @default 'deep'
|
|
2064
|
+
*/
|
|
2065
|
+
depth?: VisitorDepth;
|
|
2066
|
+
/**
|
|
2067
|
+
* Internal parent override used during recursion.
|
|
2068
|
+
*/
|
|
2069
|
+
parent?: Node;
|
|
2070
|
+
};
|
|
2071
|
+
/**
|
|
2072
|
+
* Options for `transform`.
|
|
2073
|
+
*
|
|
2074
|
+
* @example
|
|
2075
|
+
* ```ts
|
|
2076
|
+
* const options: TransformOptions = { depth: 'deep', schema: (node) => node }
|
|
2077
|
+
* ```
|
|
2078
|
+
*
|
|
2079
|
+
* @example
|
|
2080
|
+
* ```ts
|
|
2081
|
+
* // Only transform the current node, not nested children
|
|
2082
|
+
* const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
|
|
2083
|
+
* ```
|
|
2084
|
+
*/
|
|
2085
|
+
type TransformOptions = Visitor & TraversalOptions;
|
|
2086
|
+
/**
|
|
2087
|
+
* Options for `collect`.
|
|
2088
|
+
*
|
|
2089
|
+
* @example
|
|
2090
|
+
* ```ts
|
|
2091
|
+
* const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
|
|
2092
|
+
* ```
|
|
2093
|
+
*/
|
|
2094
|
+
type CollectOptions<T> = VisitorOf<T> & TraversalOptions;
|
|
2095
|
+
/**
|
|
2096
|
+
* Synchronous depth-first transform. Each visitor callback can return a
|
|
2097
|
+
* replacement node. Returning `undefined` keeps the original.
|
|
2098
|
+
*
|
|
2099
|
+
* The original tree is never mutated, a new tree is returned. Pass
|
|
2100
|
+
* `depth: 'shallow'` to skip recursion into children.
|
|
2101
|
+
*
|
|
2102
|
+
* @example Prefix every operationId
|
|
2103
|
+
* ```ts
|
|
2104
|
+
* const next = transform(root, {
|
|
2105
|
+
* operation(node) {
|
|
2106
|
+
* return { ...node, operationId: `prefixed_${node.operationId}` }
|
|
2107
|
+
* },
|
|
2108
|
+
* })
|
|
2109
|
+
* ```
|
|
2110
|
+
*
|
|
2111
|
+
* @example Replace only the root node
|
|
2112
|
+
* ```ts
|
|
2113
|
+
* const next = transform(root, {
|
|
2114
|
+
* depth: 'shallow',
|
|
2115
|
+
* input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),
|
|
2116
|
+
* })
|
|
2117
|
+
* ```
|
|
2118
|
+
*/
|
|
2119
|
+
export declare function transform<T extends Node>(node: T, options: TransformOptions): T;
|
|
2120
|
+
/**
|
|
2121
|
+
* Lazy depth-first collection pass. Yields every non-null value returned by
|
|
2122
|
+
* the visitor callbacks. Use `collectSync` for the eager array form.
|
|
2123
|
+
*
|
|
2124
|
+
* @example Collect every operationId
|
|
2125
|
+
* ```ts
|
|
2126
|
+
* const ids: string[] = []
|
|
2127
|
+
* for (const id of collect<string>(root, {
|
|
2128
|
+
* operation(node) {
|
|
2129
|
+
* return node.operationId
|
|
2130
|
+
* },
|
|
2131
|
+
* })) {
|
|
2132
|
+
* ids.push(id)
|
|
2133
|
+
* }
|
|
2134
|
+
* ```
|
|
2135
|
+
*/
|
|
2136
|
+
export declare function collect<T>(node: Node, options: CollectOptions<T>): Generator<T, void, undefined>;
|
|
2137
|
+
/**
|
|
2138
|
+
* Eager depth-first collection pass. Gathers every non-null value the visitor
|
|
2139
|
+
* callbacks return into an array.
|
|
2140
|
+
*
|
|
2141
|
+
* @example Collect every operationId
|
|
2142
|
+
* ```ts
|
|
2143
|
+
* const ids = collectSync<string>(root, {
|
|
2144
|
+
* operation(node) {
|
|
2145
|
+
* return node.operationId
|
|
2146
|
+
* },
|
|
2147
|
+
* })
|
|
2148
|
+
* ```
|
|
2149
|
+
*/
|
|
2150
|
+
export declare function collectSync<T>(node: Node, options: CollectOptions<T>): Array<T>;
|
|
2151
|
+
//#endregion
|
|
2152
|
+
//#region src/defineMacro.d.ts
|
|
2153
|
+
/**
|
|
2154
|
+
* Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,
|
|
2155
|
+
* and `undefined` keeps declaration order.
|
|
2156
|
+
*/
|
|
2157
|
+
type Enforce = 'pre' | 'post';
|
|
2158
|
+
/**
|
|
2159
|
+
* A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a
|
|
2160
|
+
* {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an
|
|
2161
|
+
* optional `match` predicate. Macros run on the shared AST, so the same macro works across every
|
|
2162
|
+
* adapter and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).
|
|
2163
|
+
*/
|
|
2164
|
+
type Macro = Visitor & {
|
|
2165
|
+
/**
|
|
2166
|
+
* Macro identifier used to tell macros apart, for example `'simplify-union'`.
|
|
2167
|
+
*/
|
|
2168
|
+
name: string;
|
|
2169
|
+
/**
|
|
2170
|
+
* Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.
|
|
2171
|
+
* Ordering within a bucket follows list order.
|
|
2172
|
+
*/
|
|
2173
|
+
enforce?: Enforce;
|
|
2174
|
+
/**
|
|
2175
|
+
* Predicate checked against the current node before any callback runs. Returning `false`
|
|
2176
|
+
* skips the macro for that node.
|
|
2177
|
+
*/
|
|
2178
|
+
match?: (node: Node) => boolean;
|
|
2179
|
+
};
|
|
2180
|
+
/**
|
|
2181
|
+
* Types a macro for inference and a single construction site, mirroring `defineExtension`.
|
|
2182
|
+
* Adds no runtime behavior.
|
|
2183
|
+
*
|
|
2184
|
+
* @example
|
|
2185
|
+
* ```ts
|
|
2186
|
+
* const macroUntagged = defineMacro({
|
|
2187
|
+
* name: 'untagged',
|
|
2188
|
+
* operation(node) {
|
|
2189
|
+
* return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }
|
|
2190
|
+
* },
|
|
2191
|
+
* })
|
|
2192
|
+
* ```
|
|
2193
|
+
*/
|
|
2194
|
+
export declare function defineMacro(macro: Macro): Macro;
|
|
2195
|
+
/**
|
|
2196
|
+
* Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin
|
|
2197
|
+
* transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied
|
|
2198
|
+
* sequentially per node so later macros see earlier output. This differs from a plain visitor, which
|
|
2199
|
+
* has no names, ordering, or composition.
|
|
2200
|
+
*
|
|
2201
|
+
* @example
|
|
2202
|
+
* ```ts
|
|
2203
|
+
* const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])
|
|
2204
|
+
* const next = transform(root, visitor)
|
|
2205
|
+
* ```
|
|
2206
|
+
*/
|
|
2207
|
+
export declare function composeMacros(macros: ReadonlyArray<Macro>): Visitor;
|
|
2208
|
+
/**
|
|
2209
|
+
* Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s
|
|
2210
|
+
* structural sharing, so an empty or no-op macro list returns the same reference. Pass
|
|
2211
|
+
* `depth: 'shallow'` to rewrite the root node only.
|
|
2212
|
+
*
|
|
2213
|
+
* @example
|
|
2214
|
+
* ```ts
|
|
2215
|
+
* const next = applyMacros(root, [macroIntegerToString])
|
|
2216
|
+
* ```
|
|
2217
|
+
*
|
|
2218
|
+
* @example Apply to the root node only
|
|
2219
|
+
* ```ts
|
|
2220
|
+
* const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })
|
|
2221
|
+
* ```
|
|
2222
|
+
*/
|
|
2223
|
+
export declare function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: {
|
|
2224
|
+
depth?: VisitorDepth;
|
|
2225
|
+
}): TNode;
|
|
2226
|
+
//#endregion
|
|
2227
|
+
//#region src/optionality.d.ts
|
|
2228
|
+
/**
|
|
2229
|
+
* Generic JSON Schema optionality: a non-required field is optional, and a
|
|
2230
|
+
* non-required nullable field is nullish.
|
|
2231
|
+
*/
|
|
2232
|
+
export declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
|
|
2233
|
+
//#endregion
|
|
2234
|
+
//#region src/createPrinter.d.ts
|
|
2235
|
+
/**
|
|
2236
|
+
* Runtime context passed as `this` to printer handlers.
|
|
2237
|
+
*
|
|
2238
|
+
* `this.transform` dispatches to node-level handlers from `nodes`.
|
|
2239
|
+
*
|
|
2240
|
+
* @example
|
|
2241
|
+
* ```ts
|
|
2242
|
+
* const context: PrinterHandlerContext<string, {}> = {
|
|
2243
|
+
* options: {},
|
|
2244
|
+
* transform: () => 'value',
|
|
2245
|
+
* base: () => 'value',
|
|
2246
|
+
* }
|
|
2247
|
+
* ```
|
|
2248
|
+
*/
|
|
2249
|
+
type PrinterHandlerContext<TOutput, TOptions extends object> = {
|
|
2250
|
+
/**
|
|
2251
|
+
* Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
|
|
2252
|
+
* Use `this.transform` inside `nodes` handlers and inside the `print` override.
|
|
2253
|
+
*/
|
|
2254
|
+
transform: (node: SchemaNode) => TOutput | null;
|
|
2255
|
+
/**
|
|
2256
|
+
* Run the printer's built-in handler for the node, ignoring any override for its type.
|
|
2257
|
+
* Inside an override, `this.base(node)` returns what the printer would have emitted,
|
|
2258
|
+
* so the override can wrap it instead of re-implementing the handler. Nested nodes
|
|
2259
|
+
* still dispatch through the overrides.
|
|
2260
|
+
*/
|
|
2261
|
+
base: (node: SchemaNode) => TOutput | null;
|
|
2262
|
+
/** Declares an import the printed code needs. The generator reads it back with `printer.drainImports()`. */
|
|
2263
|
+
import: (node: ImportNode) => void;
|
|
2264
|
+
/**
|
|
2265
|
+
* Options for this printer instance.
|
|
2266
|
+
*/
|
|
2267
|
+
options: TOptions;
|
|
2268
|
+
};
|
|
2269
|
+
/**
|
|
2270
|
+
* Handler for one schema node type.
|
|
2271
|
+
*
|
|
2272
|
+
* Use a regular function (not an arrow function) if you need `this`.
|
|
2273
|
+
*
|
|
2274
|
+
* @example
|
|
2275
|
+
* ```ts
|
|
2276
|
+
* const handler: PrinterHandler<string, {}, 'string'> = function () {
|
|
2277
|
+
* return 'string'
|
|
2278
|
+
* }
|
|
2279
|
+
* ```
|
|
2280
|
+
*/
|
|
2281
|
+
type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null;
|
|
2282
|
+
/**
|
|
2283
|
+
* Partial map of per-node-type handler overrides for a printer.
|
|
2284
|
+
*
|
|
2285
|
+
* Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
|
|
2286
|
+
* Supply only the handlers you want to replace. The printer's built-in
|
|
2287
|
+
* defaults fill in the rest.
|
|
2288
|
+
*
|
|
2289
|
+
* @example
|
|
2290
|
+
* ```ts
|
|
2291
|
+
* pluginZod({
|
|
2292
|
+
* printer: {
|
|
2293
|
+
* nodes: {
|
|
2294
|
+
* date(): string {
|
|
2295
|
+
* return 'z.string().date()'
|
|
2296
|
+
* },
|
|
2297
|
+
* } satisfies PrinterPartial<string, PrinterZodOptions>,
|
|
2298
|
+
* },
|
|
2299
|
+
* })
|
|
2300
|
+
* ```
|
|
2301
|
+
*/
|
|
2302
|
+
type PrinterPartial<TOutput, TOptions extends object> = Partial<{ [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>; }>;
|
|
2303
|
+
/**
|
|
2304
|
+
* Generic shape used by `definePrinter`.
|
|
2305
|
+
*
|
|
2306
|
+
* - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)
|
|
2307
|
+
* - `TOptions` options passed to and stored on the printer instance
|
|
2308
|
+
* - `TOutput` the type emitted by node handlers
|
|
2309
|
+
* - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)
|
|
2310
|
+
*
|
|
2311
|
+
* @example
|
|
2312
|
+
* ```ts
|
|
2313
|
+
* type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>
|
|
2314
|
+
* ```
|
|
2315
|
+
*/
|
|
2316
|
+
type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
|
|
2317
|
+
name: TName;
|
|
2318
|
+
options: TOptions;
|
|
2319
|
+
output: TOutput;
|
|
2320
|
+
printOutput: TPrintOutput;
|
|
2321
|
+
};
|
|
2322
|
+
/**
|
|
2323
|
+
* Printer instance returned by a printer factory.
|
|
2324
|
+
*
|
|
2325
|
+
* @example
|
|
2326
|
+
* ```ts
|
|
2327
|
+
* const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})
|
|
2328
|
+
* ```
|
|
2329
|
+
*/
|
|
2330
|
+
type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
|
|
2331
|
+
/**
|
|
2332
|
+
* Unique identifier supplied at creation time.
|
|
2333
|
+
*/
|
|
2334
|
+
name: T['name'];
|
|
2335
|
+
/**
|
|
2336
|
+
* Options for this printer instance.
|
|
2337
|
+
*/
|
|
2338
|
+
options: T['options'];
|
|
2339
|
+
/**
|
|
2340
|
+
* Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
|
|
2341
|
+
* Always dispatches through the `nodes` map. Never calls the `print` override.
|
|
2342
|
+
* Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
|
|
2343
|
+
*/
|
|
2344
|
+
transform: (node: SchemaNode) => T['output'] | null;
|
|
2345
|
+
/**
|
|
2346
|
+
* Public printer. If the builder provides a root-level `print`, this calls that
|
|
2347
|
+
* higher-level function (which may produce full declarations).
|
|
2348
|
+
* Otherwise, falls back to the node-level dispatcher.
|
|
2349
|
+
*/
|
|
2350
|
+
print: (node: SchemaNode) => T['printOutput'] | null;
|
|
2351
|
+
/** Returns the imports declared with `this.import(...)` since the last call, then clears them. */
|
|
2352
|
+
drainImports: () => Array<ImportNode>;
|
|
2353
|
+
};
|
|
2354
|
+
/**
|
|
2355
|
+
* Builder function passed to `definePrinter`.
|
|
2356
|
+
*
|
|
2357
|
+
* It receives resolved options and returns:
|
|
2358
|
+
* - `name`
|
|
2359
|
+
* - `options`
|
|
2360
|
+
* - `nodes` handlers
|
|
2361
|
+
* - optional top-level `print` override
|
|
2362
|
+
*
|
|
2363
|
+
* @example
|
|
2364
|
+
* ```ts
|
|
2365
|
+
* const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })
|
|
2366
|
+
* ```
|
|
2367
|
+
*/
|
|
2368
|
+
type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
|
|
2369
|
+
name: T['name'];
|
|
2370
|
+
/**
|
|
2371
|
+
* Options to store on the printer.
|
|
2372
|
+
*/
|
|
2373
|
+
options: T['options'];
|
|
2374
|
+
nodes: PrinterPartial<T['output'], T['options']>;
|
|
2375
|
+
/**
|
|
2376
|
+
* User-supplied handler overrides. An override wins over the matching `nodes` handler,
|
|
2377
|
+
* and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here
|
|
2378
|
+
* instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.
|
|
2379
|
+
*/
|
|
2380
|
+
overrides?: PrinterPartial<T['output'], T['options']>;
|
|
2381
|
+
/**
|
|
2382
|
+
* Optional root-level print override. When provided, becomes the public `printer.print`.
|
|
2383
|
+
* Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
|
|
2384
|
+
* not the override itself, so recursion is safe.
|
|
2385
|
+
*/
|
|
2386
|
+
print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null;
|
|
2387
|
+
};
|
|
2388
|
+
/**
|
|
2389
|
+
* Creates a schema printer: a function that takes a `SchemaNode` and emits
|
|
2390
|
+
* code in your target language. Each plugin that produces code from schemas
|
|
2391
|
+
* (TypeScript types, Zod schemas, Faker factories) ships a printer built
|
|
2392
|
+
* with this helper.
|
|
2393
|
+
*
|
|
2394
|
+
* The builder receives resolved options and returns:
|
|
2395
|
+
*
|
|
2396
|
+
* - `name` unique identifier for the printer.
|
|
2397
|
+
* - `options` stored on the returned printer instance.
|
|
2398
|
+
* - `nodes` map of `SchemaType` → handler. Handlers return the rendered
|
|
2399
|
+
* output (a string, a TypeScript AST node, ...) for that schema type.
|
|
2400
|
+
* - `overrides` (optional), user-supplied handlers that win over `nodes`.
|
|
2401
|
+
* An override can call `this.base(node)` to reuse the handler it replaced.
|
|
2402
|
+
* - `print` (optional), top-level override exposed as `printer.print`.
|
|
2403
|
+
* Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
|
|
2404
|
+
*
|
|
2405
|
+
* Without a `print` override, `printer.print` falls back to `printer.transform`
|
|
2406
|
+
* (the node-level dispatcher).
|
|
2407
|
+
*
|
|
2408
|
+
* @example Tiny Zod printer
|
|
2409
|
+
* ```ts
|
|
2410
|
+
* import { createPrinter, type PrinterFactoryOptions } from '@kubb/ast'
|
|
2411
|
+
*
|
|
2412
|
+
* type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
|
|
2413
|
+
*
|
|
2414
|
+
* export const zodPrinter = createPrinter<PrinterZod>((options) => ({
|
|
2415
|
+
* name: 'zod',
|
|
2416
|
+
* options: { strict: options.strict ?? true },
|
|
2417
|
+
* nodes: {
|
|
2418
|
+
* string: () => 'z.string()',
|
|
2419
|
+
* object(node) {
|
|
2420
|
+
* const props = node.properties
|
|
2421
|
+
* .map((p) => `${p.name}: ${this.transform(p.schema)}`)
|
|
2422
|
+
* .join(', ')
|
|
2423
|
+
* return `z.object({ ${props} })`
|
|
2424
|
+
* },
|
|
2425
|
+
* },
|
|
2426
|
+
* }))
|
|
2427
|
+
* ```
|
|
2428
|
+
*/
|
|
2429
|
+
export declare function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
|
|
2430
|
+
//#endregion
|
|
2431
|
+
//#region src/utils/extractStringsFromNodes.d.ts
|
|
2432
|
+
/**
|
|
2433
|
+
* Extracts all string content from a `CodeNode` tree recursively.
|
|
2434
|
+
*
|
|
2435
|
+
* Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
|
|
2436
|
+
* and nested node content. Used to build the full source string for import filtering.
|
|
2437
|
+
*/
|
|
2438
|
+
export declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
|
|
2439
|
+
//#endregion
|
|
2440
|
+
//#region src/utils/refs.d.ts
|
|
2441
|
+
/** Returns the last segment of a `$ref` pointer, for example `'Pet'` for `#/components/schemas/Pet`. */
|
|
2442
|
+
export declare function refName(ref: string): string;
|
|
2443
|
+
/**
|
|
2444
|
+
* Resolves the emitted name of the schema a ref node points at. Prefers `targetName` (set when
|
|
2445
|
+
* the referenced schema was renamed, e.g. to break a collision), then the last segment of `ref`,
|
|
2446
|
+
* then `name`, then the nested `schema.name`.
|
|
2447
|
+
*
|
|
2448
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
2449
|
+
*
|
|
2450
|
+
* @example
|
|
2451
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
2452
|
+
*
|
|
2453
|
+
* @example Collision-renamed target
|
|
2454
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Order', targetName: 'OrderSchema' }) // 'OrderSchema'`
|
|
2455
|
+
*/
|
|
2456
|
+
export declare function resolveRefName(node: SchemaNode | null | undefined): string | null;
|
|
2457
|
+
/**
|
|
2458
|
+
* Merges a ref node with its resolved schema, giving the fields set at the usage site precedence.
|
|
2459
|
+
*
|
|
2460
|
+
* Every field on the ref except `kind`, `type`, `name`, `ref`, and `schema` overrides the same field
|
|
2461
|
+
* of the resolved `schema` (for example `description`, `nullable`, `readOnly`, `deprecated`). Fields
|
|
2462
|
+
* left `undefined` on the ref do not shadow the resolved schema. A ref without a resolved `schema`
|
|
2463
|
+
* is returned as is.
|
|
2464
|
+
*
|
|
2465
|
+
* @example
|
|
2466
|
+
* ```ts
|
|
2467
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A pet', schema: petSchema })
|
|
2468
|
+
* mergeRefWithSchema(ref) // petSchema's fields with description 'A pet'
|
|
2469
|
+
* ```
|
|
2470
|
+
*/
|
|
2471
|
+
export declare function mergeRefWithSchema(node: RefSchemaNode): SchemaNode;
|
|
2472
|
+
/**
|
|
2473
|
+
* Returns `true` when a schema is a bare ref without modifiers, metadata, or omit keys.
|
|
2474
|
+
*
|
|
2475
|
+
* Modifiers inherited from the resolved schema are included in the check because a ref emits the
|
|
2476
|
+
* referenced schema variable with those modifiers already applied.
|
|
2477
|
+
*/
|
|
2478
|
+
export declare function isBareRef(node: SchemaNode | null | undefined, keysToOmit?: Array<string> | null): boolean;
|
|
2479
|
+
//#endregion
|
|
2480
|
+
//#region src/utils/schemaGraph.d.ts
|
|
2481
|
+
/**
|
|
2482
|
+
* Collects the names of every schema a node's subtree references, resolved with `resolveRefName`.
|
|
2483
|
+
* Each ref contributes its name only, so the schema it points to is never traversed. The walk is
|
|
2484
|
+
* memoized by node identity, which lets `findCircularSchemas` and `containsCircularRef` share one
|
|
2485
|
+
* scan per schema.
|
|
2486
|
+
*
|
|
2487
|
+
* @example
|
|
2488
|
+
* ```ts
|
|
2489
|
+
* collectSchemaRefs(petSchema)
|
|
2490
|
+
* // Set { 'Category', 'Tag' }
|
|
2491
|
+
* ```
|
|
2492
|
+
*/
|
|
2493
|
+
export declare const collectSchemaRefs: (key: SchemaNode) => ReadonlySet<string>;
|
|
2494
|
+
/**
|
|
2495
|
+
* Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
|
|
2496
|
+
* first-occurrence order. The walk is memoized by node identity, so the subtree is scanned once and
|
|
2497
|
+
* `resolver.imports` reads the same result across the ts, zod, and faker plugins instead of
|
|
2498
|
+
* re-scanning the same schema per plugin.
|
|
2499
|
+
*
|
|
2500
|
+
* Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
|
|
2501
|
+
* same file (a union member created by name) is left out. That leaves exactly the set
|
|
2502
|
+
* `resolver.imports` emits.
|
|
2503
|
+
*
|
|
2504
|
+
* @example
|
|
2505
|
+
* ```ts
|
|
2506
|
+
* collectImportedRefNames(petSchema)
|
|
2507
|
+
* // ['Category', 'Tag']
|
|
2508
|
+
* ```
|
|
2509
|
+
*/
|
|
2510
|
+
export declare const collectImportedRefNames: (key: SchemaNode) => readonly string[];
|
|
2511
|
+
/**
|
|
2512
|
+
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
2513
|
+
*
|
|
2514
|
+
* An operation uses a schema when its parameters, request body, or responses reference it, directly
|
|
2515
|
+
* or through other named schemas. Once a name is added to the result it is not revisited, so
|
|
2516
|
+
* reference cycles terminate.
|
|
2517
|
+
*
|
|
2518
|
+
* Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
|
|
2519
|
+
*
|
|
2520
|
+
* @example Only generate schemas referenced by included operations
|
|
2521
|
+
* ```ts
|
|
2522
|
+
* const includedOps = operations.filter((op) => resolver.default.options(op, { options, include }) !== null)
|
|
2523
|
+
* const allowed = collectUsedSchemaNames(includedOps, schemas)
|
|
2524
|
+
*
|
|
2525
|
+
* for (const schema of schemas) {
|
|
2526
|
+
* if (schema.name && !allowed.has(schema.name)) continue
|
|
2527
|
+
* // generate schema
|
|
2528
|
+
* }
|
|
2529
|
+
* ```
|
|
2530
|
+
*/
|
|
2531
|
+
export declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
2532
|
+
/**
|
|
2533
|
+
* Finds every schema that takes part in a circular dependency chain in a schema dependency graph
|
|
2534
|
+
* that maps each schema name to the names it references directly.
|
|
2535
|
+
*
|
|
2536
|
+
* Use this when the graph was already collected during another pass (e.g. the adapter's convert
|
|
2537
|
+
* walk), so the schema nodes are not swept a second time. `findCircularSchemas` builds the graph
|
|
2538
|
+
* from schema nodes and delegates here.
|
|
2539
|
+
*
|
|
2540
|
+
* @example
|
|
2541
|
+
* ```ts
|
|
2542
|
+
* const graph = new Map([
|
|
2543
|
+
* ['Pet', new Set(['Category'])],
|
|
2544
|
+
* ['Category', new Set(['Pet'])],
|
|
2545
|
+
* ])
|
|
2546
|
+
* findCircularSchemasFromGraph(graph) // Set { 'Pet', 'Category' }
|
|
2547
|
+
* ```
|
|
2548
|
+
*/
|
|
2549
|
+
export declare function findCircularSchemasFromGraph(graph: ReadonlyMap<string, ReadonlySet<string>>): Set<string>;
|
|
2550
|
+
/**
|
|
2551
|
+
* Finds every schema that takes part in a circular dependency chain, including direct self-loops.
|
|
2552
|
+
*
|
|
2553
|
+
* Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so
|
|
2554
|
+
* the generated code does not recurse forever. Refs are followed by name only, so the walk stays
|
|
2555
|
+
* linear in the size of the schema graph.
|
|
2556
|
+
*
|
|
2557
|
+
* @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.
|
|
2558
|
+
*/
|
|
2559
|
+
export declare function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
2560
|
+
//#endregion
|
|
2561
|
+
//#region src/utils/schemaProperties.d.ts
|
|
2562
|
+
/**
|
|
2563
|
+
* Finds every matching property exposed by an object, resolved reference, or intersection.
|
|
2564
|
+
*
|
|
2565
|
+
* References are followed through their parsed `schema`. Circular references terminate without
|
|
2566
|
+
* revisiting a node. Unions are not traversed because a property on one branch does not describe
|
|
2567
|
+
* every branch.
|
|
2568
|
+
*
|
|
2569
|
+
* @example Faker discriminator narrowing
|
|
2570
|
+
* ```ts
|
|
2571
|
+
* const values = resolveSchemaProperties({ node: member, propertyName: union.discriminatorPropertyName }).flatMap(({ schema }) =>
|
|
2572
|
+
* getSchemaLiteralValues(schema),
|
|
2573
|
+
* )
|
|
2574
|
+
* const typeName = `Extract<Pet, { type: ${values.map(JSON.stringify).join(' | ')} }>`
|
|
2575
|
+
* ```
|
|
2576
|
+
*
|
|
2577
|
+
* @example Zod discriminated unions
|
|
2578
|
+
* ```ts
|
|
2579
|
+
* const canDiscriminate = union.members?.every(
|
|
2580
|
+
* (member) => resolveSchemaProperties({ node: member, propertyName: 'type' }).length > 0,
|
|
2581
|
+
* )
|
|
2582
|
+
* const expression = canDiscriminate ? `z.discriminatedUnion('type', members)` : `z.union(members)`
|
|
2583
|
+
* ```
|
|
2584
|
+
*
|
|
2585
|
+
* @example TypeScript property lookup
|
|
2586
|
+
* ```ts
|
|
2587
|
+
* const properties = resolveSchemaProperties({ node: schema, propertyName: 'status' })
|
|
2588
|
+
* const statusSchemas = properties.map((property) => print(property.schema))
|
|
2589
|
+
* ```
|
|
2590
|
+
*/
|
|
2591
|
+
export declare function resolveSchemaProperties({ node, propertyName }: {
|
|
2592
|
+
node: SchemaNode;
|
|
2593
|
+
propertyName: string;
|
|
2594
|
+
}): ReadonlyArray<PropertyNode>;
|
|
2595
|
+
/**
|
|
2596
|
+
* Reads the unique literal values represented by an enum, resolved reference, or union.
|
|
2597
|
+
*
|
|
2598
|
+
* Named enum values take precedence over simple enum values, matching how renderers consume
|
|
2599
|
+
* `EnumSchemaNode`.
|
|
2600
|
+
*
|
|
2601
|
+
* @example
|
|
2602
|
+
* ```ts
|
|
2603
|
+
* const values = getSchemaLiteralValues(enumNode)
|
|
2604
|
+
* // ['cat', 'dog']
|
|
2605
|
+
* ```
|
|
2606
|
+
*/
|
|
2607
|
+
export declare function getSchemaLiteralValues(node: SchemaNode): ReadonlyArray<string | number | boolean | null>;
|
|
2608
|
+
/**
|
|
2609
|
+
* Infers an implicit discriminator: a property every member exposes with a distinct single
|
|
2610
|
+
* literal value, the same shape a declared OpenAPI `discriminator` already narrows on.
|
|
2611
|
+
*/
|
|
2612
|
+
export declare function inferDiscriminatorPropertyName(members: ReadonlyArray<SchemaNode>): string | undefined;
|
|
2613
|
+
//#endregion
|
|
2614
|
+
//#region src/infer.d.ts
|
|
2615
|
+
/**
|
|
2616
|
+
* How `format: 'date-time'` schemas are represented downstream.
|
|
2617
|
+
* - `false` falls through to a plain `string` (no validation).
|
|
2618
|
+
* - `'string'` emits a datetime string node.
|
|
2619
|
+
* - `'stringOffset'` emits a datetime node with timezone offset.
|
|
2620
|
+
* - `'stringLocal'` emits a local datetime node.
|
|
2621
|
+
* - `'date'` emits a `date` node (JavaScript `Date` object).
|
|
2622
|
+
*/
|
|
2623
|
+
type DateTimeTypeValue = false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
2624
|
+
/**
|
|
2625
|
+
* How `format: 'date'` or `format: 'time'` schemas are represented downstream.
|
|
2626
|
+
* - `false` falls through to a plain `string` (no validation).
|
|
2627
|
+
* - `'string'` (default) emits a date or time string node.
|
|
2628
|
+
* - `'date'` emits a `date`/`time` node (JavaScript `Date` object).
|
|
2629
|
+
*/
|
|
2630
|
+
type DateOnlyTypeValue = false | 'string' | 'date';
|
|
2631
|
+
/**
|
|
2632
|
+
* Per-format override of `dateType`, so `date-time`, `date`, and `time` schemas can each
|
|
2633
|
+
* resolve to a different representation. A key left out defaults to `'string'`, the same
|
|
2634
|
+
* default as the scalar form of `dateType`.
|
|
2635
|
+
*/
|
|
2636
|
+
type DateTypeOptions = {
|
|
2637
|
+
dateTime?: DateTimeTypeValue;
|
|
2638
|
+
date?: DateOnlyTypeValue;
|
|
2639
|
+
time?: DateOnlyTypeValue;
|
|
2640
|
+
};
|
|
2641
|
+
/**
|
|
2642
|
+
* Options that control how the adapter parser maps source schemas to AST nodes.
|
|
2643
|
+
*/
|
|
2644
|
+
type ParserOptions = {
|
|
2645
|
+
/**
|
|
2646
|
+
* How `date-time`, `date`, and `time` formatted schemas are represented downstream.
|
|
2647
|
+
* A scalar value ({@link DateTimeTypeValue}) applies to all three formats, matching
|
|
2648
|
+
* the pre-5.1 behavior. Pass a {@link DateTypeOptions} object to set `dateTime`,
|
|
2649
|
+
* `date`, and `time` independently.
|
|
2650
|
+
*
|
|
2651
|
+
* @example Represent `date-time` as a JS `Date`, keep `date` and `time` as strings
|
|
2652
|
+
* ```ts
|
|
2653
|
+
* dateType: { dateTime: 'date' }
|
|
2654
|
+
* ```
|
|
2655
|
+
*/
|
|
2656
|
+
dateType: DateTimeTypeValue | DateTypeOptions;
|
|
2657
|
+
/**
|
|
2658
|
+
* How a schema with `format: 'int64'` or `format: 'uint64'` maps to TypeScript. Other
|
|
2659
|
+
* integers always map to `number`.
|
|
2660
|
+
* - `'bigint'` is exact for 64-bit IDs, but does not round-trip through JSON.
|
|
2661
|
+
* - `'number'` fits most JSON APIs. Loses precision above `Number.MAX_SAFE_INTEGER`.
|
|
2662
|
+
*
|
|
2663
|
+
* @default 'bigint'
|
|
2664
|
+
*/
|
|
2665
|
+
integerType?: 'number' | 'bigint';
|
|
2666
|
+
/**
|
|
2667
|
+
* AST type used when a schema's type cannot be inferred from the spec
|
|
2668
|
+
* (`additionalProperties: true`, missing `type`, ...).
|
|
2669
|
+
*/
|
|
2670
|
+
unknownType: 'any' | 'unknown' | 'void';
|
|
2671
|
+
/**
|
|
2672
|
+
* AST type used for completely empty schemas (`{}`).
|
|
2673
|
+
*/
|
|
2674
|
+
emptySchemaType: 'any' | 'unknown' | 'void';
|
|
2675
|
+
/**
|
|
2676
|
+
* Suffix appended to derived enum names when Kubb has to invent one
|
|
2677
|
+
* (typically for inline enums on object properties).
|
|
2678
|
+
*/
|
|
2679
|
+
enumSuffix: 'enum' | (string & {});
|
|
2680
|
+
};
|
|
2681
|
+
declare namespace index_d_exports {
|
|
2682
|
+
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InputMeta, InputNode, InputSecurityScheme, InputServer, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, composeMacros, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$1 as factory, findCircularSchemas, findCircularSchemasFromGraph, getSchemaLiteralValues, inferDiscriminatorPropertyName, isBareRef, isHttpOperationNode, mergeRefWithSchema, narrowSchema, optionality, refName, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
|
|
2683
|
+
}
|
|
2684
|
+
//#endregion
|
|
2685
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InputMeta, type InputNode, type InputSecurityScheme, type InputServer, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as factory };
|
|
2686
|
+
//# sourceMappingURL=index.d.cts.map
|