UNPKG

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