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