jsi 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +18 -15
- data/jsi.gemspec +1 -1
- data/lib/jsi.rb +5 -1
- data/lib/jsi/base.rb +222 -215
- data/lib/jsi/json-schema-fragments.rb +1 -1
- data/lib/jsi/json/node.rb +61 -146
- data/lib/jsi/json/pointer.rb +235 -41
- data/lib/jsi/pathed_node.rb +113 -0
- data/lib/jsi/schema.rb +46 -40
- data/lib/jsi/schema_classes.rb +86 -0
- data/lib/jsi/simple_wrap.rb +7 -0
- data/lib/jsi/typelike_modules.rb +39 -11
- data/lib/jsi/util.rb +3 -0
- data/lib/jsi/version.rb +1 -1
- data/test/base_array_test.rb +63 -51
- data/test/base_hash_test.rb +38 -28
- data/test/base_test.rb +54 -27
- data/test/jsi_json_arraynode_test.rb +19 -18
- data/test/jsi_json_hashnode_test.rb +29 -28
- data/test/jsi_json_node_test.rb +50 -28
- data/test/jsi_json_pointer_test.rb +13 -5
- data/test/schema_test.rb +13 -13
- data/test/spreedly_openapi_test.rb +8 -0
- data/test/test_helper.rb +3 -3
- data/test/util_test.rb +10 -10
- metadata +8 -3
@@ -18,8 +18,9 @@ document_types.each do |document_type|
|
|
18
18
|
let(:document) { document_type[:document] }
|
19
19
|
# by default the node is the whole document
|
20
20
|
let(:path) { [] }
|
21
|
+
let(:pointer) { JSI::JSON::Pointer.new(path) }
|
21
22
|
# the node being tested
|
22
|
-
let(:node) { JSI::JSON::Node.new_by_type(document,
|
23
|
+
let(:node) { JSI::JSON::Node.new_by_type(document, pointer) }
|
23
24
|
|
24
25
|
describe '#each' do
|
25
26
|
it 'iterates, one argument' do
|
@@ -80,43 +81,43 @@ document_types.each do |document_type|
|
|
80
81
|
it('#empty?') { assert_equal(false, node.empty?) }
|
81
82
|
it('#has_key?') { assert_equal(true, node.has_key?('a')) }
|
82
83
|
it('#include?') { assert_equal(false, node.include?('q')) }
|
83
|
-
it('#key?')
|
84
|
-
it('#keys')
|
85
|
-
it('#length')
|
86
|
-
it('#member?')
|
87
|
-
it('#size')
|
84
|
+
it('#key?') { assert_equal(true, node.key?('c')) }
|
85
|
+
it('#keys') { assert_equal(['a', 'c'], node.keys) }
|
86
|
+
it('#length') { assert_equal(2, node.length) }
|
87
|
+
it('#member?') { assert_equal(false, node.member?(0)) }
|
88
|
+
it('#size') { assert_equal(2, node.size) }
|
88
89
|
end
|
89
90
|
describe 'key + value methods' do
|
90
|
-
it('#<')
|
91
|
-
it('#<=')
|
92
|
-
it('#>')
|
93
|
-
it('#>=')
|
94
|
-
it('#any?')
|
95
|
-
it('#assoc')
|
96
|
-
it('#dig')
|
97
|
-
it('#each_pair')
|
98
|
-
it('#each_value')
|
99
|
-
it('#fetch')
|
91
|
+
it('#<') { assert_equal(true, node < {'a' => 'b', 'c' => node['c'], 'x' => 'y'}) } if {}.respond_to?(:<)
|
92
|
+
it('#<=') { assert_equal(true, node <= node) } if {}.respond_to?(:<=)
|
93
|
+
it('#>') { assert_equal(true, node > {}) } if {}.respond_to?(:>)
|
94
|
+
it('#>=') { assert_equal(false, node >= {'foo' => 'bar'}) } if {}.respond_to?(:>=)
|
95
|
+
it('#any?') { assert_equal(false, node.any? { |k, v| v == 3 }) }
|
96
|
+
it('#assoc') { assert_equal(['a', 'b'], node.assoc('a')) }
|
97
|
+
it('#dig') { assert_equal('e', node.dig('c', 'd')) } if {}.respond_to?(:dig)
|
98
|
+
it('#each_pair') { assert_equal([['a', 'b'], ['c', node['c']]], node.each_pair.to_a) }
|
99
|
+
it('#each_value') { assert_equal(['b', node['c']], node.each_value.to_a) }
|
100
|
+
it('#fetch') { assert_equal('b', node.fetch('a')) }
|
100
101
|
it('#fetch_values') { assert_equal(['b'], node.fetch_values('a')) } if {}.respond_to?(:fetch_values)
|
101
|
-
it('#has_value?')
|
102
|
-
it('#invert')
|
103
|
-
it('#key')
|
104
|
-
it('#rassoc')
|
105
|
-
it('#to_h')
|
106
|
-
it('#to_proc')
|
102
|
+
it('#has_value?') { assert_equal(true, node.has_value?('b')) }
|
103
|
+
it('#invert') { assert_equal({'b' => 'a', node['c'] => 'c'}, node.invert) }
|
104
|
+
it('#key') { assert_equal('a', node.key('b')) }
|
105
|
+
it('#rassoc') { assert_equal(['a', 'b'], node.rassoc('b')) }
|
106
|
+
it('#to_h') { assert_equal({'a' => 'b', 'c' => node['c']}, node.to_h) }
|
107
|
+
it('#to_proc') { assert_equal('b', node.to_proc.call('a')) } if {}.respond_to?(:to_proc)
|
107
108
|
if {}.respond_to?(:transform_values)
|
108
109
|
it('#transform_values') { assert_equal({'a' => nil, 'c' => nil}, node.transform_values { |_| nil }) }
|
109
110
|
end
|
110
|
-
it('#value?')
|
111
|
-
it('#values')
|
112
|
-
it('#values_at')
|
111
|
+
it('#value?') { assert_equal(false, node.value?('0')) }
|
112
|
+
it('#values') { assert_equal(['b', node['c']], node.values) }
|
113
|
+
it('#values_at') { assert_equal(['b'], node.values_at('a')) }
|
113
114
|
end
|
114
115
|
describe 'modified copy methods' do
|
115
116
|
# I'm going to rely on the #merge test above to test the modified copy functionality and just do basic
|
116
117
|
# tests of all the modified copy methods here
|
117
|
-
it('#merge')
|
118
|
-
it('#reject')
|
119
|
-
it('#select')
|
118
|
+
it('#merge') { assert_equal(JSI::JSON::Node.new_doc(node.content), node.merge({})) }
|
119
|
+
it('#reject') { assert_equal(JSI::JSON::Node.new_doc({}), node.reject { true }) }
|
120
|
+
it('#select') { assert_equal(JSI::JSON::Node.new_doc({}), node.select { false }) }
|
120
121
|
# Hash#compact only available as of ruby 2.5.0
|
121
122
|
if {}.respond_to?(:compact)
|
122
123
|
it('#compact') { assert_equal(JSI::JSON::Node.new_doc({"a" => "b", "c" => node.content.to_hash["c"]}), node.compact) }
|
data/test/jsi_json_node_test.rb
CHANGED
@@ -2,13 +2,22 @@ require_relative 'test_helper'
|
|
2
2
|
|
3
3
|
describe JSI::JSON::Node do
|
4
4
|
let(:path) { [] }
|
5
|
-
let(:
|
5
|
+
let(:pointer) { JSI::JSON::Pointer.new(path) }
|
6
|
+
let(:node) { JSI::JSON::Node.new(document, pointer) }
|
6
7
|
|
7
8
|
describe 'initialization' do
|
8
9
|
it 'initializes' do
|
9
|
-
node = JSI::JSON::Node.new({'a' => 'b'},
|
10
|
+
node = JSI::JSON::Node.new({'a' => 'b'}, pointer)
|
10
11
|
assert_equal({'a' => 'b'}, node.document)
|
11
|
-
assert_equal([], node.
|
12
|
+
assert_equal(JSI::JSON::Pointer.new([]), node.pointer)
|
13
|
+
end
|
14
|
+
it 'initializes, pointer is not pointer' do
|
15
|
+
err = assert_raises(TypeError) { JSI::JSON::Node.new({'a' => 'b'}, []) }
|
16
|
+
assert_equal('pointer must be a JSI::JSON::Pointer. got: [] (Array)', err.message)
|
17
|
+
end
|
18
|
+
it 'initializes, document is another Node' do
|
19
|
+
err = assert_raises(TypeError) { JSI::JSON::Node.new(JSI::JSON::Node.new({'a' => 'b'}, pointer), pointer) }
|
20
|
+
assert_equal("document of a Node should not be another JSI::JSON::Node: #<JSI::JSON::Node fragment=\"#\" {\"a\"=>\"b\"}>", err.message)
|
12
21
|
end
|
13
22
|
end
|
14
23
|
describe 'initialization by .new_by_type' do
|
@@ -31,15 +40,20 @@ describe JSI::JSON::Node do
|
|
31
40
|
end
|
32
41
|
describe '#pointer' do
|
33
42
|
it 'is a JSI::JSON::Pointer' do
|
34
|
-
assert_instance_of(JSI::JSON::Pointer, JSI::JSON::Node.new({},
|
43
|
+
assert_instance_of(JSI::JSON::Pointer, JSI::JSON::Node.new({}, pointer).pointer)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
describe '#path' do
|
47
|
+
it 'is an array of reference tokens' do
|
48
|
+
assert_equal(['a'], JSI::JSON::Node.new({}, JSI::JSON::Pointer.new(['a'])).path)
|
35
49
|
end
|
36
50
|
end
|
37
51
|
describe '#content' do
|
38
52
|
it 'returns the content at the root' do
|
39
|
-
assert_equal({'a' => 'b'}, JSI::JSON::Node.new({'a' => 'b'},
|
53
|
+
assert_equal({'a' => 'b'}, JSI::JSON::Node.new({'a' => 'b'}, pointer).content)
|
40
54
|
end
|
41
55
|
it 'returns the content from the deep' do
|
42
|
-
assert_equal('b', JSI::JSON::Node.new([0, {'x' => [{'a' => ['b']}]}], [1, 'x', 0, 'a', 0]).content)
|
56
|
+
assert_equal('b', JSI::JSON::Node.new([0, {'x' => [{'a' => ['b']}]}], JSI::JSON::Pointer.new([1, 'x', 0, 'a', 0])).content)
|
43
57
|
end
|
44
58
|
end
|
45
59
|
describe '#deref' do
|
@@ -65,7 +79,7 @@ describe JSI::JSON::Node do
|
|
65
79
|
it 'subscripts a node consisting of a $ref WITHOUT following' do
|
66
80
|
subscripted = node['a']
|
67
81
|
assert_equal({'$ref' => 'bar', 'foo' => 'bar'}, subscripted.content)
|
68
|
-
assert_equal(['a'], subscripted.
|
82
|
+
assert_equal(JSI::JSON::Pointer.new(['a']), subscripted.pointer)
|
69
83
|
end
|
70
84
|
it 'looks for a node in #/schemas with the name of the $ref' do
|
71
85
|
assert_equal({'description' => ['baz']}, node['a'].deref.content)
|
@@ -73,7 +87,7 @@ describe JSI::JSON::Node do
|
|
73
87
|
it 'follows a $ref when subscripting past it' do
|
74
88
|
subscripted = node['a']['description']
|
75
89
|
assert_equal(['baz'], subscripted.content)
|
76
|
-
assert_equal(['schemas', 'bar', 'description'], subscripted.
|
90
|
+
assert_equal(JSI::JSON::Pointer.new(['schemas', 'bar', 'description']), subscripted.pointer)
|
77
91
|
end
|
78
92
|
it 'does not follow a $ref when subscripting a key that is present' do
|
79
93
|
subscripted = node['a']['foo']
|
@@ -103,13 +117,20 @@ describe JSI::JSON::Node do
|
|
103
117
|
subscripted = node[1]['x']
|
104
118
|
assert_instance_of(JSI::JSON::ArrayNode, subscripted)
|
105
119
|
assert_equal([{'a' => ['b']}], subscripted.content)
|
106
|
-
assert_equal([1, 'x'], subscripted.
|
120
|
+
assert_equal(JSI::JSON::Pointer.new([1, 'x']), subscripted.pointer)
|
107
121
|
end
|
108
122
|
it 'returns HashNode for a Hash' do
|
109
123
|
subscripted = node[1]
|
110
124
|
assert_instance_of(JSI::JSON::HashNode, subscripted)
|
111
125
|
assert_equal({'x' => [{'a' => ['b']}]}, subscripted.content)
|
112
|
-
assert_equal([1], subscripted.
|
126
|
+
assert_equal(JSI::JSON::Pointer.new([1]), subscripted.pointer)
|
127
|
+
end
|
128
|
+
describe 'content does not respond to []' do
|
129
|
+
let(:document) { Object.new }
|
130
|
+
it 'cannot subscript' do
|
131
|
+
err = assert_raises(NoMethodError) { node['x'] }
|
132
|
+
assert_equal("undefined method `[]`\nsubscripting with \"x\" (String) from Object. content is: #{document.pretty_inspect.chomp}", err.message)
|
133
|
+
end
|
113
134
|
end
|
114
135
|
end
|
115
136
|
describe 'with dereferencing' do
|
@@ -122,12 +143,12 @@ describe JSI::JSON::Node do
|
|
122
143
|
it 'subscripts a node consisting of a $ref WITHOUT following' do
|
123
144
|
subscripted = node['a']
|
124
145
|
assert_equal({'$ref' => '#/foo', 'description' => 'hi'}, subscripted.content)
|
125
|
-
assert_equal(['a'], subscripted.
|
146
|
+
assert_equal(JSI::JSON::Pointer.new(['a']), subscripted.pointer)
|
126
147
|
end
|
127
148
|
it 'follows a $ref when subscripting past it' do
|
128
149
|
subscripted = node['a']['bar']
|
129
150
|
assert_equal(['baz'], subscripted.content)
|
130
|
-
assert_equal(['foo', 'bar'], subscripted.
|
151
|
+
assert_equal(JSI::JSON::Pointer.new(['foo', 'bar']), subscripted.pointer)
|
131
152
|
end
|
132
153
|
it 'does not follow a $ref when subscripting a key that is present' do
|
133
154
|
subscripted = node['a']['description']
|
@@ -140,7 +161,7 @@ describe JSI::JSON::Node do
|
|
140
161
|
it 'assigns' do
|
141
162
|
node[0] = 'abcdefg'
|
142
163
|
assert_equal(['abcdefg', {'x' => [{'a' => ['b']}]}], document)
|
143
|
-
string_node = JSI::JSON::Node.new(document, [0])
|
164
|
+
string_node = JSI::JSON::Node.new(document, JSI::JSON::Pointer.new([0]))
|
144
165
|
string_node[0..2] = '0'
|
145
166
|
assert_equal(['0defg', {'x' => [{'a' => ['b']}]}], document)
|
146
167
|
node[0] = node[1]
|
@@ -161,19 +182,19 @@ describe JSI::JSON::Node do
|
|
161
182
|
let(:document) { {'a' => {'b' => []}} }
|
162
183
|
it 'finds a parent' do
|
163
184
|
sub = node['a']['b']
|
164
|
-
assert_equal(['a', 'b'], sub.
|
185
|
+
assert_equal(JSI::JSON::Pointer.new(['a', 'b']), sub.pointer)
|
165
186
|
parent = sub.parent_node
|
166
|
-
assert_equal(['a'], parent.
|
187
|
+
assert_equal(JSI::JSON::Pointer.new(['a']), parent.pointer)
|
167
188
|
assert_equal({'b' => []}, parent.content)
|
168
189
|
assert_equal(node['a'], parent)
|
169
190
|
root_from_sub = sub.parent_node.parent_node
|
170
|
-
assert_equal([], root_from_sub.
|
191
|
+
assert_equal(JSI::JSON::Pointer.new([]), root_from_sub.pointer)
|
171
192
|
assert_equal({'a' => {'b' => []}}, root_from_sub.content)
|
172
193
|
assert_equal(node, root_from_sub)
|
173
194
|
err = assert_raises(JSI::JSON::Pointer::ReferenceError) do
|
174
195
|
root_from_sub.parent_node
|
175
196
|
end
|
176
|
-
assert_match(/\Acannot access parent of root
|
197
|
+
assert_match(/\Acannot access parent of root pointer: #<JSI::JSON::Pointer/, err.message)
|
177
198
|
end
|
178
199
|
end
|
179
200
|
describe '#pointer_path' do
|
@@ -234,11 +255,11 @@ describe JSI::JSON::Node do
|
|
234
255
|
assert_equal(node.document_node[0].content.object_id, unmodified_dup.document_node[0].content.object_id)
|
235
256
|
end
|
236
257
|
it 'raises subscripting string from array' do
|
237
|
-
err = assert_raises(TypeError) { JSI::JSON::Node.new(document, ['x']).modified_copy(&:dup) }
|
258
|
+
err = assert_raises(TypeError) { JSI::JSON::Node.new(document, JSI::JSON::Pointer.new(['x'])).modified_copy(&:dup) }
|
238
259
|
assert_match(%r(\Abad subscript "x" with remaining subpath: \[\] for array: \[.*\]\z)m, err.message)
|
239
260
|
end
|
240
261
|
it 'raises subscripting from invalid subpath' do
|
241
|
-
err = assert_raises(TypeError) { JSI::JSON::Node.new(document, [0, 0, 'what']).modified_copy(&:dup) }
|
262
|
+
err = assert_raises(TypeError) { JSI::JSON::Node.new(document, JSI::JSON::Pointer.new([0, 0, 'what'])).modified_copy(&:dup) }
|
242
263
|
assert_match(%r(bad subscript: "what" with remaining subpath: \[\] for content: "b"\z)m, err.message)
|
243
264
|
end
|
244
265
|
end
|
@@ -257,23 +278,24 @@ describe JSI::JSON::Node do
|
|
257
278
|
end
|
258
279
|
end
|
259
280
|
describe '#fingerprint' do
|
281
|
+
let(:pointer) { JSI::JSON::Pointer.new([]) }
|
260
282
|
it 'hashes consistently' do
|
261
|
-
assert_equal('x', {JSI::JSON::Node.new([0],
|
283
|
+
assert_equal('x', {JSI::JSON::Node.new([0], pointer) => 'x'}[JSI::JSON::Node.new([0], pointer)])
|
262
284
|
end
|
263
285
|
it 'hashes consistently regardless of the Node being decorated as a subclass' do
|
264
|
-
assert_equal('x', {JSI::JSON::Node.new_doc([0]) => 'x'}[JSI::JSON::Node.new([0],
|
265
|
-
assert_equal('x', {JSI::JSON::Node.new([0],
|
286
|
+
assert_equal('x', {JSI::JSON::Node.new_doc([0]) => 'x'}[JSI::JSON::Node.new([0], pointer)])
|
287
|
+
assert_equal('x', {JSI::JSON::Node.new([0], pointer) => 'x'}[JSI::JSON::Node.new_doc([0])])
|
266
288
|
end
|
267
289
|
it '==' do
|
268
|
-
assert_equal(JSI::JSON::Node.new([0],
|
269
|
-
assert_equal(JSI::JSON::Node.new_doc([0]), JSI::JSON::Node.new([0],
|
270
|
-
assert_equal(JSI::JSON::Node.new([0],
|
290
|
+
assert_equal(JSI::JSON::Node.new([0], pointer), JSI::JSON::Node.new([0], pointer))
|
291
|
+
assert_equal(JSI::JSON::Node.new_doc([0]), JSI::JSON::Node.new([0], pointer))
|
292
|
+
assert_equal(JSI::JSON::Node.new([0], pointer), JSI::JSON::Node.new_doc([0]))
|
271
293
|
assert_equal(JSI::JSON::Node.new_doc([0]), JSI::JSON::Node.new_doc([0]))
|
272
294
|
end
|
273
295
|
it '!=' do
|
274
|
-
refute_equal(JSI::JSON::Node.new([0],
|
275
|
-
refute_equal(JSI::JSON::Node.new_doc([0]), JSI::JSON::Node.new({},
|
276
|
-
refute_equal(JSI::JSON::Node.new([0],
|
296
|
+
refute_equal(JSI::JSON::Node.new([0], pointer), JSI::JSON::Node.new({}, pointer))
|
297
|
+
refute_equal(JSI::JSON::Node.new_doc([0]), JSI::JSON::Node.new({}, pointer))
|
298
|
+
refute_equal(JSI::JSON::Node.new([0], pointer), JSI::JSON::Node.new_doc({}))
|
277
299
|
refute_equal(JSI::JSON::Node.new_doc([0]), JSI::JSON::Node.new_doc({}))
|
278
300
|
refute_equal({}, JSI::JSON::Node.new_doc({}))
|
279
301
|
refute_equal(JSI::JSON::Node.new_doc({}), {})
|
@@ -35,13 +35,13 @@ describe JSI::JSON::Pointer do
|
|
35
35
|
"/m~0n" , 8,
|
36
36
|
]
|
37
37
|
evaluations.each_slice(2) do |pointer, value|
|
38
|
-
assert_equal(value, JSI::JSON::Pointer.
|
38
|
+
assert_equal(value, JSI::JSON::Pointer.from_pointer(pointer).evaluate(document))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'raises for invalid syntax' do
|
43
43
|
err = assert_raises(JSI::JSON::Pointer::PointerSyntaxError) do
|
44
|
-
JSI::JSON::Pointer.
|
44
|
+
JSI::JSON::Pointer.from_pointer("this does not begin with slash").evaluate(document)
|
45
45
|
end
|
46
46
|
assert_equal("Invalid pointer syntax in \"this does not begin with slash\": pointer must begin with /", err.message)
|
47
47
|
end
|
@@ -80,19 +80,27 @@ describe JSI::JSON::Pointer do
|
|
80
80
|
'#/m~0n', 8,
|
81
81
|
]
|
82
82
|
evaluations.each_slice(2) do |fragment, value|
|
83
|
-
assert_equal(value, JSI::JSON::Pointer.
|
83
|
+
assert_equal(value, JSI::JSON::Pointer.from_fragment(fragment).evaluate(document))
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'raises for invalid syntax' do
|
88
88
|
err = assert_raises(JSI::JSON::Pointer::PointerSyntaxError) do
|
89
|
-
JSI::JSON::Pointer.
|
89
|
+
JSI::JSON::Pointer.from_fragment("this does not begin with #").evaluate(document)
|
90
90
|
end
|
91
91
|
assert_equal("Invalid fragment syntax in \"this does not begin with #\": fragment must begin with #", err.message)
|
92
92
|
err = assert_raises(JSI::JSON::Pointer::PointerSyntaxError) do
|
93
|
-
JSI::JSON::Pointer.
|
93
|
+
JSI::JSON::Pointer.from_fragment("#this does not begin with slash").evaluate(document)
|
94
94
|
end
|
95
95
|
assert_equal("Invalid pointer syntax in \"this does not begin with slash\": pointer must begin with /", err.message)
|
96
96
|
end
|
97
97
|
end
|
98
|
+
describe 'initialize' do
|
99
|
+
describe 'invalid reference_tokens' do
|
100
|
+
it 'raises' do
|
101
|
+
err = assert_raises(TypeError) { JSI::JSON::Pointer.new({}) }
|
102
|
+
assert_equal("reference_tokens must be an array. got: {}", err.message)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
98
106
|
end
|
data/test/schema_test.rb
CHANGED
@@ -17,7 +17,7 @@ describe JSI::Schema do
|
|
17
17
|
it 'initializes from a JSI' do
|
18
18
|
schema_jsi = SomeMetaschema.new('type' => 'object')
|
19
19
|
schema = JSI::Schema.new(schema_jsi)
|
20
|
-
assert_equal(schema_jsi
|
20
|
+
assert_equal(schema_jsi, schema.schema_node)
|
21
21
|
assert_equal(schema_jsi, schema.schema_object)
|
22
22
|
end
|
23
23
|
it 'cannot instantiate from some unknown object' do
|
@@ -167,27 +167,27 @@ describe JSI::Schema do
|
|
167
167
|
let(:schema) { JSI::Schema.new({id: 'https://schemas.jsi.unth.net/test/validation', type: 'object'}) }
|
168
168
|
describe 'without errors' do
|
169
169
|
let(:instance) { {'foo' => 'bar'} }
|
170
|
-
it '#
|
171
|
-
assert_equal([], schema.
|
170
|
+
it '#fully_validate_instance' do
|
171
|
+
assert_equal([], schema.fully_validate_instance(instance))
|
172
172
|
end
|
173
|
-
it '#
|
174
|
-
assert_equal(true, schema.
|
173
|
+
it '#validate_instance' do
|
174
|
+
assert_equal(true, schema.validate_instance(instance))
|
175
175
|
end
|
176
|
-
it '#
|
177
|
-
assert_equal(true, schema.
|
176
|
+
it '#validate_instance!' do
|
177
|
+
assert_equal(true, schema.validate_instance!(instance))
|
178
178
|
end
|
179
179
|
end
|
180
180
|
describe 'with errors' do
|
181
181
|
let(:instance) { ['no'] }
|
182
|
-
it '#
|
183
|
-
assert_equal(["The property '#/' of type array did not match the following type: object in schema https://schemas.jsi.unth.net/test/validation"], schema.
|
182
|
+
it '#fully_validate_instance' do
|
183
|
+
assert_equal(["The property '#/' of type array did not match the following type: object in schema https://schemas.jsi.unth.net/test/validation"], schema.fully_validate_instance(instance))
|
184
184
|
end
|
185
|
-
it '#
|
186
|
-
assert_equal(false, schema.
|
185
|
+
it '#validate_instance' do
|
186
|
+
assert_equal(false, schema.validate_instance(instance))
|
187
187
|
end
|
188
|
-
it '#
|
188
|
+
it '#validate_instance!' do
|
189
189
|
err = assert_raises(JSON::Schema::ValidationError) do
|
190
|
-
schema.
|
190
|
+
schema.validate_instance!(instance)
|
191
191
|
end
|
192
192
|
assert_equal("The property '#/' of type array did not match the following type: object", err.message)
|
193
193
|
end
|
data/test/test_helper.rb
CHANGED
@@ -2,8 +2,10 @@ require 'coveralls'
|
|
2
2
|
if Coveralls.will_run?
|
3
3
|
Coveralls.wear!
|
4
4
|
end
|
5
|
-
|
6
5
|
require 'simplecov'
|
6
|
+
|
7
|
+
require 'byebug'
|
8
|
+
|
7
9
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
8
10
|
require 'jsi'
|
9
11
|
|
@@ -16,8 +18,6 @@ require 'minitest/reporters'
|
|
16
18
|
|
17
19
|
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
18
20
|
|
19
|
-
require 'byebug'
|
20
|
-
|
21
21
|
class JSISpec < Minitest::Spec
|
22
22
|
if ENV['JSI_TEST_ALPHA']
|
23
23
|
# :nocov:
|
data/test/util_test.rb
CHANGED
@@ -6,23 +6,23 @@ describe JSI::Util do
|
|
6
6
|
assert_equal({'a' => 'b', 'c' => 'd', nil => 3}, JSI.stringify_symbol_keys({a: 'b', 'c' => 'd', nil => 3}))
|
7
7
|
end
|
8
8
|
it 'stringifies HashNode keys' do
|
9
|
-
actual = JSI.stringify_symbol_keys(JSI::JSON::
|
10
|
-
expected = JSI::JSON::
|
9
|
+
actual = JSI.stringify_symbol_keys(JSI::JSON::Node.new_doc({a: 'b', 'c' => 'd', nil => 3}))
|
10
|
+
expected = JSI::JSON::Node.new_doc({'a' => 'b', 'c' => 'd', nil => 3})
|
11
11
|
assert_equal(expected, actual)
|
12
12
|
end
|
13
13
|
it 'stringifies JSI hash keys' do
|
14
14
|
klass = JSI.class_for_schema(type: 'object')
|
15
|
-
expected = JSI.stringify_symbol_keys(klass.new(JSI::JSON::
|
16
|
-
actual = klass.new(JSI::JSON::
|
15
|
+
expected = JSI.stringify_symbol_keys(klass.new(JSI::JSON::Node.new_doc({a: 'b', 'c' => 'd', nil => 3})))
|
16
|
+
actual = klass.new(JSI::JSON::Node.new_doc({'a' => 'b', 'c' => 'd', nil => 3}))
|
17
17
|
assert_equal(expected, actual)
|
18
18
|
end
|
19
19
|
describe 'non-hash-like argument' do
|
20
20
|
it 'errors' do
|
21
21
|
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(nil) }
|
22
22
|
assert_equal("expected argument to be a hash; got NilClass: nil", err.message)
|
23
|
-
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI::JSON::Node.
|
23
|
+
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI::JSON::Node.new_doc(3)) }
|
24
24
|
assert_equal("expected argument to be a hash; got JSI::JSON::Node: #<JSI::JSON::Node fragment=\"#\" 3>", err.message)
|
25
|
-
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI.class_for_schema({}).new(JSI::JSON::Node.
|
25
|
+
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI.class_for_schema({}).new(JSI::JSON::Node.new_doc(3))) }
|
26
26
|
assert_match(%r(\Aexpected argument to be a hash; got JSI::SchemaClasses\["[^"]+#"\]: #<JSI::SchemaClasses\["[^"]+#"\]\n #<JSI::JSON::Node fragment="#" 3>\n>\z)m, err.message)
|
27
27
|
end
|
28
28
|
end
|
@@ -48,14 +48,14 @@ describe JSI::Util do
|
|
48
48
|
assert_equal(expected, actual)
|
49
49
|
end
|
50
50
|
it 'deep stringifies HashNode keys' do
|
51
|
-
actual = JSI.deep_stringify_symbol_keys(JSI::JSON::
|
52
|
-
expected = JSI::JSON::
|
51
|
+
actual = JSI.deep_stringify_symbol_keys(JSI::JSON::Node.new_doc({a: 'b', 'c' => {d: 0}, nil => 3}))
|
52
|
+
expected = JSI::JSON::Node.new_doc({'a' => 'b', 'c' => {'d' => 0}, nil => 3})
|
53
53
|
assert_equal(expected, actual)
|
54
54
|
end
|
55
55
|
it 'deep stringifies JSI instance' do
|
56
56
|
klass = JSI.class_for_schema(type: 'object')
|
57
|
-
actual = JSI.deep_stringify_symbol_keys(klass.new(JSI::JSON::
|
58
|
-
expected = klass.new(JSI::JSON::
|
57
|
+
actual = JSI.deep_stringify_symbol_keys(klass.new(JSI::JSON::Node.new_doc({a: 'b', 'c' => {d: 0}, nil => 3})))
|
58
|
+
expected = klass.new(JSI::JSON::Node.new_doc({'a' => 'b', 'c' => {'d' => 0}, nil => 3}))
|
59
59
|
assert_equal(expected, actual)
|
60
60
|
end
|
61
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -83,7 +83,7 @@ dependencies:
|
|
83
83
|
description: JSI represents json-schemas as ruby classes and json-schema instances
|
84
84
|
as instances of those classes
|
85
85
|
email:
|
86
|
-
- ethan@unth
|
86
|
+
- ethan@unth.net
|
87
87
|
executables: []
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
@@ -103,7 +103,10 @@ files:
|
|
103
103
|
- lib/jsi/json.rb
|
104
104
|
- lib/jsi/json/node.rb
|
105
105
|
- lib/jsi/json/pointer.rb
|
106
|
+
- lib/jsi/pathed_node.rb
|
106
107
|
- lib/jsi/schema.rb
|
108
|
+
- lib/jsi/schema_classes.rb
|
109
|
+
- lib/jsi/simple_wrap.rb
|
107
110
|
- lib/jsi/typelike_modules.rb
|
108
111
|
- lib/jsi/util.rb
|
109
112
|
- lib/jsi/version.rb
|
@@ -118,6 +121,7 @@ files:
|
|
118
121
|
- test/jsi_test.rb
|
119
122
|
- test/jsi_typelike_as_json_test.rb
|
120
123
|
- test/schema_test.rb
|
124
|
+
- test/spreedly_openapi_test.rb
|
121
125
|
- test/test_helper.rb
|
122
126
|
- test/util_test.rb
|
123
127
|
homepage: https://github.com/notEthan/jsi
|
@@ -156,5 +160,6 @@ test_files:
|
|
156
160
|
- test/jsi_test.rb
|
157
161
|
- test/jsi_typelike_as_json_test.rb
|
158
162
|
- test/schema_test.rb
|
163
|
+
- test/spreedly_openapi_test.rb
|
159
164
|
- test/test_helper.rb
|
160
165
|
- test/util_test.rb
|