j2119 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/j2119.gemspec +1 -1
- data/lib/j2119/allowed_fields.rb +12 -1
- data/lib/j2119/assigner.rb +9 -2
- data/lib/j2119/json_path_checker.rb +5 -5
- data/lib/j2119/matcher.rb +3 -0
- data/lib/j2119/node_validator.rb +14 -14
- data/lib/j2119/parser.rb +4 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 202e9050184c4caffde950c3247ff1186481b540b8dc8f9b8b3d22255f63beff
|
4
|
+
data.tar.gz: 70d6bde16dcbe291f7c1cb82305e0487a029b51abf3684dd6b5489abfed064be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e99db9fc578439cd14de9608f35ec5f524f521b351c8e180ceca6f7e2c154c2ad0a8c0f169e53eac0d3d1acbf8471c4aa75a62c9c3daaf3ead5af4694dc96a
|
7
|
+
data.tar.gz: 006c59bc14e255f57f368386b8283c91fd67987ec3b4874882c21105f59dc45f8391be2efbb00dd7adf292a4b8085a18a0d1636fc9424dc4b237a7328c20176d
|
data/j2119.gemspec
CHANGED
data/lib/j2119/allowed_fields.rb
CHANGED
@@ -19,6 +19,7 @@ module J2119
|
|
19
19
|
|
20
20
|
def initialize
|
21
21
|
@allowed = {}
|
22
|
+
@any = []
|
22
23
|
end
|
23
24
|
|
24
25
|
def set_allowed(role, child)
|
@@ -26,10 +27,20 @@ module J2119
|
|
26
27
|
@allowed[role] << child
|
27
28
|
end
|
28
29
|
|
30
|
+
def set_any(role)
|
31
|
+
@any << role
|
32
|
+
end
|
33
|
+
|
29
34
|
def allowed?(roles, child)
|
30
|
-
roles.any? do |role|
|
35
|
+
any?(roles) || roles.any? do |role|
|
31
36
|
@allowed[role] && @allowed[role].include?(child)
|
32
37
|
end
|
33
38
|
end
|
39
|
+
|
40
|
+
def any?(roles)
|
41
|
+
roles.any? do |role|
|
42
|
+
@any.include?(role)
|
43
|
+
end
|
44
|
+
end
|
34
45
|
end
|
35
46
|
end
|
data/lib/j2119/assigner.rb
CHANGED
@@ -58,6 +58,7 @@ module J2119
|
|
58
58
|
relation = assertion['relation']
|
59
59
|
target = assertion['target']
|
60
60
|
strings = assertion['strings']
|
61
|
+
child_type = assertion['child_type']
|
61
62
|
vals = assertion['vals']
|
62
63
|
|
63
64
|
# watch out for conditionals
|
@@ -110,14 +111,20 @@ module J2119
|
|
110
111
|
end
|
111
112
|
|
112
113
|
# there can be role defs there too
|
113
|
-
if
|
114
|
+
if child_type
|
114
115
|
@matcher.add_role assertion['child_role']
|
115
|
-
child_type = assertion['child_type']
|
116
116
|
if child_type == 'value'
|
117
117
|
@roles.add_child_role(role, field_name, assertion['child_role'])
|
118
118
|
elsif child_type == 'element' || child_type == 'field'
|
119
119
|
@roles.add_grandchild_role(role, field_name, assertion['child_role'])
|
120
120
|
end
|
121
|
+
else
|
122
|
+
anyOrObjectOrArray = (!type) || (type == 'object') || (type == 'array')
|
123
|
+
# untyped field without a defined child role
|
124
|
+
if field_name && anyOrObjectOrArray && (modal != 'MUST NOT')
|
125
|
+
@roles.add_grandchild_role(role, field_name, field_name)
|
126
|
+
@allowed_fields.set_any(field_name)
|
127
|
+
end
|
121
128
|
end
|
122
129
|
end
|
123
130
|
|
@@ -30,17 +30,17 @@ module J2119
|
|
30
30
|
"[#{re_classes.join('')}]"
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
name_re = classes_to_re(INITIAL_NAME_CLASSES) +
|
34
34
|
classes_to_re(FOLLOWING_NAME_CLASSES) + '*'
|
35
|
-
dot_step = DOT_SEPARATOR + '((' +
|
36
|
-
rp_dot_step = DOT_SEPARATOR +
|
37
|
-
bracket_step = '\[' + "'" +
|
35
|
+
dot_step = DOT_SEPARATOR + '((' + name_re + ')|(\*))'
|
36
|
+
rp_dot_step = DOT_SEPARATOR + name_re
|
37
|
+
bracket_step = '\[' + "'" + name_re + "'" + '\]'
|
38
38
|
rp_num_index = '\[\d+\]'
|
39
39
|
num_index = '\[\d+(, *\d+)?\]'
|
40
40
|
star_index = '\[\*\]'
|
41
41
|
colon_index = '\[(-?\d+)?:(-?\d+)?\]'
|
42
42
|
index = '((' + num_index + ')|(' + star_index + ')|(' + colon_index + '))'
|
43
|
-
step = '((' + dot_step + ')|(' + bracket_step + '))' + '(' + index + ')?'
|
43
|
+
step = '((' + dot_step + ')|(' + bracket_step + ')|(' + index + '))' + '(' + index + ')?'
|
44
44
|
rp_step = '((' + rp_dot_step + ')|(' + bracket_step + '))' + '(' + rp_num_index + ')?'
|
45
45
|
path = '^\$' + '(' + step + ')+$'
|
46
46
|
reference_path = '^\$' + '(' + rp_step + ')+$'
|
data/lib/j2119/matcher.rb
CHANGED
data/lib/j2119/node_validator.rb
CHANGED
@@ -56,21 +56,21 @@ module J2119
|
|
56
56
|
|
57
57
|
# find inheritance-based roles for that field
|
58
58
|
grandchild_roles = @parser.find_grandchild_roles(roles, name)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
59
|
+
if !@parser.allows_any?(grandchild_roles)
|
60
|
+
# recurse into grandkids
|
61
|
+
if val.is_a? Hash
|
62
|
+
val.each do |child_name, child_val|
|
63
|
+
validate_node(child_val, "#{path}.#{name}.#{child_name}",
|
64
|
+
grandchild_roles.clone, problems)
|
65
|
+
end
|
66
|
+
elsif val.is_a? Array
|
67
|
+
i = 0
|
68
|
+
val.each do |member|
|
69
|
+
validate_node(member, "#{path}.#{name}[#{i}]",
|
70
|
+
grandchild_roles.clone, problems)
|
71
|
+
i += 1
|
72
|
+
end
|
72
73
|
end
|
73
|
-
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
data/lib/j2119/parser.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: j2119
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Bray
|
@@ -14,14 +14,14 @@ dependencies:
|
|
14
14
|
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: Validates JSON objects based on constraints in RFC2119-like language
|
@@ -30,7 +30,7 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
-
- .gitignore
|
33
|
+
- ".gitignore"
|
34
34
|
- Gemfile
|
35
35
|
- LICENSE
|
36
36
|
- NOTICE.txt
|
@@ -60,17 +60,17 @@ require_paths:
|
|
60
60
|
- lib
|
61
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
|
-
- -
|
63
|
+
- - ">="
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.
|
73
|
+
rubygems_version: 2.7.7
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: JSON DSL Validator
|