openc-json_schema 0.0.2 → 0.0.3

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
- ZjYwZDVlMmQ4MWVhNmI2MDY1OTAzOWYzMTMwY2JmOWI0MTBkN2ZlOA==
4
+ OWJiYzM4NmZlYzYxNzU5MmNjODQ0NTI3ODhmODcyNTAyZGU2MTZhNQ==
5
5
  data.tar.gz: !binary |-
6
- ZmQyZjNiMmIzZTg0N2VjNGRlNmYxOTM4ZjllNDJjMjQwMGY5MzFhMQ==
6
+ NzFhYzk0MGQ0ODZlMWQ4Mjg4Njg0YjZkNWVlYWZiZDcyMGVhZjQzNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGM1ZmZkNmJjN2ExMGJlMzhhMWUzMDI2MTdjNDZiZDE0NDkwNDc0MzVhMGQw
10
- NTVmZGU5Yzc4NzdiN2MwNjkwN2NhMDFlYTA2YWEzMTY2ZGEzZjA1YmEyZjM1
11
- NmJhOWVhNmQ3OGY1OTYwZTk4NjhkNzJkYzg1MDU2MGJkMDAyZWI=
9
+ NjM0ZTVlZDRjZGVlY2NkMWQyZjQ1YWNiZDdmYzg1MmJjNTllZmNhOTgwYWNj
10
+ M2NlNGE0OGM0MzJhY2I5MmE0ZDRmZWIzMDQzZjkwYjYwZmJmNTA5YzRlMzk1
11
+ OGQyZjZmZDdjMGI4YWE1ODYzM2JkZGNmOWM5OGIwMTllY2VmNDE=
12
12
  data.tar.gz: !binary |-
13
- OTdmYmMwODc0MTQ1OWYwZmQxZDdhMzQ3NzZjZDI3ZGQ1OWI4YWE3OWY4OTg5
14
- ZWMxN2FhY2EwNmI2YjExZmY0NDkyNGQ0ZGZmMWE4OWRmNDBhNGEzZThjYjg2
15
- YjhjODA5OGY2NzRiZDAwNmM5OWJhNzQxMDU3ODc3OGY2OWFmYmY=
13
+ NTE0OWZhNWMwNTJkOGYxOGFmN2M0NWY2NzJlZWViYzczODM4YWZiMjc2YzE1
14
+ MTgwZmQ0MTc0ZGNiYjBhZDFhNzI4NDM1NWQ0ZTlkMTA4MDRiZmM4MTljMWY3
15
+ YTFkOWFhYWFmOWMxY2UzOGE3NzY2OWEwNGM4NjdiYThkZTg5YjU=
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openc-json_schema (0.0.2)
4
+ openc-json_schema (0.0.3)
5
5
  json-schema (= 2.5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.3.6)
10
+ addressable (2.3.7)
11
11
  diff-lcs (1.2.5)
12
12
  json-schema (2.5.0)
13
13
  addressable (~> 2.3)
@@ -34,19 +34,24 @@ module Openc
34
34
  if error[:message].match(/did not match any/)
35
35
  path_elements = fragment_to_path(error[:fragment]).split('.')
36
36
 
37
- raise "Deeply nested OneOf error at: #{error[:fragment]}" unless path_elements.size == 1
37
+ record_fragment = record
38
+ schema_fragment = schema
38
39
 
39
- record_fragment = record[path_elements[0]]
40
- schema_fragments = schema['properties'][path_elements[0]]['oneOf']
40
+ path_elements.each do |element|
41
+ record_fragment = record_fragment[element]
42
+ schema_fragment = schema_fragment['properties'][element]
43
+ end
44
+
45
+ one_of_schemas = schema_fragment['oneOf']
41
46
 
42
- unless schema_fragments.nil?
43
- schema_fragments.each do |s|
47
+ unless one_of_schemas.nil?
48
+ one_of_schemas.each do |s|
44
49
  s['properties'].each do |k, v|
45
50
  next if v['enum'].nil?
46
51
 
47
52
  if v['enum'].include?(record_fragment[k])
48
53
  error1 = validate(s, schema_dir, record_fragment)
49
- return error1.merge(:path => "#{path_elements[0]}.#{error1[:path]}")
54
+ return error1.merge(:path => "#{path_elements.join('.')}.#{error1[:path]}")
50
55
  end
51
56
  end
52
57
  end
@@ -1,5 +1,5 @@
1
1
  module Openc
2
2
  module JsonSchema
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
data/publish.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+
3
+ gem build openc-json_schema.gemspec
4
+ gem push $(ls *gem|tail -1)
5
+
6
+ function clean {
7
+ rm *gem
8
+ }
9
+ trap clean EXIT
@@ -89,6 +89,51 @@ describe Openc::JsonSchema do
89
89
  )
90
90
  end
91
91
 
92
+ specify 'and we are switching on a nested enum field' do
93
+ schema = {
94
+ '$schema' => 'http://json-schema.org/draft-04/schema#',
95
+ 'type' => 'object',
96
+ 'properties' => {
97
+ 'xxx' => {
98
+ 'type' => 'object',
99
+ 'properties' => {
100
+ 'aaa' => {
101
+ 'type' => 'object',
102
+ 'oneOf' => [{
103
+ 'properties' => {
104
+ 'a_type' => {
105
+ 'enum' => ['a1']
106
+ },
107
+ 'a_properties' => {
108
+ 'type' => 'object',
109
+ 'required' => ['bbb'],
110
+ }
111
+ }
112
+ }, {
113
+ 'properties' => {
114
+ 'a_type' => {
115
+ 'enum' => ['a2']
116
+ },
117
+ 'a_properties' => {
118
+ 'type' => 'object',
119
+ 'required' => ['ccc']
120
+ }
121
+ }
122
+ }]
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+
129
+ record = {'xxx' => {'aaa' => {'a_type' => 'a1', 'a_properties' => {}}}}
130
+
131
+ expect([schema, record]).to fail_validation_with(
132
+ :type => :missing,
133
+ :path => 'xxx.aaa.a_properties.bbb'
134
+ )
135
+ end
136
+
92
137
  specify 'and we are not switching on an enum field' do
93
138
  schema = {
94
139
  '$schema' => 'http://json-schema.org/draft-04/schema#',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openc-json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenCorporates
@@ -83,6 +83,7 @@ files:
83
83
  - lib/openc/json_schema/validator.rb
84
84
  - lib/openc/json_schema/version.rb
85
85
  - openc-json_schema.gemspec
86
+ - publish.sh
86
87
  - spec/openc_json_schema_spec.rb
87
88
  - spec/schemas/aaa.json
88
89
  - spec/schemas/ccc.json