@@ -4,6 +4,10 @@ module Draft202012
4
4
module Vocab
5
5
module Applicator
6
6
class AllOf < Keyword
7
+ def error ( formatted_instance_location :, **)
8
+ "value at #{ formatted_instance_location } does not match all `allOf` schemas"
9
+ end
10
+
7
11
def parse
8
12
value . map . with_index do |subschema , index |
9
13
subschema ( subschema , index . to_s )
@@ -19,6 +23,10 @@ def validate(instance, instance_location, keyword_location, context)
19
23
end
20
24
21
25
class AnyOf < Keyword
26
+ def error ( formatted_instance_location :, **)
27
+ "value at #{ formatted_instance_location } does not match any `anyOf` schemas"
28
+ end
29
+
22
30
def parse
23
31
value . map . with_index do |subschema , index |
24
32
subschema ( subschema , index . to_s )
@@ -34,6 +42,10 @@ def validate(instance, instance_location, keyword_location, context)
34
42
end
35
43
36
44
class OneOf < Keyword
45
+ def error ( formatted_instance_location :, **)
46
+ "value at #{ formatted_instance_location } does not match exactly one `oneOf` schema"
47
+ end
48
+
37
49
def parse
38
50
value . map . with_index do |subschema , index |
39
51
subschema ( subschema , index . to_s )
@@ -50,6 +62,10 @@ def validate(instance, instance_location, keyword_location, context)
50
62
end
51
63
52
64
class Not < Keyword
65
+ def error ( formatted_instance_location :, **)
66
+ "value at #{ formatted_instance_location } matches `not` schema"
67
+ end
68
+
53
69
def parse
54
70
subschema ( value )
55
71
end
@@ -72,28 +88,42 @@ def validate(instance, instance_location, keyword_location, context)
72
88
end
73
89
74
90
class Then < Keyword
91
+ def error ( formatted_instance_location :, **)
92
+ "value at #{ formatted_instance_location } does not match conditional `then` schema"
93
+ end
94
+
75
95
def parse
76
96
subschema ( value )
77
97
end
78
98
79
99
def validate ( instance , instance_location , keyword_location , context )
80
100
return unless context . adjacent_results . key? ( If ) && context . adjacent_results . fetch ( If ) . annotation
81
- parsed . validate_instance ( instance , instance_location , keyword_location , context )
101
+ subschema_result = parsed . validate_instance ( instance , instance_location , keyword_location , context )
102
+ result ( instance , instance_location , keyword_location , subschema_result . valid , subschema_result . nested )
82
103
end
83
104
end
84
105
85
106
class Else < Keyword
107
+ def error ( formatted_instance_location :, **)
108
+ "value at #{ formatted_instance_location } does not match conditional `else` schema"
109
+ end
110
+
86
111
def parse
87
112
subschema ( value )
88
113
end
89
114
90
115
def validate ( instance , instance_location , keyword_location , context )
91
116
return unless context . adjacent_results . key? ( If ) && !context . adjacent_results . fetch ( If ) . annotation
92
- parsed . validate_instance ( instance , instance_location , keyword_location , context )
117
+ subschema_result = parsed . validate_instance ( instance , instance_location , keyword_location , context )
118
+ result ( instance , instance_location , keyword_location , subschema_result . valid , subschema_result . nested )
93
119
end
94
120
end
95
121
96
122
class DependentSchemas < Keyword
123
+ def error ( formatted_instance_location :, **)
124
+ "value at #{ formatted_instance_location } does not match applicable `dependentSchemas` schemas"
125
+ end
126
+
97
127
def parse
98
128
value . each_with_object ( { } ) do |( key , subschema ) , out |
99
129
out [ key ] = subschema ( subschema , key )
@@ -114,6 +144,10 @@ def validate(instance, instance_location, keyword_location, context)
114
144
end
115
145
116
146
class PrefixItems < Keyword
147
+ def error ( formatted_instance_location :, **)
148
+ "array items at #{ formatted_instance_location } do not match corresponding `prefixItems` schemas"
149
+ end
150
+
117
151
def parse
118
152
value . map . with_index do |subschema , index |
119
153
subschema ( subschema , index . to_s )
@@ -132,6 +166,10 @@ def validate(instance, instance_location, keyword_location, context)
132
166
end
133
167
134
168
class Items < Keyword
169
+ def error ( formatted_instance_location :, **)
170
+ "array items at #{ formatted_instance_location } do not match `items` schema"
171
+ end
172
+
135
173
def parse
136
174
subschema ( value )
137
175
end
@@ -151,6 +189,10 @@ def validate(instance, instance_location, keyword_location, context)
151
189
end
152
190
153
191
class Contains < Keyword
192
+ def error ( formatted_instance_location :, **)
193
+ "array at #{ formatted_instance_location } does not contain enough items that match `contains` schema"
194
+ end
195
+
154
196
def parse
155
197
subschema ( value )
156
198
end
@@ -174,6 +216,10 @@ def validate(instance, instance_location, keyword_location, context)
174
216
end
175
217
176
218
class Properties < Keyword
219
+ def error ( formatted_instance_location :, **)
220
+ "object properties at #{ formatted_instance_location } do not match corresponding `properties` schemas"
221
+ end
222
+
177
223
def parse
178
224
value . each_with_object ( { } ) do |( property , subschema ) , out |
179
225
out [ property ] = subschema ( subschema , property )
@@ -214,6 +260,10 @@ def validate(instance, instance_location, keyword_location, context)
214
260
end
215
261
216
262
class PatternProperties < Keyword
263
+ def error ( formatted_instance_location :, **)
264
+ "object properties at #{ formatted_instance_location } do not match corresponding `patternProperties` schemas"
265
+ end
266
+
217
267
def parse
218
268
value . each_with_object ( { } ) do |( pattern , subschema ) , out |
219
269
out [ pattern ] = subschema ( subschema , pattern )
@@ -241,6 +291,14 @@ def validate(instance, instance_location, keyword_location, context)
241
291
end
242
292
243
293
class AdditionalProperties < Keyword
294
+ def error ( formatted_instance_location :, **)
295
+ "object properties at #{ formatted_instance_location } do not match `additionalProperties` schema"
296
+ end
297
+
298
+ def false_schema_error ( formatted_instance_location :, **)
299
+ "object property at #{ formatted_instance_location } is not defined and schema does not allow additional properties"
300
+ end
301
+
244
302
def parse
245
303
subschema ( value )
246
304
end
@@ -265,6 +323,10 @@ def validate(instance, instance_location, keyword_location, context)
265
323
end
266
324
267
325
class PropertyNames < Keyword
326
+ def error ( formatted_instance_location :, **)
327
+ "object property names at #{ formatted_instance_location } do not match `propertyNames` schema"
328
+ end
329
+
268
330
def parse
269
331
subschema ( value )
270
332
end
@@ -281,6 +343,10 @@ def validate(instance, instance_location, keyword_location, context)
281
343
end
282
344
283
345
class Dependencies < Keyword
346
+ def error ( formatted_instance_location :, **)
347
+ "object at #{ formatted_instance_location } either does not match applicable `dependencies` schemas or is missing required `dependencies` properties"
348
+ end
349
+
284
350
def parse
285
351
value . each_with_object ( { } ) do |( key , value ) , out |
286
352
out [ key ] = value . is_a? ( Array ) ? value : subschema ( value , key )
0 commit comments