json-schema 1.2.0 → 1.2.1

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDQzOTViYTAzYzllZGY1OWQxMTE5NjczYzM0MTc1YTM5OTI4NDU3OA==
4
+ NjcxNmQ1MWU2ODRmMzM4MDE1NTQ3YzA1YWNhOWY2NjlkOTQ3OThjZg==
5
5
  data.tar.gz: !binary |-
6
- ZDNhMDY5MjQ4MDFmZDMzY2I2MGY4YjY4YTNkZGZiM2Q1YzM3OWVhMg==
6
+ MTZmY2FiYjI0OWJiMjlkNzFjZjA3ZjdkMWY1MGZmZGVhYzExMDVmZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDRhZjZlOTA3MWUxYjkwZjE1MDFjN2JlZjM1ZGE0ZDU5ZDE1NDVjMzE5NjQ2
10
- YjhkZTc4ZGU3MjNlYzA3ZmRlYzRjM2FiYWI4NzMxNzU5NTNkODYwODllZmY3
11
- ZmYxMDcyMTA0MTA3MjNiYzQ5YWE5ODVlNzk4ZjdmYmNmY2JiNzE=
9
+ NDc2NGZmMTdmMDM4NmQ2MzhmYTgyYzAxZGMzMGQ2ZWEwMzYxYzQ4OGZhNmRl
10
+ MGU1OWNjOWE4MzQ1MTc2ZTc5YzdlNDUxOWY4ZjZjMjU5MTNlYjAxMzFhOTVi
11
+ ZTlhYjQxYzA5OTg1Yjg0MTI3ZTgwZTAyNzgwOTU1MDFmYzY5ZDc=
12
12
  data.tar.gz: !binary |-
13
- YzY0MzlhNDM5MjUwYjczMjcwNTBjMmNjY2ExN2IwNDEzNDk2NzQ5YjUyMjY4
14
- NzRlODJhMmI5YTBjNmViNTZlOTYzZDI4YzE3YjA5YjE5N2Y1NDRhN2Q3ZTBh
15
- MDE0MzM2NGYwYjJlYzYxZTk3OWFmMWZkNWI2Y2UzMjM0M2Y5NjY=
13
+ N2NkYTNlYmIwNTkwZDdhYTk2Yzc1MjU5Y2E5MjUzZGQzZTYwZTkxNGIwZDhl
14
+ OWUxZjk0NGZhZTgwZDhiY2UxYzhhZDRhMWRjNGNhNTYyYTFmOGMzNmQxNWVi
15
+ YjhmMTg3MDJiY2VlN2I5MjRiMjAxZDQxNWE1YzZkOWNhZTEwYWY=
data/README.textile CHANGED
@@ -18,7 +18,7 @@ From the git repo:
18
18
 
19
19
  <pre>
20
20
  $ gem build json-schema.gemspec
21
- $ gem install json-schema-1.2.0.gem
21
+ $ gem install json-schema-1.2.1.gem
22
22
  </pre>
23
23
 
24
24
 
@@ -77,8 +77,17 @@ With the <code>:strict</code>code> option, validation fails when an object conta
77
77
  require 'rubygems'
78
78
  require 'json-schema'
79
79
 
80
- data = ['user','user','user']
81
- JSON::Validator.validate('user.json', data, :list => true)
80
+ schema = {
81
+ "type" => "object",
82
+ "properties" => {
83
+ "a" => {"type" => "integer"},
84
+ "b" => {"type" => "integer"}
85
+ }
86
+ }
87
+
88
+ JSON::Validator.validate(schema, {"a" => 1, "b" => 2}, :strict => true) # ==> true
89
+ JSON::Validator.validate(schema, {"a" => 1, "b" => 2, "c" => 3}, :strict => true) # ==> false
90
+ JSON::Validator.validate(schema, {"a" => 1}, :strict => true) # ==> false
82
91
  </pre>
83
92
 
84
93
  h3. Catch a validation error and print it out
@@ -25,7 +25,20 @@ module JSON
25
25
  # When strict is true, ensure no undefined properties exist in the data
26
26
  if (options[:strict] == true && !current_schema.schema.has_key?('additionalProperties'))
27
27
  diff = data.select do |k,v|
28
- !current_schema.schema['properties'].has_key?(k.to_s) && !current_schema.schema['properties'].has_key?(k.to_sym)
28
+ if current_schema.schema.has_key?('patternProperties')
29
+ match = false
30
+ current_schema.schema['patternProperties'].each do |property,property_schema|
31
+ r = Regexp.new(property)
32
+ if r.match(k)
33
+ match = true
34
+ break
35
+ end
36
+ end
37
+
38
+ !current_schema.schema['properties'].has_key?(k.to_s) && !current_schema.schema['properties'].has_key?(k.to_sym) && !match
39
+ else
40
+ !current_schema.schema['properties'].has_key?(k.to_s) && !current_schema.schema['properties'].has_key?(k.to_sym)
41
+ end
29
42
  end
30
43
 
31
44
  if diff.size > 0
@@ -510,6 +510,38 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
510
510
  assert(JSON::Validator.validate(schema,data,:strict => true))
511
511
  end
512
512
 
513
+ def test_strict_properties_pattern_props
514
+ schema = {
515
+ "$schema" => "http://json-schema.org/draft-03/schema#",
516
+ "properties" => {
517
+ "a" => {"type" => "string"},
518
+ "b" => {"type" => "string"}
519
+ },
520
+ "patternProperties" => {"\\d+ taco" => {"type" => "integer"}}
521
+ }
522
+
523
+ data = {"a" => "a"}
524
+ assert(!JSON::Validator.validate(schema,data,:strict => true))
525
+
526
+ data = {"b" => "b"}
527
+ assert(!JSON::Validator.validate(schema,data,:strict => true))
528
+
529
+ data = {"a" => "a", "b" => "b"}
530
+ assert(JSON::Validator.validate(schema,data,:strict => true))
531
+
532
+ data = {"a" => "a", "b" => "b", "c" => "c"}
533
+ assert(!JSON::Validator.validate(schema,data,:strict => true))
534
+
535
+ data = {"a" => "a", "b" => "b", "c" => 3}
536
+ assert(!JSON::Validator.validate(schema,data,:strict => true))
537
+
538
+ data = {"a" => "a", "b" => "b", "23 taco" => 3}
539
+ assert(JSON::Validator.validate(schema,data,:strict => true))
540
+
541
+ data = {"a" => "a", "b" => "b", "23 taco" => "cheese"}
542
+ assert(!JSON::Validator.validate(schema,data,:strict => true))
543
+ end
544
+
513
545
  def test_pattern
514
546
  # Set up the default datatype
515
547
  schema = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenny Hoxworth
OSZAR »