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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmM4OTcxOWE4NDM5YTcxYzQyYWMwYjNmYTczMzhkN2I2YjVjNDA2Nw==
4
+ MmI5ZTBkM2Q5MmNiNTc3M2QwNWRhZmU5ZDYzODA1MjBlOGEwYThhMg==
5
5
  data.tar.gz: !binary |-
6
- MThkMzRkMTNjYWYxYTNhYmRlNGFjYjg1YjQ3ZDc4OGNmOTZlZDBiOA==
6
+ MWQ5ZGM5ZDUxYmM3NmM4ZjE2MTJiNTMyNDZhMDkyZjcwYWFiOGI4ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjJjZWMzMjZlOWI4ODk2NDc4OGIyMjgyMzg5Y2Y5ZTNjOTY5OTcyMWZhNDkz
10
- Y2MwZTI5ZTQ2ZGZhYjc5MTc1ODkzZTRiOGQ0Y2UyNzlkZjIzYmUxYjg3YzAw
11
- YTgzOTFiNzg2ZmZmNzdhYjliMDUwMDIzNjdlMjk2MmFiYzc2YzY=
9
+ OWM1ZGVkNDkyYzU5NzI5Mjg0NjcxNDY2MmM0ZDM1OTY2YzM4NjM0NDQxOGVi
10
+ ZDNiYTlkNTE3NzI3NTM2M2M3MzMzMzY3ZTliYjhiNGVmZjBkZjc4NzI1Zjdk
11
+ YmVlOTEyYzZjYmI2N2ZjYTQzNDZlNzIxYzY4MjkwYWQwMjE4NTg=
12
12
  data.tar.gz: !binary |-
13
- ZjRjNDZhNTkyNGU5MGVhY2ExMTU4NzkyNGY0NTg2Mzc4N2UxYmFlZDdhMzFj
14
- OTY1MjFlNDE4YzNlMGY4M2VhYjdhNjk2OGM2ZDE4OTIzM2MyMjYwZmUwYmVl
15
- ZGFkMjcyOTZjNzU1YTZiMDNmYjVkMjgwOTgyZTk5MDQxYmNkMTI=
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.5)
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
- {:type => :missing, :path => path}
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
- {:type => :one_of_no_matches, :path => fragment_to_path(error[:fragment])}
94
+ "No match for property: #{path}"
89
95
  else
90
- {:type => :one_of_many_matches, :path => fragment_to_path(error[:fragment])}
96
+ "Multiple possible matches for property: #{path}"
91
97
  end
92
98
  when 'AnyOf'
93
- {:type => :any_of_no_matches, :path => fragment_to_path(error[:fragment])}
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
- {:type => :too_short, :path => fragment_to_path(error[:fragment]), :length => min_length}
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
- {:type => :too_long, :path => fragment_to_path(error[:fragment]), :length => max_length}
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
- {:type => :type_mismatch, :path => fragment_to_path(error[:fragment]), :allowed_types => allowed_types}
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
- {:type => :enum_mismatch, :path => fragment_to_path(error[:fragment]), :allowed_values => allowed_values}
110
- when 'AdditionalProperties'
111
- match = error[:message].match(/contains additional properties \["(.*)"\] outside of the schema/)
112
- extra_properties = match[1].split('", "')
113
- {:type => :extra_properties, :path => fragment_to_path(error[:fragment]), :extra_properties => extra_properties}
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
- {:type => :format_mismatch, :path => fragment_to_path(error[:fragment]), :expected_format => 'yyyy-mm-dd'}
122
+ "Property not of expected format: #{path} (must be of format yyyy-mm-dd)"
117
123
  else
118
- {:type => :unknown, :path => fragment_to_path(error[:fragment]), :failed_attribute => error[:failed_attribute], :message => error[:message]}
124
+ "Error of unknown type: #{path} (#{error[:message]})"
119
125
  end
120
126
  end
121
127
  end
@@ -1,5 +1,5 @@
1
1
  module Openc
2
2
  module JsonSchema
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  end
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec", "~> 3.0"
23
23
 
24
- # spec.add_dependency "json-schema", "2.5.0"
24
+ spec.add_dependency "json-schema-openc-fork", "0.0.1"
25
25
  end
@@ -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
- expect([schema, record]).to fail_validation_with(
45
- :type => :missing,
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
- expect([schema, record]).to fail_validation_with(
87
- :type => :missing,
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
- expect([schema, record]).to fail_validation_with(
132
- :type => :missing,
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
- expect([schema, record]).to fail_validation_with(
167
- :type => :one_of_no_matches,
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
- expect([schema, record]).to fail_validation_with(
184
- :type => :too_short,
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
- expect([schema, record]).to fail_validation_with(
206
- :type => :too_short,
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
- expect([schema, record]).to fail_validation_with(
223
- :type => :too_long,
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
- expect([schema, record]).to fail_validation_with(
240
- :type => :type_mismatch,
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
- expect([schema, record]).to fail_validation_with(
257
- :type => :type_mismatch,
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
- expect([schema, record]).to fail_validation_with(
274
- :type => :enum_mismatch,
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 additional properties are present but disallowed' do
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' => {'type' => 'number'}
286
- },
287
- 'additionalProperties' => false
271
+ 'aaa' => {'enum' => ['a']}
272
+ }
288
273
  }
274
+ record = {'aaa' => 'z'}
289
275
 
290
- record = {'aaa' => 1, 'bbb' => 2, 'ccc' => 3}
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
- expect([schema, record]).to fail_validation_with(
310
- :type => :format_mismatch,
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
- expect([schema, record]).to fail_validation_with(
327
- :type => :format_mismatch,
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
- expect([schema_path, record]).to fail_validation_with(
344
- :type => :type_mismatch,
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
- expect([schema_path, record]).to fail_validation_with(
362
- :type => :type_mismatch,
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
- expect([schema_path, record]).to fail_validation_with(
379
- :type => :type_mismatch,
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
- expect([schema_path, record]).to fail_validation_with(
397
- :type => :type_mismatch,
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
- expect([schema_path, record]).to fail_validation_with(
411
- :type => :one_of_no_matches,
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
- expect([schema_path, record]).to fail_validation_with(
427
- :type => :type_mismatch,
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
- expect([schema, record]).to fail_validation_with(
454
- :type => :format_mismatch,
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.5
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-16 00:00:00.000000000 Z
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: []