@hyperjump/json-schema 1.3.1 → 1.4.0

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.
Files changed (38) hide show
  1. package/README.md +116 -5
  2. package/annotations/annotated-instance.d.ts +83 -0
  3. package/annotations/annotated-instance.js +50 -0
  4. package/annotations/index.d.ts +11 -0
  5. package/annotations/index.js +123 -0
  6. package/annotations/tests/applicators.json +375 -0
  7. package/annotations/tests/content.json +60 -0
  8. package/annotations/tests/core.json +33 -0
  9. package/annotations/tests/format.json +21 -0
  10. package/annotations/tests/meta-data.json +135 -0
  11. package/annotations/tests/unevaluated.json +557 -0
  12. package/annotations/tests/unknown.json +91 -0
  13. package/annotations/tests/validation.json +328 -0
  14. package/annotations/validation-error.d.ts +8 -0
  15. package/annotations/validation-error.js +7 -0
  16. package/bundle/index.js +2 -3
  17. package/lib/keywords/additionalProperties.js +19 -4
  18. package/lib/keywords/allOf.js +2 -2
  19. package/lib/keywords/anyOf.js +2 -2
  20. package/lib/keywords/contains.js +14 -14
  21. package/lib/keywords/contentSchema.js +7 -2
  22. package/lib/keywords/dependentSchemas.js +18 -8
  23. package/lib/keywords/dynamicRef.js +2 -2
  24. package/lib/keywords/else.js +12 -19
  25. package/lib/keywords/if.js +2 -2
  26. package/lib/keywords/items.js +3 -3
  27. package/lib/keywords/not.js +1 -1
  28. package/lib/keywords/oneOf.js +2 -2
  29. package/lib/keywords/patternProperties.js +20 -3
  30. package/lib/keywords/prefixItems.js +3 -3
  31. package/lib/keywords/properties.js +18 -6
  32. package/lib/keywords/propertyDependencies.js +2 -2
  33. package/lib/keywords/propertyNames.js +1 -1
  34. package/lib/keywords/then.js +12 -19
  35. package/lib/keywords/unevaluatedItems.js +2 -2
  36. package/lib/keywords/unevaluatedProperties.js +25 -5
  37. package/lib/keywords/validation.js +43 -53
  38. package/package.json +4 -2
@@ -0,0 +1,375 @@
1
+ [
2
+ {
3
+ "title": "`properties`, `patternProperties`, and `additionalProperties`",
4
+ "schema": {
5
+ "properties": {
6
+ "foo": { "title": "Foo" }
7
+ },
8
+ "patternProperties": {
9
+ "^a": { "title": "Bar" }
10
+ },
11
+ "additionalProperties": { "title": "Baz" }
12
+ },
13
+ "subjects": [
14
+ {
15
+ "instance": {},
16
+ "assertions": [
17
+ {
18
+ "location": "#/foo",
19
+ "keyword": "title",
20
+ "expected": []
21
+ },
22
+ {
23
+ "location": "#/apple",
24
+ "keyword": "title",
25
+ "expected": []
26
+ },
27
+ {
28
+ "location": "#/bar",
29
+ "keyword": "title",
30
+ "expected": []
31
+ }
32
+ ]
33
+ },
34
+ {
35
+ "instance": {
36
+ "foo": {},
37
+ "apple": {},
38
+ "baz": {}
39
+ },
40
+ "assertions": [
41
+ {
42
+ "location": "#/foo",
43
+ "keyword": "title",
44
+ "expected": ["Foo"]
45
+ },
46
+ {
47
+ "location": "#/apple",
48
+ "keyword": "title",
49
+ "expected": ["Bar"]
50
+ },
51
+ {
52
+ "location": "#/baz",
53
+ "keyword": "title",
54
+ "expected": ["Baz"]
55
+ }
56
+ ]
57
+ }
58
+ ]
59
+ },
60
+ {
61
+ "title": "`propertyNames`",
62
+ "schema": {
63
+ "propertyNames": {
64
+ "const": "foo",
65
+ "title": "Foo"
66
+ }
67
+ },
68
+ "subjects": [
69
+ {
70
+ "instance": { "foo": 42 },
71
+ "assertions": [
72
+ {
73
+ "location": "#",
74
+ "keyword": "propertyNames",
75
+ "expected": []
76
+ },
77
+ {
78
+ "location": "#/foo",
79
+ "keyword": "title",
80
+ "expected": []
81
+ }
82
+ ]
83
+ }
84
+ ]
85
+ },
86
+ {
87
+ "title": "`prefixItems` and `items`",
88
+ "schema": {
89
+ "prefixItems": [{ "title": "Foo" }],
90
+ "items": { "title": "Bar" }
91
+ },
92
+ "subjects": [
93
+ {
94
+ "instance": ["foo", "bar"],
95
+ "assertions": [
96
+ {
97
+ "location": "#/0",
98
+ "keyword": "title",
99
+ "expected": ["Foo"]
100
+ },
101
+ {
102
+ "location": "#/1",
103
+ "keyword": "title",
104
+ "expected": ["Bar"]
105
+ },
106
+ {
107
+ "location": "#/2",
108
+ "keyword": "title",
109
+ "expected": []
110
+ }
111
+ ]
112
+ }
113
+ ]
114
+ },
115
+ {
116
+ "title": "`contains`",
117
+ "schema": {
118
+ "contains": {
119
+ "type": "number",
120
+ "title": "Foo"
121
+ }
122
+ },
123
+ "subjects": [
124
+ {
125
+ "instance": ["foo", 42, true],
126
+ "assertions": [
127
+ {
128
+ "location": "#/0",
129
+ "keyword": "title",
130
+ "expected": []
131
+ },
132
+ {
133
+ "location": "#/1",
134
+ "keyword": "title",
135
+ "expected": ["Foo"]
136
+ },
137
+ {
138
+ "location": "#/2",
139
+ "keyword": "title",
140
+ "expected": []
141
+ },
142
+ {
143
+ "location": "#/3",
144
+ "keyword": "title",
145
+ "expected": []
146
+ }
147
+ ]
148
+ }
149
+ ]
150
+ },
151
+ {
152
+ "title": "`allOf`",
153
+ "schema": {
154
+ "allOf": [
155
+ { "title": "Foo" },
156
+ { "title": "Bar" }
157
+ ]
158
+ },
159
+ "subjects": [
160
+ {
161
+ "instance": "foo",
162
+ "assertions": [
163
+ {
164
+ "location": "#",
165
+ "keyword": "allOf",
166
+ "expected": []
167
+ },
168
+ {
169
+ "location": "#",
170
+ "keyword": "title",
171
+ "expected": ["Bar", "Foo"]
172
+ }
173
+ ]
174
+ }
175
+ ]
176
+ },
177
+ {
178
+ "title": "`anyOf`",
179
+ "schema": {
180
+ "anyOf": [
181
+ {
182
+ "type": "integer",
183
+ "title": "Foo"
184
+ },
185
+ {
186
+ "type": "number",
187
+ "title": "Bar"
188
+ }
189
+ ]
190
+ },
191
+ "subjects": [
192
+ {
193
+ "instance": 42,
194
+ "assertions": [
195
+ {
196
+ "location": "#",
197
+ "keyword": "anyOf",
198
+ "expected": []
199
+ },
200
+ {
201
+ "location": "#",
202
+ "keyword": "title",
203
+ "expected": ["Bar", "Foo"]
204
+ }
205
+ ]
206
+ },
207
+ {
208
+ "instance": 4.2,
209
+ "assertions": [
210
+ {
211
+ "location": "#",
212
+ "keyword": "title",
213
+ "expected": ["Bar"]
214
+ }
215
+ ]
216
+ }
217
+ ]
218
+ },
219
+ {
220
+ "title": "`oneOf`",
221
+ "schema": {
222
+ "oneOf": [
223
+ {
224
+ "type": "string",
225
+ "title": "Foo"
226
+ },
227
+ {
228
+ "type": "number",
229
+ "title": "Bar"
230
+ }
231
+ ]
232
+ },
233
+ "subjects": [
234
+ {
235
+ "instance": "foo",
236
+ "assertions": [
237
+ {
238
+ "location": "#",
239
+ "keyword": "oneOf",
240
+ "expected": []
241
+ },
242
+ {
243
+ "location": "#",
244
+ "keyword": "title",
245
+ "expected": ["Foo"]
246
+ }
247
+ ]
248
+ },
249
+ {
250
+ "instance": 42,
251
+ "assertions": [
252
+ {
253
+ "location": "#",
254
+ "keyword": "title",
255
+ "expected": ["Bar"]
256
+ }
257
+ ]
258
+ }
259
+ ]
260
+ },
261
+ {
262
+ "title": "`not`",
263
+ "schema": {
264
+ "title": "Foo",
265
+ "not": {
266
+ "not": { "title": "Bar" }
267
+ }
268
+ },
269
+ "subjects": [
270
+ {
271
+ "instance": {},
272
+ "assertions": [
273
+ {
274
+ "location": "#",
275
+ "keyword": "not",
276
+ "expected": []
277
+ },
278
+ {
279
+ "location": "#",
280
+ "keyword": "title",
281
+ "expected": ["Foo"]
282
+ }
283
+ ]
284
+ }
285
+ ]
286
+ },
287
+ {
288
+ "title": "`dependentSchemas`",
289
+ "schema": {
290
+ "dependentSchemas": {
291
+ "foo": { "title": "Foo" }
292
+ }
293
+ },
294
+ "subjects": [
295
+ {
296
+ "instance": { "foo": 42 },
297
+ "assertions": [
298
+ {
299
+ "keyword": "dependentSchemas",
300
+ "location": "#",
301
+ "expected": []
302
+ },
303
+ {
304
+ "keyword": "title",
305
+ "location": "#",
306
+ "expected": ["Foo"]
307
+ }
308
+ ]
309
+ },
310
+ {
311
+ "instance": { "foo": 42 },
312
+ "assertions": [
313
+ {
314
+ "keyword": "title",
315
+ "location": "#/foo",
316
+ "expected": []
317
+ }
318
+ ]
319
+ }
320
+ ]
321
+ },
322
+ {
323
+ "title": "`if`, `then`, and `else`",
324
+ "schema": {
325
+ "if": {
326
+ "title": "If",
327
+ "type": "string"
328
+ },
329
+ "then": { "title": "Then" },
330
+ "else": { "title": "Else" }
331
+ },
332
+ "subjects": [
333
+ {
334
+ "instance": "foo",
335
+ "assertions": [
336
+ {
337
+ "location": "#",
338
+ "keyword": "if",
339
+ "expected": []
340
+ },
341
+ {
342
+ "location": "#",
343
+ "keyword": "then",
344
+ "expected": []
345
+ },
346
+ {
347
+ "location": "#",
348
+ "keyword": "title",
349
+ "expected": ["Then", "If"]
350
+ }
351
+ ]
352
+ },
353
+ {
354
+ "instance": 42,
355
+ "assertions": [
356
+ {
357
+ "location": "#",
358
+ "keyword": "if",
359
+ "expected": []
360
+ },
361
+ {
362
+ "location": "#",
363
+ "keyword": "else",
364
+ "expected": []
365
+ },
366
+ {
367
+ "location": "#",
368
+ "keyword": "title",
369
+ "expected": ["Else", "If"]
370
+ }
371
+ ]
372
+ }
373
+ ]
374
+ }
375
+ ]
@@ -0,0 +1,60 @@
1
+ [
2
+ {
3
+ "title": "`contentMediaType` is an annotation",
4
+ "schema": {
5
+ "contentMediaType": "application/json"
6
+ },
7
+ "subjects": [
8
+ {
9
+ "title": "String",
10
+ "instance": "{ \"foo\": \"bar\" }",
11
+ "assertions": [
12
+ {
13
+ "location": "#",
14
+ "keyword": "contentMediaType",
15
+ "expected": ["application/json"]
16
+ }
17
+ ]
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "title": "`contentEncoding` is an annotation",
23
+ "schema": {
24
+ "contentEncoding": "base64"
25
+ },
26
+ "subjects": [
27
+ {
28
+ "title": "Any instance",
29
+ "instance": "SGVsbG8gZnJvbSBKU09OIFNjaGVtYQ==",
30
+ "assertions": [
31
+ {
32
+ "location": "#",
33
+ "keyword": "contentEncoding",
34
+ "expected": ["base64"]
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ },
40
+ {
41
+ "title": "`contentSchema` is an annotation",
42
+ "schema": {
43
+ "$id": "https://annotations.json-schema.org/test/contentSchema-is-an-annotation",
44
+ "contentSchema": { "type": "number" }
45
+ },
46
+ "subjects": [
47
+ {
48
+ "title": "String",
49
+ "instance": "42",
50
+ "assertions": [
51
+ {
52
+ "location": "#",
53
+ "keyword": "contentSchema",
54
+ "expected": ["https://annotations.json-schema.org/test/contentSchema-is-an-annotation#/contentSchema"]
55
+ }
56
+ ]
57
+ }
58
+ ]
59
+ }
60
+ ]
@@ -0,0 +1,33 @@
1
+ [
2
+ {
3
+ "title": "`$ref` and `$defs`",
4
+ "schema": {
5
+ "$ref": "#/$defs/foo",
6
+ "$defs": {
7
+ "foo": { "title": "Foo" }
8
+ }
9
+ },
10
+ "subjects": [
11
+ {
12
+ "instance": "foo",
13
+ "assertions": [
14
+ {
15
+ "location": "#",
16
+ "keyword": "$ref",
17
+ "expected": []
18
+ },
19
+ {
20
+ "location": "#",
21
+ "keyword": "$defs",
22
+ "expected": []
23
+ },
24
+ {
25
+ "location": "#",
26
+ "keyword": "title",
27
+ "expected": ["Foo"]
28
+ }
29
+ ]
30
+ }
31
+ ]
32
+ }
33
+ ]
@@ -0,0 +1,21 @@
1
+ [
2
+ {
3
+ "title": "`format` is an annotation",
4
+ "schema": {
5
+ "format": "email"
6
+ },
7
+ "subjects": [
8
+ {
9
+ "title": "String",
10
+ "instance": "foo@bar.com",
11
+ "assertions": [
12
+ {
13
+ "location": "#",
14
+ "keyword": "format",
15
+ "expected": ["email"]
16
+ }
17
+ ]
18
+ }
19
+ ]
20
+ }
21
+ ]
@@ -0,0 +1,135 @@
1
+ [
2
+ {
3
+ "title": "`title` is an annotation",
4
+ "schema": {
5
+ "title": "Foo"
6
+ },
7
+ "subjects": [
8
+ {
9
+ "title": "Any instance",
10
+ "instance": 42,
11
+ "assertions": [
12
+ {
13
+ "location": "#",
14
+ "keyword": "title",
15
+ "expected": ["Foo"]
16
+ }
17
+ ]
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "title": "`description` is an annotation",
23
+ "schema": {
24
+ "description": "Foo"
25
+ },
26
+ "subjects": [
27
+ {
28
+ "title": "Any instance",
29
+ "instance": 42,
30
+ "assertions": [
31
+ {
32
+ "location": "#",
33
+ "keyword": "description",
34
+ "expected": ["Foo"]
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ },
40
+ {
41
+ "title": "`default` is an annotation",
42
+ "schema": {
43
+ "default": "Foo"
44
+ },
45
+ "subjects": [
46
+ {
47
+ "title": "Any instance",
48
+ "instance": 42,
49
+ "assertions": [
50
+ {
51
+ "location": "#",
52
+ "keyword": "default",
53
+ "expected": ["Foo"]
54
+ }
55
+ ]
56
+ }
57
+ ]
58
+ },
59
+ {
60
+ "title": "`deprecated` is an annotation",
61
+ "schema": {
62
+ "deprecated": true
63
+ },
64
+ "subjects": [
65
+ {
66
+ "title": "Any instance",
67
+ "instance": 42,
68
+ "assertions": [
69
+ {
70
+ "location": "#",
71
+ "keyword": "deprecated",
72
+ "expected": [true]
73
+ }
74
+ ]
75
+ }
76
+ ]
77
+ },
78
+ {
79
+ "title": "`readOnly` is an annotation",
80
+ "schema": {
81
+ "readOnly": true
82
+ },
83
+ "subjects": [
84
+ {
85
+ "title": "Any instance",
86
+ "instance": 42,
87
+ "assertions": [
88
+ {
89
+ "location": "#",
90
+ "keyword": "readOnly",
91
+ "expected": [true]
92
+ }
93
+ ]
94
+ }
95
+ ]
96
+ },
97
+ {
98
+ "title": "`writeOnly` is an annotation",
99
+ "schema": {
100
+ "writeOnly": true
101
+ },
102
+ "subjects": [
103
+ {
104
+ "title": "Any instance",
105
+ "instance": 42,
106
+ "assertions": [
107
+ {
108
+ "location": "#",
109
+ "keyword": "writeOnly",
110
+ "expected": [true]
111
+ }
112
+ ]
113
+ }
114
+ ]
115
+ },
116
+ {
117
+ "title": "`examples` is an annotation",
118
+ "schema": {
119
+ "examples": ["Foo", "Bar"]
120
+ },
121
+ "subjects": [
122
+ {
123
+ "title": "Any instance",
124
+ "instance": "Foo",
125
+ "assertions": [
126
+ {
127
+ "location": "#",
128
+ "keyword": "examples",
129
+ "expected": [["Foo", "Bar"]]
130
+ }
131
+ ]
132
+ }
133
+ ]
134
+ }
135
+ ]