@kubb/ast 5.0.0-alpha.3 → 5.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1123 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +283 -17
- package/dist/index.js +1102 -154
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/visitor-z-5U8NoF.d.ts +2200 -0
- package/package.json +3 -2
- package/src/constants.ts +118 -4
- package/src/factory.ts +332 -18
- package/src/guards.ts +63 -8
- package/src/index.ts +25 -7
- package/src/infer.ts +130 -0
- package/src/mocks.ts +12 -5
- package/src/nodes/base.ts +32 -4
- package/src/nodes/function.ts +201 -0
- package/src/nodes/http.ts +17 -5
- package/src/nodes/index.ts +21 -5
- package/src/nodes/operation.ts +69 -6
- package/src/nodes/parameter.ts +27 -1
- package/src/nodes/property.ts +23 -1
- package/src/nodes/response.ts +29 -3
- package/src/nodes/root.ts +41 -10
- package/src/nodes/schema.ts +440 -42
- package/src/printer.ts +172 -60
- package/src/refs.ts +36 -4
- package/src/resolvers.ts +45 -0
- package/src/transformers.ts +156 -0
- package/src/types.ts +13 -2
- package/src/utils.ts +431 -4
- package/src/visitor.ts +378 -81
- package/dist/visitor-oFfdU8QA.d.ts +0 -653
package/src/nodes/schema.ts
CHANGED
|
@@ -1,213 +1,604 @@
|
|
|
1
1
|
import type { BaseNode } from './base.ts'
|
|
2
2
|
import type { PropertyNode } from './property.ts'
|
|
3
3
|
|
|
4
|
-
export type PrimitiveSchemaType =
|
|
4
|
+
export type PrimitiveSchemaType =
|
|
5
|
+
/**
|
|
6
|
+
* Text value.
|
|
7
|
+
*/
|
|
8
|
+
| 'string'
|
|
9
|
+
/**
|
|
10
|
+
* Floating-point number.
|
|
11
|
+
*/
|
|
12
|
+
| 'number'
|
|
13
|
+
/**
|
|
14
|
+
* Integer number.
|
|
15
|
+
*/
|
|
16
|
+
| 'integer'
|
|
17
|
+
/**
|
|
18
|
+
* Big integer number.
|
|
19
|
+
*/
|
|
20
|
+
| 'bigint'
|
|
21
|
+
/**
|
|
22
|
+
* Boolean value.
|
|
23
|
+
*/
|
|
24
|
+
| 'boolean'
|
|
25
|
+
/**
|
|
26
|
+
* Null value.
|
|
27
|
+
*/
|
|
28
|
+
| 'null'
|
|
29
|
+
/**
|
|
30
|
+
* Any value.
|
|
31
|
+
*/
|
|
32
|
+
| 'any'
|
|
33
|
+
/**
|
|
34
|
+
* Unknown value.
|
|
35
|
+
*/
|
|
36
|
+
| 'unknown'
|
|
37
|
+
/**
|
|
38
|
+
* No value (`void`).
|
|
39
|
+
*/
|
|
40
|
+
| 'void'
|
|
41
|
+
/**
|
|
42
|
+
* Never value.
|
|
43
|
+
*/
|
|
44
|
+
| 'never'
|
|
45
|
+
/**
|
|
46
|
+
* Object value.
|
|
47
|
+
*/
|
|
48
|
+
| 'object'
|
|
49
|
+
/**
|
|
50
|
+
* Array value.
|
|
51
|
+
*/
|
|
52
|
+
| 'array'
|
|
53
|
+
/**
|
|
54
|
+
* Date value.
|
|
55
|
+
*/
|
|
56
|
+
| 'date'
|
|
5
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Composite schema types.
|
|
60
|
+
*/
|
|
6
61
|
export type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum'
|
|
7
62
|
|
|
8
63
|
/**
|
|
9
|
-
*
|
|
64
|
+
* Schema types that need special handling in generators.
|
|
10
65
|
*/
|
|
11
|
-
export type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'blob'
|
|
66
|
+
export type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'ipv4' | 'ipv6' | 'blob'
|
|
12
67
|
|
|
68
|
+
/**
|
|
69
|
+
* All schema type strings.
|
|
70
|
+
*/
|
|
13
71
|
export type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType
|
|
14
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Scalar schema types without extra object/array/ref structure.
|
|
75
|
+
*/
|
|
15
76
|
export type ScalarSchemaType = Exclude<
|
|
16
77
|
SchemaType,
|
|
17
|
-
|
|
78
|
+
| 'object'
|
|
79
|
+
| 'array'
|
|
80
|
+
| 'tuple'
|
|
81
|
+
| 'union'
|
|
82
|
+
| 'intersection'
|
|
83
|
+
| 'enum'
|
|
84
|
+
| 'ref'
|
|
85
|
+
| 'datetime'
|
|
86
|
+
| 'date'
|
|
87
|
+
| 'time'
|
|
88
|
+
| 'string'
|
|
89
|
+
| 'number'
|
|
90
|
+
| 'integer'
|
|
91
|
+
| 'bigint'
|
|
92
|
+
| 'url'
|
|
93
|
+
| 'uuid'
|
|
94
|
+
| 'email'
|
|
18
95
|
>
|
|
19
96
|
|
|
20
97
|
/**
|
|
21
|
-
*
|
|
98
|
+
* Fields shared by all schema nodes.
|
|
22
99
|
*/
|
|
23
100
|
type SchemaNodeBase = BaseNode & {
|
|
101
|
+
/**
|
|
102
|
+
* Node kind.
|
|
103
|
+
*/
|
|
24
104
|
kind: 'Schema'
|
|
25
105
|
/**
|
|
26
|
-
*
|
|
106
|
+
* Schema name for named definitions (for example, `"Pet"`).
|
|
107
|
+
* Inline schemas omit this field.
|
|
108
|
+
* `null` means kubb has processed this and determined there is no applicable name.
|
|
109
|
+
* `undefined` means the name has not been set yet.
|
|
110
|
+
*/
|
|
111
|
+
name?: string | null
|
|
112
|
+
/**
|
|
113
|
+
* Short schema title.
|
|
27
114
|
*/
|
|
28
|
-
name?: string
|
|
29
115
|
title?: string
|
|
116
|
+
/**
|
|
117
|
+
* Schema description text.
|
|
118
|
+
*/
|
|
30
119
|
description?: string
|
|
120
|
+
/**
|
|
121
|
+
* Whether `null` is allowed.
|
|
122
|
+
*/
|
|
31
123
|
nullable?: boolean
|
|
124
|
+
/**
|
|
125
|
+
* Whether the field is optional.
|
|
126
|
+
*/
|
|
32
127
|
optional?: boolean
|
|
33
128
|
/**
|
|
34
129
|
* Both optional and nullable (`optional` + `nullable`).
|
|
35
130
|
*/
|
|
36
131
|
nullish?: boolean
|
|
132
|
+
/**
|
|
133
|
+
* Whether the schema is deprecated.
|
|
134
|
+
*/
|
|
37
135
|
deprecated?: boolean
|
|
136
|
+
/**
|
|
137
|
+
* Whether the schema is read-only.
|
|
138
|
+
*/
|
|
38
139
|
readOnly?: boolean
|
|
140
|
+
/**
|
|
141
|
+
* Whether the schema is write-only.
|
|
142
|
+
*/
|
|
39
143
|
writeOnly?: boolean
|
|
144
|
+
/**
|
|
145
|
+
* Default value.
|
|
146
|
+
*/
|
|
40
147
|
default?: unknown
|
|
148
|
+
/**
|
|
149
|
+
* Example value.
|
|
150
|
+
*/
|
|
41
151
|
example?: unknown
|
|
42
152
|
/**
|
|
43
|
-
*
|
|
153
|
+
* Base primitive type.
|
|
154
|
+
* For example, this is `'string'` for a `uuid` schema.
|
|
44
155
|
*/
|
|
45
156
|
primitive?: PrimitiveSchemaType
|
|
46
157
|
}
|
|
47
158
|
|
|
48
159
|
/**
|
|
49
|
-
* Object schema with ordered
|
|
160
|
+
* Object schema with ordered properties.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* const objectSchema: ObjectSchemaNode = {
|
|
165
|
+
* kind: 'Schema',
|
|
166
|
+
* type: 'object',
|
|
167
|
+
* properties: [],
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
50
170
|
*/
|
|
51
171
|
export type ObjectSchemaNode = SchemaNodeBase & {
|
|
172
|
+
/**
|
|
173
|
+
* Schema type discriminator.
|
|
174
|
+
*/
|
|
52
175
|
type: 'object'
|
|
176
|
+
/**
|
|
177
|
+
* Primitive type — always `'object'` for object schemas.
|
|
178
|
+
*/
|
|
179
|
+
primitive: 'object'
|
|
180
|
+
/**
|
|
181
|
+
* Ordered object properties.
|
|
182
|
+
*/
|
|
53
183
|
properties: Array<PropertyNode>
|
|
54
184
|
/**
|
|
55
|
-
*
|
|
185
|
+
* Additional object properties behavior:
|
|
186
|
+
* - `true`: allow any value
|
|
187
|
+
* - `false`: reject unknown properties (maps to `.strict()` in Zod)
|
|
188
|
+
* - `SchemaNode`: allow values that match that schema
|
|
189
|
+
* - `undefined`: no additional properties constraint (open object)
|
|
190
|
+
*/
|
|
191
|
+
additionalProperties?: SchemaNode | boolean
|
|
192
|
+
/**
|
|
193
|
+
* Pattern-based property schemas.
|
|
56
194
|
*/
|
|
57
|
-
additionalProperties?: SchemaNode | true
|
|
58
195
|
patternProperties?: Record<string, SchemaNode>
|
|
196
|
+
/**
|
|
197
|
+
* Minimum number of properties allowed.
|
|
198
|
+
*/
|
|
199
|
+
minProperties?: number
|
|
200
|
+
/**
|
|
201
|
+
* Maximum number of properties allowed.
|
|
202
|
+
*/
|
|
203
|
+
maxProperties?: number
|
|
59
204
|
}
|
|
60
205
|
|
|
61
206
|
/**
|
|
62
|
-
* Array or tuple
|
|
207
|
+
* Array-like schema (`array` or `tuple`).
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const arraySchema: ArraySchemaNode = {
|
|
212
|
+
* kind: 'Schema',
|
|
213
|
+
* type: 'array',
|
|
214
|
+
* items: [],
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
63
217
|
*/
|
|
64
218
|
export type ArraySchemaNode = SchemaNodeBase & {
|
|
219
|
+
/**
|
|
220
|
+
* Schema type discriminator (`array` or `tuple`).
|
|
221
|
+
*/
|
|
65
222
|
type: 'array' | 'tuple'
|
|
223
|
+
/**
|
|
224
|
+
* Item schemas.
|
|
225
|
+
*/
|
|
66
226
|
items?: Array<SchemaNode>
|
|
67
227
|
/**
|
|
68
|
-
*
|
|
228
|
+
* Tuple rest-item schema for elements beyond positional `items`.
|
|
69
229
|
*/
|
|
70
230
|
rest?: SchemaNode
|
|
231
|
+
/**
|
|
232
|
+
* Minimum item count (or tuple length).
|
|
233
|
+
*/
|
|
71
234
|
min?: number
|
|
235
|
+
/**
|
|
236
|
+
* Maximum item count (or tuple length).
|
|
237
|
+
*/
|
|
72
238
|
max?: number
|
|
239
|
+
/**
|
|
240
|
+
* Whether all items must be unique.
|
|
241
|
+
*/
|
|
73
242
|
unique?: boolean
|
|
74
243
|
}
|
|
75
244
|
|
|
76
245
|
/**
|
|
77
|
-
* Shared
|
|
246
|
+
* Shared shape for union and intersection schemas.
|
|
78
247
|
*/
|
|
79
248
|
type CompositeSchemaNodeBase = SchemaNodeBase & {
|
|
249
|
+
/**
|
|
250
|
+
* Member schemas.
|
|
251
|
+
*/
|
|
80
252
|
members?: Array<SchemaNode>
|
|
81
253
|
}
|
|
82
254
|
|
|
83
255
|
/**
|
|
84
|
-
* Union schema
|
|
256
|
+
* Union schema, often from `oneOf` or `anyOf`.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* const unionSchema: UnionSchemaNode = {
|
|
261
|
+
* kind: 'Schema',
|
|
262
|
+
* type: 'union',
|
|
263
|
+
* members: [],
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
85
266
|
*/
|
|
86
267
|
export type UnionSchemaNode = CompositeSchemaNodeBase & {
|
|
268
|
+
/**
|
|
269
|
+
* Schema type discriminator.
|
|
270
|
+
*/
|
|
87
271
|
type: 'union'
|
|
88
272
|
/**
|
|
89
|
-
* Discriminator property from
|
|
273
|
+
* Discriminator property name from OpenAPI `discriminator.propertyName`.
|
|
90
274
|
*/
|
|
91
275
|
discriminatorPropertyName?: string
|
|
92
276
|
}
|
|
93
277
|
|
|
94
278
|
/**
|
|
95
|
-
* Intersection schema
|
|
279
|
+
* Intersection schema, often from `allOf`.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* const intersectionSchema: IntersectionSchemaNode = {
|
|
284
|
+
* kind: 'Schema',
|
|
285
|
+
* type: 'intersection',
|
|
286
|
+
* members: [],
|
|
287
|
+
* }
|
|
288
|
+
* ```
|
|
96
289
|
*/
|
|
97
290
|
export type IntersectionSchemaNode = CompositeSchemaNodeBase & {
|
|
291
|
+
/**
|
|
292
|
+
* Schema type discriminator.
|
|
293
|
+
*/
|
|
98
294
|
type: 'intersection'
|
|
99
295
|
}
|
|
100
296
|
|
|
101
297
|
/**
|
|
102
|
-
*
|
|
298
|
+
* One named enum item.
|
|
103
299
|
*/
|
|
104
300
|
export type EnumValueNode = {
|
|
301
|
+
/**
|
|
302
|
+
* Enum item name.
|
|
303
|
+
*/
|
|
105
304
|
name: string
|
|
305
|
+
/**
|
|
306
|
+
* Enum item value.
|
|
307
|
+
*/
|
|
106
308
|
value: string | number | boolean
|
|
107
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Primitive type of the enum value.
|
|
311
|
+
*/
|
|
312
|
+
primitive: Extract<PrimitiveSchemaType, 'string' | 'number' | 'boolean'>
|
|
108
313
|
}
|
|
109
314
|
|
|
110
315
|
/**
|
|
111
|
-
* Enum schema.
|
|
316
|
+
* Enum schema node.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* const enumSchema: EnumSchemaNode = {
|
|
321
|
+
* kind: 'Schema',
|
|
322
|
+
* type: 'enum',
|
|
323
|
+
* enumValues: ['a', 'b'],
|
|
324
|
+
* }
|
|
325
|
+
* ```
|
|
112
326
|
*/
|
|
113
327
|
export type EnumSchemaNode = SchemaNodeBase & {
|
|
114
|
-
type: 'enum'
|
|
115
328
|
/**
|
|
116
|
-
*
|
|
329
|
+
* Schema type discriminator.
|
|
117
330
|
*/
|
|
118
|
-
|
|
331
|
+
type: 'enum'
|
|
119
332
|
/**
|
|
120
|
-
*
|
|
333
|
+
* Enum values in simple form.
|
|
121
334
|
*/
|
|
122
335
|
enumValues?: Array<string | number | boolean | null>
|
|
123
336
|
/**
|
|
124
|
-
*
|
|
337
|
+
* Enum values in named form.
|
|
338
|
+
* If present, this is used instead of `enumValues`.
|
|
125
339
|
*/
|
|
126
340
|
namedEnumValues?: Array<EnumValueNode>
|
|
127
341
|
}
|
|
128
342
|
|
|
129
343
|
/**
|
|
130
|
-
*
|
|
344
|
+
* Reference schema that points to another schema definition.
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* const refSchema: RefSchemaNode = {
|
|
349
|
+
* kind: 'Schema',
|
|
350
|
+
* type: 'ref',
|
|
351
|
+
* ref: '#/components/schemas/Pet',
|
|
352
|
+
* }
|
|
353
|
+
* ```
|
|
131
354
|
*/
|
|
132
355
|
export type RefSchemaNode = SchemaNodeBase & {
|
|
356
|
+
/**
|
|
357
|
+
* Schema type discriminator.
|
|
358
|
+
*/
|
|
133
359
|
type: 'ref'
|
|
360
|
+
/**
|
|
361
|
+
* Referenced schema name.
|
|
362
|
+
*/
|
|
134
363
|
name?: string
|
|
135
364
|
/**
|
|
136
|
-
* Original `$ref` path
|
|
365
|
+
* Original `$ref` path, for example, `#/components/schemas/Order`.
|
|
366
|
+
* Used to resolve names later.
|
|
137
367
|
*/
|
|
138
368
|
ref?: string
|
|
139
369
|
/**
|
|
140
|
-
* Pattern
|
|
370
|
+
* Pattern copied from a sibling `pattern` field.
|
|
141
371
|
*/
|
|
142
372
|
pattern?: string
|
|
373
|
+
/**
|
|
374
|
+
* The fully-parsed schema that this ref resolves to.
|
|
375
|
+
* Populated during OAS parsing when the referenced definition can be resolved.
|
|
376
|
+
* `undefined` when the ref cannot be resolved or is part of a circular chain.
|
|
377
|
+
*
|
|
378
|
+
* Useful for inspecting the referenced schema's structure (e.g. `primitive`, `properties`)
|
|
379
|
+
* without following the reference manually.
|
|
380
|
+
*/
|
|
381
|
+
schema?: SchemaNode
|
|
143
382
|
}
|
|
144
383
|
|
|
145
384
|
/**
|
|
146
385
|
* Datetime schema.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* const datetimeSchema: DatetimeSchemaNode = { kind: 'Schema', type: 'datetime' }
|
|
390
|
+
* ```
|
|
147
391
|
*/
|
|
148
392
|
export type DatetimeSchemaNode = SchemaNodeBase & {
|
|
393
|
+
/**
|
|
394
|
+
* Schema type discriminator.
|
|
395
|
+
*/
|
|
149
396
|
type: 'datetime'
|
|
150
397
|
/**
|
|
151
|
-
*
|
|
398
|
+
* Whether the datetime includes a timezone offset (`dateType: 'stringOffset'`).
|
|
152
399
|
*/
|
|
153
400
|
offset?: boolean
|
|
154
401
|
/**
|
|
155
|
-
*
|
|
402
|
+
* Whether the datetime is local (no timezone, `dateType: 'stringLocal'`).
|
|
156
403
|
*/
|
|
157
404
|
local?: boolean
|
|
158
405
|
}
|
|
159
406
|
|
|
160
407
|
/**
|
|
161
|
-
*
|
|
408
|
+
* Shared base for `date` and `time` schemas.
|
|
162
409
|
*/
|
|
163
410
|
type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
|
|
411
|
+
/**
|
|
412
|
+
* Schema type discriminator.
|
|
413
|
+
*/
|
|
164
414
|
type: T
|
|
165
415
|
/**
|
|
166
|
-
*
|
|
416
|
+
* Output representation in generated code.
|
|
167
417
|
*/
|
|
168
418
|
representation: 'date' | 'string'
|
|
169
419
|
}
|
|
170
420
|
|
|
171
421
|
/**
|
|
172
|
-
* Date schema.
|
|
422
|
+
* Date schema node.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* const dateSchema: DateSchemaNode = { kind: 'Schema', type: 'date', representation: 'string' }
|
|
427
|
+
* ```
|
|
173
428
|
*/
|
|
174
429
|
export type DateSchemaNode = TemporalSchemaNodeBase<'date'>
|
|
175
430
|
|
|
176
431
|
/**
|
|
177
|
-
* Time schema.
|
|
432
|
+
* Time schema node.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```ts
|
|
436
|
+
* const timeSchema: TimeSchemaNode = { kind: 'Schema', type: 'time', representation: 'string' }
|
|
437
|
+
* ```
|
|
178
438
|
*/
|
|
179
439
|
export type TimeSchemaNode = TemporalSchemaNodeBase<'time'>
|
|
180
440
|
|
|
181
441
|
/**
|
|
182
|
-
* String schema.
|
|
442
|
+
* String schema node.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```ts
|
|
446
|
+
* const stringSchema: StringSchemaNode = { kind: 'Schema', type: 'string' }
|
|
447
|
+
* ```
|
|
183
448
|
*/
|
|
184
449
|
export type StringSchemaNode = SchemaNodeBase & {
|
|
450
|
+
/**
|
|
451
|
+
* Schema type discriminator.
|
|
452
|
+
*/
|
|
185
453
|
type: 'string'
|
|
454
|
+
/**
|
|
455
|
+
* Minimum string length.
|
|
456
|
+
*/
|
|
186
457
|
min?: number
|
|
458
|
+
/**
|
|
459
|
+
* Maximum string length.
|
|
460
|
+
*/
|
|
187
461
|
max?: number
|
|
462
|
+
/**
|
|
463
|
+
* Regex pattern.
|
|
464
|
+
*/
|
|
188
465
|
pattern?: string
|
|
189
466
|
}
|
|
190
467
|
|
|
191
468
|
/**
|
|
192
|
-
*
|
|
469
|
+
* Numeric schema (`number`, `integer`, or `bigint`).
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* const numberSchema: NumberSchemaNode = { kind: 'Schema', type: 'number' }
|
|
474
|
+
* ```
|
|
193
475
|
*/
|
|
194
476
|
export type NumberSchemaNode = SchemaNodeBase & {
|
|
477
|
+
/**
|
|
478
|
+
* Schema type discriminator.
|
|
479
|
+
*/
|
|
195
480
|
type: 'number' | 'integer' | 'bigint'
|
|
481
|
+
/**
|
|
482
|
+
* Minimum value.
|
|
483
|
+
*/
|
|
196
484
|
min?: number
|
|
485
|
+
/**
|
|
486
|
+
* Maximum value.
|
|
487
|
+
*/
|
|
197
488
|
max?: number
|
|
489
|
+
/**
|
|
490
|
+
* Exclusive minimum value.
|
|
491
|
+
*/
|
|
198
492
|
exclusiveMinimum?: number
|
|
493
|
+
/**
|
|
494
|
+
* Exclusive maximum value.
|
|
495
|
+
*/
|
|
199
496
|
exclusiveMaximum?: number
|
|
497
|
+
/**
|
|
498
|
+
* The value must be a multiple of this number.
|
|
499
|
+
*/
|
|
500
|
+
multipleOf?: number
|
|
200
501
|
}
|
|
201
502
|
|
|
202
503
|
/**
|
|
203
|
-
*
|
|
504
|
+
* Scalar schema with no extra constraints.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* const anySchema: ScalarSchemaNode = { kind: 'Schema', type: 'any' }
|
|
509
|
+
* ```
|
|
204
510
|
*/
|
|
205
511
|
export type ScalarSchemaNode = SchemaNodeBase & {
|
|
512
|
+
/**
|
|
513
|
+
* Schema type discriminator.
|
|
514
|
+
*/
|
|
206
515
|
type: ScalarSchemaType
|
|
207
516
|
}
|
|
208
517
|
|
|
209
518
|
/**
|
|
210
|
-
*
|
|
519
|
+
* URL schema node.
|
|
520
|
+
* Can include an OpenAPI-style path template for template literal types.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets/{petId}' }
|
|
525
|
+
* ```
|
|
526
|
+
*/
|
|
527
|
+
export type UrlSchemaNode = SchemaNodeBase & {
|
|
528
|
+
/**
|
|
529
|
+
* Schema type discriminator.
|
|
530
|
+
*/
|
|
531
|
+
type: 'url'
|
|
532
|
+
/**
|
|
533
|
+
* OpenAPI-style path template, for example, `'/pets/{petId}'`.
|
|
534
|
+
*/
|
|
535
|
+
path?: string
|
|
536
|
+
/**
|
|
537
|
+
* Minimum string length.
|
|
538
|
+
*/
|
|
539
|
+
min?: number
|
|
540
|
+
/**
|
|
541
|
+
* Maximum string length.
|
|
542
|
+
*/
|
|
543
|
+
max?: number
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Format-string schema for string-based formats that support length constraints.
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```ts
|
|
551
|
+
* const uuidSchema: FormatStringSchemaNode = { kind: 'Schema', type: 'uuid', min: 36, max: 36 }
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
export type FormatStringSchemaNode = SchemaNodeBase & {
|
|
555
|
+
/**
|
|
556
|
+
* Schema type discriminator.
|
|
557
|
+
*/
|
|
558
|
+
type: 'uuid' | 'email'
|
|
559
|
+
/**
|
|
560
|
+
* Minimum string length.
|
|
561
|
+
*/
|
|
562
|
+
min?: number
|
|
563
|
+
/**
|
|
564
|
+
* Maximum string length.
|
|
565
|
+
*/
|
|
566
|
+
max?: number
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* IPv4 address schema node.
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* ```ts
|
|
574
|
+
* const ipv4Schema: Ipv4SchemaNode = { kind: 'Schema', type: 'ipv4' }
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
export type Ipv4SchemaNode = SchemaNodeBase & {
|
|
578
|
+
/**
|
|
579
|
+
* Schema type discriminator.
|
|
580
|
+
*/
|
|
581
|
+
type: 'ipv4'
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* IPv6 address schema node.
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```ts
|
|
589
|
+
* const ipv6Schema: Ipv6SchemaNode = { kind: 'Schema', type: 'ipv6' }
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
export type Ipv6SchemaNode = SchemaNodeBase & {
|
|
593
|
+
/**
|
|
594
|
+
* Schema type discriminator.
|
|
595
|
+
*/
|
|
596
|
+
type: 'ipv6'
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Mapping from schema type literals to concrete schema node types.
|
|
601
|
+
* Used by `narrowSchema`.
|
|
211
602
|
*/
|
|
212
603
|
export type SchemaNodeByType = {
|
|
213
604
|
object: ObjectSchemaNode
|
|
@@ -229,14 +620,17 @@ export type SchemaNodeByType = {
|
|
|
229
620
|
any: ScalarSchemaNode
|
|
230
621
|
unknown: ScalarSchemaNode
|
|
231
622
|
void: ScalarSchemaNode
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
623
|
+
never: ScalarSchemaNode
|
|
624
|
+
uuid: FormatStringSchemaNode
|
|
625
|
+
email: FormatStringSchemaNode
|
|
626
|
+
url: UrlSchemaNode
|
|
627
|
+
ipv4: Ipv4SchemaNode
|
|
628
|
+
ipv6: Ipv6SchemaNode
|
|
235
629
|
blob: ScalarSchemaNode
|
|
236
630
|
}
|
|
237
631
|
|
|
238
632
|
/**
|
|
239
|
-
*
|
|
633
|
+
* Union of all schema node types.
|
|
240
634
|
*/
|
|
241
635
|
export type SchemaNode =
|
|
242
636
|
| ObjectSchemaNode
|
|
@@ -250,4 +644,8 @@ export type SchemaNode =
|
|
|
250
644
|
| TimeSchemaNode
|
|
251
645
|
| StringSchemaNode
|
|
252
646
|
| NumberSchemaNode
|
|
647
|
+
| UrlSchemaNode
|
|
648
|
+
| FormatStringSchemaNode
|
|
649
|
+
| Ipv4SchemaNode
|
|
650
|
+
| Ipv6SchemaNode
|
|
253
651
|
| ScalarSchemaNode
|