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