1 | // ==================================================================================================
|
2 | // JSON Schema Draft 04
|
3 | // ==================================================================================================
|
4 |
|
5 | /**
|
6 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1
|
7 | */
|
8 | export type JSONSchema4TypeName =
|
9 | | "string" //
|
10 | | "number"
|
11 | | "integer"
|
12 | | "boolean"
|
13 | | "object"
|
14 | | "array"
|
15 | | "null"
|
16 | | "any";
|
17 |
|
18 | /**
|
19 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-3.5
|
20 | */
|
21 | export type JSONSchema4Type =
|
22 | | string //
|
23 | | number
|
24 | | boolean
|
25 | | JSONSchema4Object
|
26 | | JSONSchema4Array
|
27 | | null;
|
28 |
|
29 | // Workaround for infinite type recursion
|
30 | export interface JSONSchema4Object {
|
31 | [key: string]: JSONSchema4Type;
|
32 | }
|
33 |
|
34 | // Workaround for infinite type recursion
|
35 | // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
36 | export interface JSONSchema4Array extends Array<JSONSchema4Type> {}
|
37 |
|
38 | /**
|
39 | * Meta schema
|
40 | *
|
41 | * Recommended values:
|
42 | * - 'http://json-schema.org/schema#'
|
43 | * - 'http://json-schema.org/hyper-schema#'
|
44 | * - 'http://json-schema.org/draft-04/schema#'
|
45 | * - 'http://json-schema.org/draft-04/hyper-schema#'
|
46 | * - 'http://json-schema.org/draft-03/schema#'
|
47 | * - 'http://json-schema.org/draft-03/hyper-schema#'
|
48 | *
|
49 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
50 | */
|
51 | export type JSONSchema4Version = string;
|
52 |
|
53 | /**
|
54 | * JSON Schema V4
|
55 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-04
|
56 | */
|
57 | export interface JSONSchema4 {
|
58 | id?: string | undefined;
|
59 | $ref?: string | undefined;
|
60 | $schema?: JSONSchema4Version | undefined;
|
61 |
|
62 | /**
|
63 | * This attribute is a string that provides a short description of the
|
64 | * instance property.
|
65 | *
|
66 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.21
|
67 | */
|
68 | title?: string | undefined;
|
69 |
|
70 | /**
|
71 | * This attribute is a string that provides a full description of the of
|
72 | * purpose the instance property.
|
73 | *
|
74 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.22
|
75 | */
|
76 | description?: string | undefined;
|
77 |
|
78 | default?: JSONSchema4Type | undefined;
|
79 | multipleOf?: number | undefined;
|
80 | maximum?: number | undefined;
|
81 | exclusiveMaximum?: boolean | undefined;
|
82 | minimum?: number | undefined;
|
83 | exclusiveMinimum?: boolean | undefined;
|
84 | maxLength?: number | undefined;
|
85 | minLength?: number | undefined;
|
86 | pattern?: string | undefined;
|
87 |
|
88 | /**
|
89 | * May only be defined when "items" is defined, and is a tuple of JSONSchemas.
|
90 | *
|
91 | * This provides a definition for additional items in an array instance
|
92 | * when tuple definitions of the items is provided. This can be false
|
93 | * to indicate additional items in the array are not allowed, or it can
|
94 | * be a schema that defines the schema of the additional items.
|
95 | *
|
96 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.6
|
97 | */
|
98 | additionalItems?: boolean | JSONSchema4 | undefined;
|
99 |
|
100 | /**
|
101 | * This attribute defines the allowed items in an instance array, and
|
102 | * MUST be a schema or an array of schemas. The default value is an
|
103 | * empty schema which allows any value for items in the instance array.
|
104 | *
|
105 | * When this attribute value is a schema and the instance value is an
|
106 | * array, then all the items in the array MUST be valid according to the
|
107 | * schema.
|
108 | *
|
109 | * When this attribute value is an array of schemas and the instance
|
110 | * value is an array, each position in the instance array MUST conform
|
111 | * to the schema in the corresponding position for this array. This
|
112 | * called tuple typing. When tuple typing is used, additional items are
|
113 | * allowed, disallowed, or constrained by the "additionalItems"
|
114 | * (Section 5.6) attribute using the same rules as
|
115 | * "additionalProperties" (Section 5.4) for objects.
|
116 | *
|
117 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.5
|
118 | */
|
119 | items?: JSONSchema4 | JSONSchema4[] | undefined;
|
120 |
|
121 | maxItems?: number | undefined;
|
122 | minItems?: number | undefined;
|
123 | uniqueItems?: boolean | undefined;
|
124 | maxProperties?: number | undefined;
|
125 | minProperties?: number | undefined;
|
126 |
|
127 | /**
|
128 | * This attribute indicates if the instance must have a value, and not
|
129 | * be undefined. This is false by default, making the instance
|
130 | * optional.
|
131 | *
|
132 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7
|
133 | */
|
134 | required?: boolean | string[] | undefined;
|
135 |
|
136 | /**
|
137 | * This attribute defines a schema for all properties that are not
|
138 | * explicitly defined in an object type definition. If specified, the
|
139 | * value MUST be a schema or a boolean. If false is provided, no
|
140 | * additional properties are allowed beyond the properties defined in
|
141 | * the schema. The default value is an empty schema which allows any
|
142 | * value for additional properties.
|
143 | *
|
144 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.4
|
145 | */
|
146 | additionalProperties?: boolean | JSONSchema4 | undefined;
|
147 |
|
148 | definitions?: {
|
149 | [k: string]: JSONSchema4;
|
150 | } | undefined;
|
151 |
|
152 | /**
|
153 | * This attribute is an object with property definitions that define the
|
154 | * valid values of instance object property values. When the instance
|
155 | * value is an object, the property values of the instance object MUST
|
156 | * conform to the property definitions in this object. In this object,
|
157 | * each property definition's value MUST be a schema, and the property's
|
158 | * name MUST be the name of the instance property that it defines. The
|
159 | * instance property value MUST be valid according to the schema from
|
160 | * the property definition. Properties are considered unordered, the
|
161 | * order of the instance properties MAY be in any order.
|
162 | *
|
163 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.2
|
164 | */
|
165 | properties?: {
|
166 | [k: string]: JSONSchema4;
|
167 | } | undefined;
|
168 |
|
169 | /**
|
170 | * This attribute is an object that defines the schema for a set of
|
171 | * property names of an object instance. The name of each property of
|
172 | * this attribute's object is a regular expression pattern in the ECMA
|
173 | * 262/Perl 5 format, while the value is a schema. If the pattern
|
174 | * matches the name of a property on the instance object, the value of
|
175 | * the instance's property MUST be valid against the pattern name's
|
176 | * schema value.
|
177 | *
|
178 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.3
|
179 | */
|
180 | patternProperties?: {
|
181 | [k: string]: JSONSchema4;
|
182 | } | undefined;
|
183 | dependencies?: {
|
184 | [k: string]: JSONSchema4 | string[];
|
185 | } | undefined;
|
186 |
|
187 | /**
|
188 | * This provides an enumeration of all possible values that are valid
|
189 | * for the instance property. This MUST be an array, and each item in
|
190 | * the array represents a possible value for the instance value. If
|
191 | * this attribute is defined, the instance value MUST be one of the
|
192 | * values in the array in order for the schema to be valid.
|
193 | *
|
194 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.19
|
195 | */
|
196 | enum?: JSONSchema4Type[] | undefined;
|
197 |
|
198 | /**
|
199 | * A single type, or a union of simple types
|
200 | */
|
201 | type?: JSONSchema4TypeName | JSONSchema4TypeName[] | undefined;
|
202 |
|
203 | allOf?: JSONSchema4[] | undefined;
|
204 | anyOf?: JSONSchema4[] | undefined;
|
205 | oneOf?: JSONSchema4[] | undefined;
|
206 | not?: JSONSchema4 | undefined;
|
207 |
|
208 | /**
|
209 | * The value of this property MUST be another schema which will provide
|
210 | * a base schema which the current schema will inherit from. The
|
211 | * inheritance rules are such that any instance that is valid according
|
212 | * to the current schema MUST be valid according to the referenced
|
213 | * schema. This MAY also be an array, in which case, the instance MUST
|
214 | * be valid for all the schemas in the array. A schema that extends
|
215 | * another schema MAY define additional attributes, constrain existing
|
216 | * attributes, or add other constraints.
|
217 | *
|
218 | * Conceptually, the behavior of extends can be seen as validating an
|
219 | * instance against all constraints in the extending schema as well as
|
220 | * the extended schema(s).
|
221 | *
|
222 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.26
|
223 | */
|
224 | extends?: string | string[] | undefined;
|
225 |
|
226 | /**
|
227 | * @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-5.6
|
228 | */
|
229 | [k: string]: any;
|
230 |
|
231 | format?: string | undefined;
|
232 | }
|
233 |
|
234 | // ==================================================================================================
|
235 | // JSON Schema Draft 06
|
236 | // ==================================================================================================
|
237 |
|
238 | export type JSONSchema6TypeName =
|
239 | | "string" //
|
240 | | "number"
|
241 | | "integer"
|
242 | | "boolean"
|
243 | | "object"
|
244 | | "array"
|
245 | | "null"
|
246 | | "any";
|
247 |
|
248 | export type JSONSchema6Type =
|
249 | | string //
|
250 | | number
|
251 | | boolean
|
252 | | JSONSchema6Object
|
253 | | JSONSchema6Array
|
254 | | null;
|
255 |
|
256 | // Workaround for infinite type recursion
|
257 | export interface JSONSchema6Object {
|
258 | [key: string]: JSONSchema6Type;
|
259 | }
|
260 |
|
261 | // Workaround for infinite type recursion
|
262 | // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
263 | export interface JSONSchema6Array extends Array<JSONSchema6Type> {}
|
264 |
|
265 | /**
|
266 | * Meta schema
|
267 | *
|
268 | * Recommended values:
|
269 | * - 'http://json-schema.org/schema#'
|
270 | * - 'http://json-schema.org/hyper-schema#'
|
271 | * - 'http://json-schema.org/draft-06/schema#'
|
272 | * - 'http://json-schema.org/draft-06/hyper-schema#'
|
273 | *
|
274 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
275 | */
|
276 | export type JSONSchema6Version = string;
|
277 |
|
278 | /**
|
279 | * JSON Schema V6
|
280 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01
|
281 | */
|
282 | export type JSONSchema6Definition = JSONSchema6 | boolean;
|
283 | export interface JSONSchema6 {
|
284 | $id?: string | undefined;
|
285 | $ref?: string | undefined;
|
286 | $schema?: JSONSchema6Version | undefined;
|
287 |
|
288 | /**
|
289 | * Must be strictly greater than 0.
|
290 | * A numeric instance is valid only if division by this keyword's value results in an integer.
|
291 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.1
|
292 | */
|
293 | multipleOf?: number | undefined;
|
294 |
|
295 | /**
|
296 | * Representing an inclusive upper limit for a numeric instance.
|
297 | * This keyword validates only if the instance is less than or exactly equal to "maximum".
|
298 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.2
|
299 | */
|
300 | maximum?: number | undefined;
|
301 |
|
302 | /**
|
303 | * Representing an exclusive upper limit for a numeric instance.
|
304 | * This keyword validates only if the instance is strictly less than (not equal to) to "exclusiveMaximum".
|
305 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.3
|
306 | */
|
307 | exclusiveMaximum?: number | undefined;
|
308 |
|
309 | /**
|
310 | * Representing an inclusive lower limit for a numeric instance.
|
311 | * This keyword validates only if the instance is greater than or exactly equal to "minimum".
|
312 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.4
|
313 | */
|
314 | minimum?: number | undefined;
|
315 |
|
316 | /**
|
317 | * Representing an exclusive lower limit for a numeric instance.
|
318 | * This keyword validates only if the instance is strictly greater than (not equal to) to "exclusiveMinimum".
|
319 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.5
|
320 | */
|
321 | exclusiveMinimum?: number | undefined;
|
322 |
|
323 | /**
|
324 | * Must be a non-negative integer.
|
325 | * A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.
|
326 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.6
|
327 | */
|
328 | maxLength?: number | undefined;
|
329 |
|
330 | /**
|
331 | * Must be a non-negative integer.
|
332 | * A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
|
333 | * Omitting this keyword has the same behavior as a value of 0.
|
334 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.7
|
335 | */
|
336 | minLength?: number | undefined;
|
337 |
|
338 | /**
|
339 | * Should be a valid regular expression, according to the ECMA 262 regular expression dialect.
|
340 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.8
|
341 | */
|
342 | pattern?: string | undefined;
|
343 |
|
344 | /**
|
345 | * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.
|
346 | * Omitting this keyword has the same behavior as an empty schema.
|
347 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.9
|
348 | */
|
349 | items?: JSONSchema6Definition | JSONSchema6Definition[] | undefined;
|
350 |
|
351 | /**
|
352 | * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.
|
353 | * If "items" is an array of schemas, validation succeeds if every instance element
|
354 | * at a position greater than the size of "items" validates against "additionalItems".
|
355 | * Otherwise, "additionalItems" MUST be ignored, as the "items" schema
|
356 | * (possibly the default value of an empty schema) is applied to all elements.
|
357 | * Omitting this keyword has the same behavior as an empty schema.
|
358 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.10
|
359 | */
|
360 | additionalItems?: JSONSchema6Definition | undefined;
|
361 |
|
362 | /**
|
363 | * Must be a non-negative integer.
|
364 | * An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.
|
365 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.11
|
366 | */
|
367 | maxItems?: number | undefined;
|
368 |
|
369 | /**
|
370 | * Must be a non-negative integer.
|
371 | * An array instance is valid against "maxItems" if its size is greater than, or equal to, the value of this keyword.
|
372 | * Omitting this keyword has the same behavior as a value of 0.
|
373 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.12
|
374 | */
|
375 | minItems?: number | undefined;
|
376 |
|
377 | /**
|
378 | * If this keyword has boolean value false, the instance validates successfully.
|
379 | * If it has boolean value true, the instance validates successfully if all of its elements are unique.
|
380 | * Omitting this keyword has the same behavior as a value of false.
|
381 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.13
|
382 | */
|
383 | uniqueItems?: boolean | undefined;
|
384 |
|
385 | /**
|
386 | * An array instance is valid against "contains" if at least one of its elements is valid against the given schema.
|
387 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.14
|
388 | */
|
389 | contains?: JSONSchema6Definition | undefined;
|
390 |
|
391 | /**
|
392 | * Must be a non-negative integer.
|
393 | * An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
|
394 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.15
|
395 | */
|
396 | maxProperties?: number | undefined;
|
397 |
|
398 | /**
|
399 | * Must be a non-negative integer.
|
400 | * An object instance is valid against "maxProperties" if its number of properties is greater than,
|
401 | * or equal to, the value of this keyword.
|
402 | * Omitting this keyword has the same behavior as a value of 0.
|
403 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.16
|
404 | */
|
405 | minProperties?: number | undefined;
|
406 |
|
407 | /**
|
408 | * Elements of this array must be unique.
|
409 | * An object instance is valid against this keyword if every item in the array is the name of a property in the instance.
|
410 | * Omitting this keyword has the same behavior as an empty array.
|
411 | *
|
412 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.17
|
413 | */
|
414 | required?: string[] | undefined;
|
415 |
|
416 | /**
|
417 | * This keyword determines how child instances validate for objects, and does not directly validate the immediate instance itself.
|
418 | * Validation succeeds if, for each name that appears in both the instance and as a name within this keyword's value,
|
419 | * the child instance for that name successfully validates against the corresponding schema.
|
420 | * Omitting this keyword has the same behavior as an empty object.
|
421 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.18
|
422 | */
|
423 | properties?: {
|
424 | [k: string]: JSONSchema6Definition;
|
425 | } | undefined;
|
426 |
|
427 | /**
|
428 | * This attribute is an object that defines the schema for a set of property names of an object instance.
|
429 | * The name of each property of this attribute's object is a regular expression pattern in the ECMA 262, while the value is a schema.
|
430 | * If the pattern matches the name of a property on the instance object, the value of the instance's property
|
431 | * MUST be valid against the pattern name's schema value.
|
432 | * Omitting this keyword has the same behavior as an empty object.
|
433 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.19
|
434 | */
|
435 | patternProperties?: {
|
436 | [k: string]: JSONSchema6Definition;
|
437 | } | undefined;
|
438 |
|
439 | /**
|
440 | * This attribute defines a schema for all properties that are not explicitly defined in an object type definition.
|
441 | * If specified, the value MUST be a schema or a boolean.
|
442 | * If false is provided, no additional properties are allowed beyond the properties defined in the schema.
|
443 | * The default value is an empty schema which allows any value for additional properties.
|
444 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.20
|
445 | */
|
446 | additionalProperties?: JSONSchema6Definition | undefined;
|
447 |
|
448 | /**
|
449 | * This keyword specifies rules that are evaluated if the instance is an object and contains a certain property.
|
450 | * Each property specifies a dependency.
|
451 | * If the dependency value is an array, each element in the array must be unique.
|
452 | * Omitting this keyword has the same behavior as an empty object.
|
453 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.21
|
454 | */
|
455 | dependencies?: {
|
456 | [k: string]: JSONSchema6Definition | string[];
|
457 | } | undefined;
|
458 |
|
459 | /**
|
460 | * Takes a schema which validates the names of all properties rather than their values.
|
461 | * Note the property name that the schema is testing will always be a string.
|
462 | * Omitting this keyword has the same behavior as an empty schema.
|
463 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.22
|
464 | */
|
465 | propertyNames?: JSONSchema6Definition | undefined;
|
466 |
|
467 | /**
|
468 | * This provides an enumeration of all possible values that are valid
|
469 | * for the instance property. This MUST be an array, and each item in
|
470 | * the array represents a possible value for the instance value. If
|
471 | * this attribute is defined, the instance value MUST be one of the
|
472 | * values in the array in order for the schema to be valid.
|
473 | *
|
474 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.23
|
475 | */
|
476 | enum?: JSONSchema6Type[] | undefined;
|
477 |
|
478 | /**
|
479 | * More readable form of a one-element "enum"
|
480 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.24
|
481 | */
|
482 | const?: JSONSchema6Type | undefined;
|
483 |
|
484 | /**
|
485 | * A single type, or a union of simple types
|
486 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.25
|
487 | */
|
488 | type?: JSONSchema6TypeName | JSONSchema6TypeName[] | undefined;
|
489 |
|
490 | /**
|
491 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
|
492 | */
|
493 | allOf?: JSONSchema6Definition[] | undefined;
|
494 |
|
495 | /**
|
496 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27
|
497 | */
|
498 | anyOf?: JSONSchema6Definition[] | undefined;
|
499 |
|
500 | /**
|
501 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28
|
502 | */
|
503 | oneOf?: JSONSchema6Definition[] | undefined;
|
504 |
|
505 | /**
|
506 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.29
|
507 | */
|
508 | not?: JSONSchema6Definition | undefined;
|
509 |
|
510 | /**
|
511 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.1
|
512 | */
|
513 | definitions?: {
|
514 | [k: string]: JSONSchema6Definition;
|
515 | } | undefined;
|
516 |
|
517 | /**
|
518 | * This attribute is a string that provides a short description of the instance property.
|
519 | *
|
520 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.2
|
521 | */
|
522 | title?: string | undefined;
|
523 |
|
524 | /**
|
525 | * This attribute is a string that provides a full description of the of purpose the instance property.
|
526 | *
|
527 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.2
|
528 | */
|
529 | description?: string | undefined;
|
530 |
|
531 | /**
|
532 | * This keyword can be used to supply a default JSON value associated with a particular schema.
|
533 | * It is RECOMMENDED that a default value be valid against the associated schema.
|
534 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.3
|
535 | */
|
536 | default?: JSONSchema6Type | undefined;
|
537 |
|
538 | /**
|
539 | * Array of examples with no validation effect the value of "default" is usable as an example without repeating it under this keyword
|
540 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.4
|
541 | */
|
542 | examples?: JSONSchema6Type[] | undefined;
|
543 |
|
544 | /**
|
545 | * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-8
|
546 | */
|
547 | format?: string | undefined;
|
548 | }
|
549 |
|
550 | // ==================================================================================================
|
551 | // JSON Schema Draft 07
|
552 | // ==================================================================================================
|
553 | // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
554 | // --------------------------------------------------------------------------------------------------
|
555 |
|
556 | /**
|
557 | * Primitive type
|
558 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
559 | */
|
560 | export type JSONSchema7TypeName =
|
561 | | "string" //
|
562 | | "number"
|
563 | | "integer"
|
564 | | "boolean"
|
565 | | "object"
|
566 | | "array"
|
567 | | "null";
|
568 |
|
569 | /**
|
570 | * Primitive type
|
571 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
572 | */
|
573 | export type JSONSchema7Type =
|
574 | | string //
|
575 | | number
|
576 | | boolean
|
577 | | JSONSchema7Object
|
578 | | JSONSchema7Array
|
579 | | null;
|
580 |
|
581 | // Workaround for infinite type recursion
|
582 | export interface JSONSchema7Object {
|
583 | [key: string]: JSONSchema7Type;
|
584 | }
|
585 |
|
586 | // Workaround for infinite type recursion
|
587 | // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
588 | export interface JSONSchema7Array extends Array<JSONSchema7Type> {}
|
589 |
|
590 | /**
|
591 | * Meta schema
|
592 | *
|
593 | * Recommended values:
|
594 | * - 'http://json-schema.org/schema#'
|
595 | * - 'http://json-schema.org/hyper-schema#'
|
596 | * - 'http://json-schema.org/draft-07/schema#'
|
597 | * - 'http://json-schema.org/draft-07/hyper-schema#'
|
598 | *
|
599 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
600 | */
|
601 | export type JSONSchema7Version = string;
|
602 |
|
603 | /**
|
604 | * JSON Schema v7
|
605 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
606 | */
|
607 | export type JSONSchema7Definition = JSONSchema7 | boolean;
|
608 | export interface JSONSchema7 {
|
609 | $id?: string | undefined;
|
610 | $ref?: string | undefined;
|
611 | $schema?: JSONSchema7Version | undefined;
|
612 | $comment?: string | undefined;
|
613 |
|
614 | /**
|
615 | * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
|
616 | * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
|
617 | */
|
618 | $defs?: {
|
619 | [key: string]: JSONSchema7Definition;
|
620 | } | undefined;
|
621 |
|
622 | /**
|
623 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
|
624 | */
|
625 | type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
626 | enum?: JSONSchema7Type[] | undefined;
|
627 | const?: JSONSchema7Type | undefined;
|
628 |
|
629 | /**
|
630 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
|
631 | */
|
632 | multipleOf?: number | undefined;
|
633 | maximum?: number | undefined;
|
634 | exclusiveMaximum?: number | undefined;
|
635 | minimum?: number | undefined;
|
636 | exclusiveMinimum?: number | undefined;
|
637 |
|
638 | /**
|
639 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
|
640 | */
|
641 | maxLength?: number | undefined;
|
642 | minLength?: number | undefined;
|
643 | pattern?: string | undefined;
|
644 |
|
645 | /**
|
646 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
|
647 | */
|
648 | items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
649 | additionalItems?: JSONSchema7Definition | undefined;
|
650 | maxItems?: number | undefined;
|
651 | minItems?: number | undefined;
|
652 | uniqueItems?: boolean | undefined;
|
653 | contains?: JSONSchema7Definition | undefined;
|
654 |
|
655 | /**
|
656 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
|
657 | */
|
658 | maxProperties?: number | undefined;
|
659 | minProperties?: number | undefined;
|
660 | required?: string[] | undefined;
|
661 | properties?: {
|
662 | [key: string]: JSONSchema7Definition;
|
663 | } | undefined;
|
664 | patternProperties?: {
|
665 | [key: string]: JSONSchema7Definition;
|
666 | } | undefined;
|
667 | additionalProperties?: JSONSchema7Definition | undefined;
|
668 | dependencies?: {
|
669 | [key: string]: JSONSchema7Definition | string[];
|
670 | } | undefined;
|
671 | propertyNames?: JSONSchema7Definition | undefined;
|
672 |
|
673 | /**
|
674 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
|
675 | */
|
676 | if?: JSONSchema7Definition | undefined;
|
677 | then?: JSONSchema7Definition | undefined;
|
678 | else?: JSONSchema7Definition | undefined;
|
679 |
|
680 | /**
|
681 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
|
682 | */
|
683 | allOf?: JSONSchema7Definition[] | undefined;
|
684 | anyOf?: JSONSchema7Definition[] | undefined;
|
685 | oneOf?: JSONSchema7Definition[] | undefined;
|
686 | not?: JSONSchema7Definition | undefined;
|
687 |
|
688 | /**
|
689 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
|
690 | */
|
691 | format?: string | undefined;
|
692 |
|
693 | /**
|
694 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
|
695 | */
|
696 | contentMediaType?: string | undefined;
|
697 | contentEncoding?: string | undefined;
|
698 |
|
699 | /**
|
700 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
|
701 | */
|
702 | definitions?: {
|
703 | [key: string]: JSONSchema7Definition;
|
704 | } | undefined;
|
705 |
|
706 | /**
|
707 | * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
708 | */
|
709 | title?: string | undefined;
|
710 | description?: string | undefined;
|
711 | default?: JSONSchema7Type | undefined;
|
712 | readOnly?: boolean | undefined;
|
713 | writeOnly?: boolean | undefined;
|
714 | examples?: JSONSchema7Type | undefined;
|
715 | }
|
716 |
|
717 | export interface ValidationResult {
|
718 | valid: boolean;
|
719 | errors: ValidationError[];
|
720 | }
|
721 |
|
722 | export interface ValidationError {
|
723 | property: string;
|
724 | message: string;
|
725 | }
|
726 |
|
727 | /**
|
728 | * To use the validator call JSONSchema.validate with an instance object and an optional schema object.
|
729 | * If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
|
730 | * that schema will be used to validate and the schema parameter is not necessary (if both exist,
|
731 | * both validations will occur).
|
732 | */
|
733 | export function validate(instance: {}, schema: JSONSchema4 | JSONSchema6 | JSONSchema7): ValidationResult;
|
734 |
|
735 | /**
|
736 | * The checkPropertyChange method will check to see if an value can legally be in property with the given schema
|
737 | * This is slightly different than the validate method in that it will fail if the schema is readonly and it will
|
738 | * not check for self-validation, it is assumed that the passed in value is already internally valid.
|
739 | */
|
740 | export function checkPropertyChange(
|
741 | value: any,
|
742 | schema: JSONSchema4 | JSONSchema6 | JSONSchema7,
|
743 | property: string,
|
744 | ): ValidationResult;
|
745 |
|
746 | /**
|
747 | * This checks to ensure that the result is valid and will throw an appropriate error message if it is not.
|
748 | */
|
749 | export function mustBeValid(result: ValidationResult): void;
|