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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a228323c155619099b250dca5490ad4a133c8c5
4
- data.tar.gz: f4f387127f174dd6e7bf70dc083683e21e267f8d
3
+ metadata.gz: 3ad0b2694247ed71b5163e4cb0e13799bc976c74
4
+ data.tar.gz: 8cb84d6e25a4badfd97a8b59dd81b75cb75bb88c
5
5
  SHA512:
6
- metadata.gz: 1221fc9ae3074dfbf3696e95264f5991dc31d6eb19fe391e6945f5ea41c86a8c50e07bcda4b48ea89ffa38c35fd8781e57075a81af6bf073742676a9396caca1
7
- data.tar.gz: 3b53f66e639b027b4fb482b32c6132d9c91003713519250bb6b75d0a52d06002007ee35042abda4157e37ab077e5e23214bcafeb1141347db9c15cdfd23e531e
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
@@ -13,7 +13,7 @@ module JsonSchema
13
13
  end
14
14
 
15
15
  def add_schema(schema)
16
- raise "can't add nil URI" if schema.uri.nil?
16
+ raise ArgumentError, "can't add nil URI" if schema.uri.nil?
17
17
  uri = schema.uri.chomp('#')
18
18
  @schema_map[uri] = schema
19
19
  end
@@ -1,5 +1,20 @@
1
1
  module JsonSchema
2
- class SchemaError
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)
@@ -37,7 +37,7 @@ module JsonSchema
37
37
  def parse!(data, parent = nil)
38
38
  schema = parse(data, parent)
39
39
  if !schema
40
- raise @errors.join(" ")
40
+ raise AggregateError.new(@errors)
41
41
  end
42
42
  schema
43
43
  end
@@ -33,7 +33,7 @@ module JsonSchema
33
33
 
34
34
  def expand!(schema, options = {})
35
35
  if !expand(schema, options)
36
- raise @errors.join(" ")
36
+ raise AggregateError.new(@errors)
37
37
  end
38
38
  true
39
39
  end
@@ -27,7 +27,7 @@ module JsonSchema
27
27
 
28
28
  def validate!(data)
29
29
  if !validate(data)
30
- raise @errors.join(" ")
30
+ raise AggregateError.new(@errors)
31
31
  end
32
32
  end
33
33
 
@@ -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(RuntimeError) { @evaluator.evaluate("foo") }
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(RuntimeError) { @evaluator.evaluate("#foo") }
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(RuntimeError) { @evaluator.evaluate("/foo/bar") }
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.11.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-16 00:00:00.000000000 Z
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.2.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.