openc-json_schema 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +0 -2
- data/Gemfile.lock +4 -10
- data/lib/openc/json_schema/validator.rb +21 -15
- data/lib/openc/json_schema/version.rb +1 -1
- data/openc-json_schema.gemspec +1 -1
- data/spec/openc_json_schema_spec.rb +63 -108
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmI5ZTBkM2Q5MmNiNTc3M2QwNWRhZmU5ZDYzODA1MjBlOGEwYThhMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWQ5ZGM5ZDUxYmM3NmM4ZjE2MTJiNTMyNDZhMDkyZjcwYWFiOGI4ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWM1ZGVkNDkyYzU5NzI5Mjg0NjcxNDY2MmM0ZDM1OTY2YzM4NjM0NDQxOGVi
|
10
|
+
ZDNiYTlkNTE3NzI3NTM2M2M3MzMzMzY3ZTliYjhiNGVmZjBkZjc4NzI1Zjdk
|
11
|
+
YmVlOTEyYzZjYmI2N2ZjYTQzNDZlNzIxYzY4MjkwYWQwMjE4NTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGUxNDU0N2RmMWZmZDAyNmY0ZmUxNWNjZDg5OTdjMTI0ZmY4ZjMwN2I2NTI2
|
14
|
+
N2RjZmFjYWIxNDRjZDdkNDM1NTA5NDk4YjQ0NDRlNWVmNTU1MTQ4NGM2MWQ3
|
15
|
+
NGE5N2IwMGFhY2MzYWRkNTE0OTBkYjMyMzY2YjE3OWRlOTc5MzA=
|
data/Gemfile
CHANGED
@@ -3,6 +3,4 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in openc-json-schema.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem 'json-schema', :git => 'git://github.com/ruby-json-schema/json-schema.git', :ref => 'aded4d798a48545184dae7ae0a3bb41ec2794c88'
|
7
|
-
|
8
6
|
gem 'simplecov', :require => false
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,16 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/ruby-json-schema/json-schema.git
|
3
|
-
revision: aded4d798a48545184dae7ae0a3bb41ec2794c88
|
4
|
-
ref: aded4d798a48545184dae7ae0a3bb41ec2794c88
|
5
|
-
specs:
|
6
|
-
json-schema (2.5.0)
|
7
|
-
addressable (~> 2.3)
|
8
|
-
|
9
1
|
PATH
|
10
2
|
remote: .
|
11
3
|
specs:
|
12
|
-
openc-json_schema (0.0.
|
4
|
+
openc-json_schema (0.0.7)
|
5
|
+
json-schema-openc-fork (= 0.0.1)
|
13
6
|
|
14
7
|
GEM
|
15
8
|
remote: https://rubygems.org/
|
16
9
|
specs:
|
17
10
|
addressable (2.3.7)
|
18
11
|
diff-lcs (1.2.5)
|
12
|
+
json-schema-openc-fork (0.0.1)
|
13
|
+
addressable (~> 2.3)
|
19
14
|
multi_json (1.10.1)
|
20
15
|
rake (10.4.2)
|
21
16
|
rspec (3.1.0)
|
@@ -40,7 +35,6 @@ PLATFORMS
|
|
40
35
|
|
41
36
|
DEPENDENCIES
|
42
37
|
bundler (~> 1.7)
|
43
|
-
json-schema!
|
44
38
|
openc-json_schema!
|
45
39
|
rake (~> 10.0)
|
46
40
|
rspec (~> 3.0)
|
@@ -76,46 +76,52 @@ module Openc
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def convert_error(error)
|
79
|
+
path = fragment_to_path(error[:fragment])
|
80
|
+
|
79
81
|
case error[:failed_attribute]
|
80
82
|
when 'Required'
|
81
83
|
match = error[:message].match(/required property of '(.*)'/)
|
82
84
|
missing_property = match[1]
|
83
85
|
path = fragment_to_path("#{error[:fragment]}/#{missing_property}")
|
84
|
-
|
85
|
-
|
86
|
+
"Missing required property: #{path}"
|
87
|
+
when 'AdditionalProperties'
|
88
|
+
match = error[:message].match(/contains additional properties \["(.*)"\] outside of the schema/)
|
89
|
+
additional_property = match[1].split('", "')[0]
|
90
|
+
path = fragment_to_path("#{error[:fragment]}/#{additional_property}")
|
91
|
+
"Disallowed additional property: #{path}"
|
86
92
|
when 'OneOf'
|
87
93
|
if error[:message].match(/did not match any/)
|
88
|
-
|
94
|
+
"No match for property: #{path}"
|
89
95
|
else
|
90
|
-
|
96
|
+
"Multiple possible matches for property: #{path}"
|
91
97
|
end
|
92
98
|
when 'AnyOf'
|
93
|
-
|
99
|
+
"No match for property: #{path}"
|
94
100
|
when 'MinLength'
|
95
101
|
match = error[:message].match(/minimum string length of (\d+) in/)
|
96
102
|
min_length = match[1].to_i
|
97
|
-
|
103
|
+
"Property too short: #{path} (must be at least #{min_length} characters)"
|
98
104
|
when 'MaxLength'
|
99
105
|
match = error[:message].match(/maximum string length of (\d+) in/)
|
100
106
|
max_length = match[1].to_i
|
101
|
-
|
107
|
+
"Property too long: #{path} (must be at most #{max_length} characters)"
|
102
108
|
when 'TypeV4'
|
103
109
|
match = error[:message].match(/the following types?: ([\w\s,]+) in schema/)
|
104
110
|
allowed_types = match[1].split(',').map(&:strip)
|
105
|
-
|
111
|
+
"Property of wrong type: #{path} (must be of type #{allowed_types.join(', ')})"
|
106
112
|
when 'Enum'
|
107
113
|
match = error[:message].match(/the following values: ([\w\s,]+) in schema/)
|
108
114
|
allowed_values = match[1].split(',').map(&:strip)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
115
|
+
if allowed_values.size == 1
|
116
|
+
"Property must have value #{allowed_values[0]}: #{path}"
|
117
|
+
else
|
118
|
+
"Property not an allowed value: #{path} (must be one of #{allowed_values.join(', ')})"
|
119
|
+
end
|
114
120
|
else
|
115
121
|
if error[:message].match(/must be of format yyyy-mm-dd/)
|
116
|
-
|
122
|
+
"Property not of expected format: #{path} (must be of format yyyy-mm-dd)"
|
117
123
|
else
|
118
|
-
|
124
|
+
"Error of unknown type: #{path} (#{error[:message]})"
|
119
125
|
end
|
120
126
|
end
|
121
127
|
end
|
data/openc-json_schema.gemspec
CHANGED
@@ -20,11 +20,8 @@ describe Openc::JsonSchema do
|
|
20
20
|
'required' => ['aaa'],
|
21
21
|
}
|
22
22
|
record = {}
|
23
|
-
|
24
|
-
expect([schema, record]).to fail_validation_with(
|
25
|
-
:type => :missing,
|
26
|
-
:path => 'aaa'
|
27
|
-
)
|
23
|
+
error = 'Missing required property: aaa'
|
24
|
+
expect([schema, record]).to fail_validation_with(error)
|
28
25
|
end
|
29
26
|
|
30
27
|
specify 'when required nested property missing' do
|
@@ -40,11 +37,24 @@ describe Openc::JsonSchema do
|
|
40
37
|
}
|
41
38
|
}
|
42
39
|
record = {'aaa' => {}}
|
40
|
+
error = 'Missing required property: aaa.bbb'
|
41
|
+
expect([schema, record]).to fail_validation_with(error)
|
42
|
+
end
|
43
|
+
|
44
|
+
specify 'when additional properties are present but disallowed' do
|
45
|
+
schema = {
|
46
|
+
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
47
|
+
'type' => 'object',
|
48
|
+
'properties' => {
|
49
|
+
'aaa' => {'type' => 'number'}
|
50
|
+
},
|
51
|
+
'additionalProperties' => false
|
52
|
+
}
|
53
|
+
|
54
|
+
record = {'aaa' => 1, 'bbb' => 2, 'ccc' => 3}
|
43
55
|
|
44
|
-
|
45
|
-
|
46
|
-
:path => 'aaa.bbb'
|
47
|
-
)
|
56
|
+
error = 'Disallowed additional property: bbb'
|
57
|
+
expect([schema, record]).to fail_validation_with(error)
|
48
58
|
end
|
49
59
|
|
50
60
|
context 'when none of oneOf options match' do
|
@@ -83,10 +93,8 @@ describe Openc::JsonSchema do
|
|
83
93
|
|
84
94
|
record = {'aaa' => {'a_type' => 'a1', 'a_properties' => {}}}
|
85
95
|
|
86
|
-
|
87
|
-
|
88
|
-
:path => 'aaa.a_properties.bbb'
|
89
|
-
)
|
96
|
+
error = 'Missing required property: aaa.a_properties.bbb'
|
97
|
+
expect([schema, record]).to fail_validation_with(error)
|
90
98
|
end
|
91
99
|
|
92
100
|
specify 'and we are switching on a nested enum field' do
|
@@ -128,10 +136,8 @@ describe Openc::JsonSchema do
|
|
128
136
|
|
129
137
|
record = {'xxx' => {'aaa' => {'a_type' => 'a1', 'a_properties' => {}}}}
|
130
138
|
|
131
|
-
|
132
|
-
|
133
|
-
:path => 'xxx.aaa.a_properties.bbb'
|
134
|
-
)
|
139
|
+
error = 'Missing required property: xxx.aaa.a_properties.bbb'
|
140
|
+
expect([schema, record]).to fail_validation_with(error)
|
135
141
|
end
|
136
142
|
|
137
143
|
specify 'and we are not switching on an enum field' do
|
@@ -163,10 +169,8 @@ describe Openc::JsonSchema do
|
|
163
169
|
|
164
170
|
record = {'aaa' => {'bbb' => {}}}
|
165
171
|
|
166
|
-
|
167
|
-
|
168
|
-
:path => 'aaa'
|
169
|
-
)
|
172
|
+
error = 'No match for property: aaa'
|
173
|
+
expect([schema, record]).to fail_validation_with(error)
|
170
174
|
end
|
171
175
|
end
|
172
176
|
|
@@ -180,11 +184,8 @@ describe Openc::JsonSchema do
|
|
180
184
|
}
|
181
185
|
record = {'aaa' => 'x'}
|
182
186
|
|
183
|
-
|
184
|
-
|
185
|
-
:path => 'aaa',
|
186
|
-
:length => 2
|
187
|
-
)
|
187
|
+
error = 'Property too short: aaa (must be at least 2 characters)'
|
188
|
+
expect([schema, record]).to fail_validation_with(error)
|
188
189
|
end
|
189
190
|
|
190
191
|
specify 'when nested property too short' do
|
@@ -202,11 +203,8 @@ describe Openc::JsonSchema do
|
|
202
203
|
}
|
203
204
|
record = {'aaa' => {'bbb' => 'x'}}
|
204
205
|
|
205
|
-
|
206
|
-
|
207
|
-
:path => 'aaa.bbb',
|
208
|
-
:length => 2
|
209
|
-
)
|
206
|
+
error = 'Property too short: aaa.bbb (must be at least 2 characters)'
|
207
|
+
expect([schema, record]).to fail_validation_with(error)
|
210
208
|
end
|
211
209
|
|
212
210
|
specify 'when property too long' do
|
@@ -219,11 +217,8 @@ describe Openc::JsonSchema do
|
|
219
217
|
}
|
220
218
|
record = {'aaa' => 'xxx'}
|
221
219
|
|
222
|
-
|
223
|
-
|
224
|
-
:path => 'aaa',
|
225
|
-
:length => 2
|
226
|
-
)
|
220
|
+
error = 'Property too long: aaa (must be at most 2 characters)'
|
221
|
+
expect([schema, record]).to fail_validation_with(error)
|
227
222
|
end
|
228
223
|
|
229
224
|
specify 'when property of wrong type and many types allowed' do
|
@@ -236,11 +231,8 @@ describe Openc::JsonSchema do
|
|
236
231
|
}
|
237
232
|
record = {'aaa' => ['xxx']}
|
238
233
|
|
239
|
-
|
240
|
-
|
241
|
-
:path => 'aaa',
|
242
|
-
:allowed_types => ['number', 'string']
|
243
|
-
)
|
234
|
+
error = 'Property of wrong type: aaa (must be of type number, string)'
|
235
|
+
expect([schema, record]).to fail_validation_with(error)
|
244
236
|
end
|
245
237
|
|
246
238
|
specify 'when property of wrong type and single type allowed' do
|
@@ -253,14 +245,11 @@ describe Openc::JsonSchema do
|
|
253
245
|
}
|
254
246
|
record = {'aaa' => 'xxx'}
|
255
247
|
|
256
|
-
|
257
|
-
|
258
|
-
:path => 'aaa',
|
259
|
-
:allowed_types => ['number']
|
260
|
-
)
|
248
|
+
error = 'Property of wrong type: aaa (must be of type number)'
|
249
|
+
expect([schema, record]).to fail_validation_with(error)
|
261
250
|
end
|
262
251
|
|
263
|
-
specify 'when property not in enum' do
|
252
|
+
specify 'when property not in enum and many values allowed' do
|
264
253
|
schema = {
|
265
254
|
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
266
255
|
'type' => 'object',
|
@@ -270,30 +259,22 @@ describe Openc::JsonSchema do
|
|
270
259
|
}
|
271
260
|
record = {'aaa' => 'z'}
|
272
261
|
|
273
|
-
|
274
|
-
|
275
|
-
:path => 'aaa',
|
276
|
-
:allowed_values => ['a', 'b', 'c']
|
277
|
-
)
|
262
|
+
error = 'Property not an allowed value: aaa (must be one of a, b, c)'
|
263
|
+
expect([schema, record]).to fail_validation_with(error)
|
278
264
|
end
|
279
265
|
|
280
|
-
specify 'when
|
266
|
+
specify 'when property not in enum and single value allowed' do
|
281
267
|
schema = {
|
282
268
|
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
283
269
|
'type' => 'object',
|
284
270
|
'properties' => {
|
285
|
-
'aaa' => {'
|
286
|
-
}
|
287
|
-
'additionalProperties' => false
|
271
|
+
'aaa' => {'enum' => ['a']}
|
272
|
+
}
|
288
273
|
}
|
274
|
+
record = {'aaa' => 'z'}
|
289
275
|
|
290
|
-
|
291
|
-
|
292
|
-
expect([schema, record]).to fail_validation_with(
|
293
|
-
:type => :extra_properties,
|
294
|
-
:path => '',
|
295
|
-
:extra_properties => ['bbb', 'ccc']
|
296
|
-
)
|
276
|
+
error = 'Property must have value a: aaa'
|
277
|
+
expect([schema, record]).to fail_validation_with(error)
|
297
278
|
end
|
298
279
|
|
299
280
|
specify 'when property of wrong format' do
|
@@ -306,11 +287,8 @@ describe Openc::JsonSchema do
|
|
306
287
|
}
|
307
288
|
record = {'aaa' => 'zzz'}
|
308
289
|
|
309
|
-
|
310
|
-
|
311
|
-
:path => 'aaa',
|
312
|
-
:expected_format => 'yyyy-mm-dd'
|
313
|
-
)
|
290
|
+
error = 'Property not of expected format: aaa (must be of format yyyy-mm-dd)'
|
291
|
+
expect([schema, record]).to fail_validation_with(error)
|
314
292
|
end
|
315
293
|
|
316
294
|
specify 'when property with format is empty' do
|
@@ -323,11 +301,8 @@ describe Openc::JsonSchema do
|
|
323
301
|
}
|
324
302
|
record = {'aaa' => ''}
|
325
303
|
|
326
|
-
|
327
|
-
|
328
|
-
:path => 'aaa',
|
329
|
-
:expected_format => 'yyyy-mm-dd'
|
330
|
-
)
|
304
|
+
error = 'Property not of expected format: aaa (must be of format yyyy-mm-dd)'
|
305
|
+
expect([schema, record]).to fail_validation_with(error)
|
331
306
|
end
|
332
307
|
|
333
308
|
context 'when schema includes $ref' do
|
@@ -340,11 +315,8 @@ describe Openc::JsonSchema do
|
|
340
315
|
specify 'when data is invalid' do
|
341
316
|
schema_path = 'spec/schemas/aaa.json'
|
342
317
|
record = {'aaa' => 1, 'bbb' => {'BBB' => '10'}}
|
343
|
-
|
344
|
-
|
345
|
-
:path => 'bbb.BBB',
|
346
|
-
:allowed_types => ['number']
|
347
|
-
)
|
318
|
+
error = 'Property of wrong type: bbb.BBB (must be of type number)'
|
319
|
+
expect([schema_path, record]).to fail_validation_with(error)
|
348
320
|
end
|
349
321
|
end
|
350
322
|
|
@@ -358,11 +330,8 @@ describe Openc::JsonSchema do
|
|
358
330
|
specify 'when data is invalid' do
|
359
331
|
schema_path = 'spec/schemas/fff.json'
|
360
332
|
record = {'fff' => {'ggg' => {'hhh' => '123'}}}
|
361
|
-
|
362
|
-
|
363
|
-
:path => 'fff.ggg.hhh',
|
364
|
-
:allowed_types => ['number']
|
365
|
-
)
|
333
|
+
error = 'Property of wrong type: fff.ggg.hhh (must be of type number)'
|
334
|
+
expect([schema_path, record]).to fail_validation_with(error)
|
366
335
|
end
|
367
336
|
|
368
337
|
context 'and schema is an included schema' do
|
@@ -375,11 +344,8 @@ describe Openc::JsonSchema do
|
|
375
344
|
specify 'when data is invalid' do
|
376
345
|
schema_path = 'spec/schemas/includes/ggg.json'
|
377
346
|
record = {'ggg' => {'hhh' => '123'}}
|
378
|
-
|
379
|
-
|
380
|
-
:path => 'ggg.hhh',
|
381
|
-
:allowed_types => ['number']
|
382
|
-
)
|
347
|
+
error = 'Property of wrong type: ggg.hhh (must be of type number)'
|
348
|
+
expect([schema_path, record]).to fail_validation_with(error)
|
383
349
|
end
|
384
350
|
end
|
385
351
|
|
@@ -393,11 +359,8 @@ describe Openc::JsonSchema do
|
|
393
359
|
specify 'when data is invalid' do
|
394
360
|
schema_path = 'spec/schemas/iii.json'
|
395
361
|
record = {'iii' => {'jjj' => {'kkk' => '123'}}}
|
396
|
-
|
397
|
-
|
398
|
-
:path => 'iii.jjj.kkk',
|
399
|
-
:allowed_types => ['number']
|
400
|
-
)
|
362
|
+
error = 'Property of wrong type: iii.jjj.kkk (must be of type number)'
|
363
|
+
expect([schema_path, record]).to fail_validation_with(error)
|
401
364
|
end
|
402
365
|
end
|
403
366
|
end
|
@@ -407,10 +370,8 @@ describe Openc::JsonSchema do
|
|
407
370
|
record = {
|
408
371
|
'mmm' => []
|
409
372
|
}
|
410
|
-
|
411
|
-
|
412
|
-
:path => 'mmm'
|
413
|
-
)
|
373
|
+
error = 'No match for property: mmm'
|
374
|
+
expect([schema_path, record]).to fail_validation_with(error)
|
414
375
|
end
|
415
376
|
|
416
377
|
specify 'when schema includes oneOfs which contain $refs indirectly' do
|
@@ -423,14 +384,11 @@ describe Openc::JsonSchema do
|
|
423
384
|
}
|
424
385
|
}
|
425
386
|
}
|
426
|
-
|
427
|
-
|
428
|
-
:path => 'ccc.ccc_properties.ddd',
|
429
|
-
:allowed_types => ['number'],
|
430
|
-
)
|
387
|
+
error = 'Property of wrong type: ccc.ccc_properties.ddd (must be of type number)'
|
388
|
+
expect([schema_path, record]).to fail_validation_with(error)
|
431
389
|
end
|
432
390
|
|
433
|
-
specify '' do
|
391
|
+
specify 'when oneOf is used to dispatch on type' do
|
434
392
|
schema = {
|
435
393
|
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
436
394
|
'type' => 'object',
|
@@ -450,11 +408,8 @@ describe Openc::JsonSchema do
|
|
450
408
|
}
|
451
409
|
}
|
452
410
|
record = {'aaa' => 'not-a-date'}
|
453
|
-
|
454
|
-
|
455
|
-
:path => 'aaa',
|
456
|
-
:expected_format => 'yyyy-mm-dd'
|
457
|
-
)
|
411
|
+
error = 'Property not of expected format: aaa (must be of format yyyy-mm-dd)'
|
412
|
+
expect([schema, record]).to fail_validation_with(error)
|
458
413
|
end
|
459
414
|
end
|
460
415
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openc-json_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenCorporates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json-schema-openc-fork
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.1
|
55
69
|
description:
|
56
70
|
email: info@opencorporates.com
|
57
71
|
executables: []
|