json-schema 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ module JSON
15
15
  if @schema['id']
16
16
  temp_uri = URI.parse(@schema['id'])
17
17
  if temp_uri.relative?
18
- uri.path = (Pathname.new(uri.path).parent + @schema['id']).cleanpath
18
+ uri.path = (Pathname.new(uri.path).parent + @schema['id']).cleanpath.to_s
19
19
  temp_uri = uri
20
20
  end
21
21
  @uri = temp_uri
@@ -15,6 +15,9 @@ module JSON
15
15
  super(message)
16
16
  end
17
17
  end
18
+
19
+ class SchemaError < Exception
20
+ end
18
21
 
19
22
  class Validator
20
23
 
@@ -197,7 +200,7 @@ module JSON
197
200
 
198
201
  # Validate the minimum number of items in an array
199
202
  def validate_minItems(current_schema, data, fragments)
200
- if data.is_a?(Array) && (data.nitems < current_schema.schema['minItems'])
203
+ if data.is_a?(Array) && (data.compact.size < current_schema.schema['minItems'])
201
204
  message = "The property '#{build_fragment(fragments)}' did not contain a minimum number of items #{current_schema.schema['minItems']}"
202
205
  raise ValidationError.new(message, fragments, current_schema)
203
206
  end
@@ -206,7 +209,7 @@ module JSON
206
209
 
207
210
  # Validate the maximum number of items in an array
208
211
  def validate_maxItems(current_schema, data, fragments)
209
- if data.is_a?(Array) && (data.nitems > current_schema.schema['maxItems'])
212
+ if data.is_a?(Array) && (data.compact.size > current_schema.schema['maxItems'])
210
213
  message = "The property '#{build_fragment(fragments)}' did not contain a minimum number of items #{current_schema.schema['minItems']}"
211
214
  raise ValidationError.new(message, fragments, current_schema)
212
215
  end
@@ -456,9 +459,9 @@ module JSON
456
459
  # Check for absolute path
457
460
  path = current_schema.schema['$ref'].split("#")[0]
458
461
  if path[0,1] == "/"
459
- temp_uri.path = Pathname.new(path).cleanpath
462
+ temp_uri.path = Pathname.new(path).cleanpath.to_s
460
463
  else
461
- temp_uri.path = (Pathname.new(current_schema.uri.path).parent + path).cleanpath
464
+ temp_uri.path = (Pathname.new(current_schema.uri.path).parent + path).cleanpath.to_s
462
465
  end
463
466
  temp_uri.fragment = current_schema.schema['$ref'].split("#")[1]
464
467
  end
@@ -472,6 +475,7 @@ module JSON
472
475
  # Perform fragment resolution to retrieve the appropriate level for the schema
473
476
  target_schema = ref_schema.schema
474
477
  fragments = temp_uri.fragment.split("/")
478
+ fragment_path = ''
475
479
  fragments.each do |fragment|
476
480
  if fragment && fragment != ''
477
481
  if target_schema.is_a?(Array)
@@ -479,6 +483,10 @@ module JSON
479
483
  else
480
484
  target_schema = target_schema[fragment]
481
485
  end
486
+ fragment_path = fragment_path + "/#{fragment}"
487
+ if target_schema.nil?
488
+ raise SchemaError.new("The fragment '#{fragment_path}' does not exist on schema #{ref_schema.uri.to_s}")
489
+ end
482
490
  end
483
491
  end
484
492
 
@@ -503,9 +511,9 @@ module JSON
503
511
  # Check for absolute path
504
512
  path = ref.split("#")[0]
505
513
  if path[0,1] == '/'
506
- uri.path = Pathname.new(path).cleanpath
514
+ uri.path = Pathname.new(path).cleanpath.to_s
507
515
  else
508
- uri.path = (Pathname.new(parent_schema.uri.path).parent + path).cleanpath
516
+ uri.path = (Pathname.new(parent_schema.uri.path).parent + path).cleanpath.to_s
509
517
  end
510
518
  uri.fragment = nil
511
519
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 9
10
- version: 0.1.9
9
+ - 10
10
+ version: 0.1.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kenny Hoxworth
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-14 00:00:00 -05:00
18
+ date: 2011-01-09 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency