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 +8 -8
- data/Gemfile.lock +2 -2
- data/lib/openc/json_schema/validator.rb +11 -6
- data/lib/openc/json_schema/version.rb +1 -1
- data/publish.sh +9 -0
- data/spec/openc_json_schema_spec.rb +45 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWJiYzM4NmZlYzYxNzU5MmNjODQ0NTI3ODhmODcyNTAyZGU2MTZhNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzFhYzk0MGQ0ODZlMWQ4Mjg4Njg0YjZkNWVlYWZiZDcyMGVhZjQzNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjM0ZTVlZDRjZGVlY2NkMWQyZjQ1YWNiZDdmYzg1MmJjNTllZmNhOTgwYWNj
|
10
|
+
M2NlNGE0OGM0MzJhY2I5MmE0ZDRmZWIzMDQzZjkwYjYwZmJmNTA5YzRlMzk1
|
11
|
+
OGQyZjZmZDdjMGI4YWE1ODYzM2JkZGNmOWM5OGIwMTllY2VmNDE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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.
|
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.
|
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
|
-
|
37
|
+
record_fragment = record
|
38
|
+
schema_fragment = schema
|
38
39
|
|
39
|
-
|
40
|
-
|
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
|
43
|
-
|
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
|
54
|
+
return error1.merge(:path => "#{path_elements.join('.')}.#{error1[:path]}")
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
data/publish.sh
ADDED
@@ -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.
|
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
|