json_schema 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json_pointer/evaluator.rb +2 -2
- data/lib/json_schema.rb +1 -1
- data/lib/json_schema/document_store.rb +1 -1
- data/lib/json_schema/{schema_error.rb → error.rb} +16 -1
- data/lib/json_schema/parser.rb +1 -1
- data/lib/json_schema/reference_expander.rb +1 -1
- data/lib/json_schema/validator.rb +1 -1
- data/test/json_pointer/evaluator_test.rb +3 -3
- data/test/json_schema/parser_test.rb +12 -0
- data/test/json_schema/reference_expander_test.rb +15 -0
- data/test/json_schema/validator_test.rb +17 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ad0b2694247ed71b5163e4cb0e13799bc976c74
|
4
|
+
data.tar.gz: 8cb84d6e25a4badfd97a8b59dd81b75cb75bb88c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7db5975866312faf10720b8cc1e188f3fc8b12c2d06507dd3536411870e90ea9524f437400730071aff6687b38cc5616849ab47b22e257f60fee8ec7643e942c
|
7
|
+
data.tar.gz: 05d7b10c66a92eb00d6e3baafe1d37d5a471e7e25e0554b46a0922338703abc37523c55e36671b8e7b5517e3aa59654a591ba8cb621c3824527f60a11aaedc41
|
@@ -16,7 +16,7 @@ module JsonPointer
|
|
16
16
|
end
|
17
17
|
|
18
18
|
if path[0] != "/"
|
19
|
-
raise %{Path must begin with a leading "/": #{original_path}.}
|
19
|
+
raise ArgumentError, %{Path must begin with a leading "/": #{original_path}.}
|
20
20
|
end
|
21
21
|
|
22
22
|
path_parts = split(path)
|
@@ -35,7 +35,7 @@ module JsonPointer
|
|
35
35
|
key = transform_key(path_parts.shift)
|
36
36
|
if data.is_a?(Array)
|
37
37
|
unless key =~ /^\d+$/
|
38
|
-
raise %{Key operating on an array must be a digit or "-": #{key}.}
|
38
|
+
raise ArgumentError, %{Key operating on an array must be a digit or "-": #{key}.}
|
39
39
|
end
|
40
40
|
evaluate_segment(data[key.to_i], path_parts)
|
41
41
|
else
|
data/lib/json_schema.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require_relative "json_schema/configuration"
|
2
2
|
require_relative "json_schema/document_store"
|
3
|
+
require_relative "json_schema/error"
|
3
4
|
require_relative "json_schema/parser"
|
4
5
|
require_relative "json_schema/reference_expander"
|
5
6
|
require_relative "json_schema/schema"
|
6
|
-
require_relative "json_schema/schema_error"
|
7
7
|
require_relative "json_schema/validator"
|
8
8
|
|
9
9
|
module JsonSchema
|
@@ -1,5 +1,20 @@
|
|
1
1
|
module JsonSchema
|
2
|
-
class
|
2
|
+
class Error < RuntimeError
|
3
|
+
end
|
4
|
+
|
5
|
+
class AggregateError < Error
|
6
|
+
attr_accessor :errors
|
7
|
+
|
8
|
+
def initialize(errors)
|
9
|
+
@errors = errors
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
@errors.join(" ")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class SchemaError < Error
|
3
18
|
attr_accessor :message, :schema, :type
|
4
19
|
|
5
20
|
def self.aggregate(errors)
|
data/lib/json_schema/parser.rb
CHANGED
@@ -31,14 +31,14 @@ describe JsonPointer::Evaluator do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "raises when a path doesn't being with /" do
|
34
|
-
e = assert_raises(
|
34
|
+
e = assert_raises(ArgumentError) { @evaluator.evaluate("foo") }
|
35
35
|
assert_equal %{Path must begin with a leading "/": foo.}, e.message
|
36
|
-
e = assert_raises(
|
36
|
+
e = assert_raises(ArgumentError) { @evaluator.evaluate("#foo") }
|
37
37
|
assert_equal %{Path must begin with a leading "/": #foo.}, e.message
|
38
38
|
end
|
39
39
|
|
40
40
|
it "raises when a non-digit is specified on an array" do
|
41
|
-
e = assert_raises(
|
41
|
+
e = assert_raises(ArgumentError) { @evaluator.evaluate("/foo/bar") }
|
42
42
|
assert_equal %{Key operating on an array must be a digit or "-": bar.},
|
43
43
|
e.message
|
44
44
|
end
|
@@ -307,6 +307,18 @@ describe JsonSchema::Parser do
|
|
307
307
|
assert_includes error_types, :unknown_format
|
308
308
|
end
|
309
309
|
|
310
|
+
it "raises an aggregate error with parse!" do
|
311
|
+
schema_sample["id"] = 4
|
312
|
+
|
313
|
+
parser = JsonSchema::Parser.new
|
314
|
+
|
315
|
+
# don't bother checking the particulars of the error here because we have
|
316
|
+
# other tests for that above
|
317
|
+
assert_raises JsonSchema::AggregateError do
|
318
|
+
parser.parse!(schema_sample)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
310
322
|
def error_messages
|
311
323
|
@parser.errors.map { |e| e.message }
|
312
324
|
end
|
@@ -212,6 +212,21 @@ describe JsonSchema::ReferenceExpander do
|
|
212
212
|
assert_includes error_types, :unresolved_references
|
213
213
|
end
|
214
214
|
|
215
|
+
it "raises an aggregate error with expand!" do
|
216
|
+
pointer("#/properties").merge!(
|
217
|
+
"app" => { "$ref" => "#/definitions/nope" }
|
218
|
+
)
|
219
|
+
|
220
|
+
schema = JsonSchema::Parser.new.parse!(schema_sample)
|
221
|
+
expander = JsonSchema::ReferenceExpander.new
|
222
|
+
|
223
|
+
# don't bother checking the particulars of the error here because we have
|
224
|
+
# other tests for that above
|
225
|
+
assert_raises JsonSchema::AggregateError do
|
226
|
+
expander.expand!(schema)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
215
230
|
def error_messages
|
216
231
|
@expander.errors.map { |e| e.message }
|
217
232
|
end
|
@@ -841,6 +841,23 @@ describe JsonSchema::Validator do
|
|
841
841
|
assert_includes error_types, :invalid_format
|
842
842
|
end
|
843
843
|
|
844
|
+
it "raises an aggregate error with validate!" do
|
845
|
+
pointer("#/definitions/app").merge!(
|
846
|
+
"type" => ["object"]
|
847
|
+
)
|
848
|
+
|
849
|
+
schema = JsonSchema.parse!(schema_sample)
|
850
|
+
schema.expand_references!
|
851
|
+
schema = schema.definitions["app"]
|
852
|
+
validator = JsonSchema::Validator.new(schema)
|
853
|
+
|
854
|
+
# don't bother checking the particulars of the error here because we have
|
855
|
+
# other tests for that above
|
856
|
+
assert_raises JsonSchema::AggregateError do
|
857
|
+
validator.validate!(4)
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
844
861
|
def data_sample
|
845
862
|
@data_sample ||= DataScaffold.data_sample
|
846
863
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecma-re-validator
|
@@ -70,10 +70,10 @@ files:
|
|
70
70
|
- lib/json_schema.rb
|
71
71
|
- lib/json_schema/configuration.rb
|
72
72
|
- lib/json_schema/document_store.rb
|
73
|
+
- lib/json_schema/error.rb
|
73
74
|
- lib/json_schema/parser.rb
|
74
75
|
- lib/json_schema/reference_expander.rb
|
75
76
|
- lib/json_schema/schema.rb
|
76
|
-
- lib/json_schema/schema_error.rb
|
77
77
|
- lib/json_schema/validator.rb
|
78
78
|
- schemas/hyper-schema.json
|
79
79
|
- schemas/schema.json
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.4.5
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: A JSON Schema V4 and Hyperschema V4 parser and validator.
|