-
Notifications
You must be signed in to change notification settings - Fork 2
/
JsonSchema.ts
133 lines (123 loc) · 4.23 KB
/
JsonSchema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* JSON Schema is ultimately a nested definition system. The root should always contain the $schema property,
* but further definitions (typically stored on the object in the 'definitions' key of the root) can simply be
* something like:
* {
* "type": "string"
* }
*/
export interface JsonSchema {
$ref?: string;
///////////////////////////////////////////////////////////////////////////
// Schema Metadata
///////////////////////////////////////////////////////////////////////////
/**
* This is important because it tells refs where the root of the document is located
*/
id?: string;
/**
* It is recommended that the meta-schema is included in the root of any json schema and must be a uri
*/
$schema?: string;
/**
* Title of the schema
*/
title?: string;
/**
* Schema description
*/
description?: string;
/**
* Default json for the object represented by this schema
*/
'default'?: any;
///////////////////////////////////////////////////////////////////////////
// Number Validation
///////////////////////////////////////////////////////////////////////////
/**
* The value must be a multiple of the number (e.g. 10 is a multiple of 5)
*/
multipleOf?: number;
maximum?: number;
/**
* If true maximum must be > value, >= otherwise
*/
exclusiveMaximum?: boolean;
minimum?: number;
/**
* If true minimum must be < value, <= otherwise
*/
exclusiveMinimum?: boolean;
///////////////////////////////////////////////////////////////////////////
// String Validation
///////////////////////////////////////////////////////////////////////////
maxLength?: number;
minLength?: number;
/**
* This is a regex string that the value must conform to
*/
pattern?: string;
///////////////////////////////////////////////////////////////////////////
// Array Validation
///////////////////////////////////////////////////////////////////////////
additionalItems?: boolean | JsonSchema;
items?: JsonSchema | JsonSchema[];
maxItems?: number;
minItems?: number;
uniqueItems?: boolean;
///////////////////////////////////////////////////////////////////////////
// Object Validation
///////////////////////////////////////////////////////////////////////////
maxProperties?: number;
minProperties?: number;
required?: string[];
additionalProperties?: boolean | JsonSchema;
/**
* Holds simple JSON Schema definitions for referencing from elsewhere
*/
definitions?: { [key: string]: JsonSchema };
/**
* The keys that can exist on the object with the json schema that should validate their value
*/
properties?: { [property: string]: JsonSchema };
/**
* The key of this object is a regex for which properties the schema applies to
*/
patternProperties?: { [pattern: string]: JsonSchema };
/**
* If the key is present as a property then the string of properties must also be present.
* If the value is a JSON Schema then it must also be valid for the object if the key is present.
*/
dependencies?: { [key: string]: JsonSchema | string[] };
///////////////////////////////////////////////////////////////////////////
// Generic
///////////////////////////////////////////////////////////////////////////
/**
* Enumerates the values that this schema can be (e.g. {"type": "string", "enum": ["red", "green", "blue"]})
*/
'enum'?: any[];
/**
* The basic type of this schema, can be one of [string, number, object, array, boolean, null] or an array of
* the acceptable types
*/
type?: string | string[];
format?: string;
///////////////////////////////////////////////////////////////////////////
// Combining Schemas
///////////////////////////////////////////////////////////////////////////
allOf?: JsonSchema[];
anyOf?: JsonSchema[];
oneOf?: JsonSchema[];
/**
* The entity being validated must not match this schema
*/
not?: JsonSchema;
///////////////////////////////////////////////////////////////////////////
// Hyperfish Specific
///////////////////////////////////////////////////////////////////////////
viewProperties?: string[];
component?: string;
valueSource?: string;
identifiers?: string[];
links?: (JsonSchema & { rel: string, href: string })[];
}