json-schema 2.2.0 → 2.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 +8 -8
- data/README.textile +12 -3
- data/lib/json-schema/attributes/properties.rb +14 -1
- data/lib/json-schema/attributes/properties_v4.rb +14 -1
- data/test/test_jsonschema_draft3.rb +30 -0
- data/test/test_jsonschema_draft4.rb +30 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTUxNTA3MTA3MmZmODJlZDJhYjk5NzIxM2FjNmY4MjdlODgzNDc0NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODJlOGI0OTMwNjU5OTU2OTFmMjg5MTE1ODlkYTFhNjI1NGY3ZjNjNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmE4OTAxOWJkNTc3ZTcyNWU3MTRkMDdkMzAxMjk2ZDc5ZTBiYTVmY2E5ZDY1
|
10
|
+
NWNjYWM1ZTMxMjU4ZjcyZmMwMWNjNjQ4ZTk1Y2QzNjBkZjRiYThlOTg1NjZk
|
11
|
+
YWI3MDEwYjRmNjBkZWNjZjIwNjBiZWJmNzZjNTVhODY2NDZlNmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGJlODg2YTY5MTgyOTRmYTRmNTMwMzNhOGI1ZDVkY2RhN2VjNzNiYTRjNmMz
|
14
|
+
NjA3NjI1ZDlkNzgxNzVkYzdiNGUzM2IwMTAwZTNjNzlmMWQyYjE2NjIzOTA1
|
15
|
+
NWEzNWU1ZWM0NGM2MjFiMzk3MDA1ODUyZDI2M2IyYjkyNWJmYTQ=
|
data/README.textile
CHANGED
@@ -22,7 +22,7 @@ From the git repo:
|
|
22
22
|
|
23
23
|
<pre>
|
24
24
|
$ gem build json-schema.gemspec
|
25
|
-
$ gem install json-schema-2.2.
|
25
|
+
$ gem install json-schema-2.2.1.gem
|
26
26
|
</pre>
|
27
27
|
|
28
28
|
|
@@ -82,8 +82,17 @@ With the <code>:strict</code>code> option, validation fails when an object conta
|
|
82
82
|
require 'rubygems'
|
83
83
|
require 'json-schema'
|
84
84
|
|
85
|
-
|
86
|
-
|
85
|
+
schema = {
|
86
|
+
"type" => "object",
|
87
|
+
"properties" => {
|
88
|
+
"a" => {"type" => "integer"},
|
89
|
+
"b" => {"type" => "integer"}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
JSON::Validator.validate(schema, {"a" => 1, "b" => 2}, :strict => true) # ==> true
|
94
|
+
JSON::Validator.validate(schema, {"a" => 1, "b" => 2, "c" => 3}, :strict => true) # ==> false
|
95
|
+
JSON::Validator.validate(schema, {"a" => 1}, :strict => true) # ==> false
|
87
96
|
</pre>
|
88
97
|
|
89
98
|
h3. Catch a validation error and print it out
|
@@ -30,7 +30,20 @@ module JSON
|
|
30
30
|
# When strict is true, ensure no undefined properties exist in the data
|
31
31
|
if (options[:strict] == true && !current_schema.schema.has_key?('additionalProperties'))
|
32
32
|
diff = data.select do |k,v|
|
33
|
-
|
33
|
+
if current_schema.schema.has_key?('patternProperties')
|
34
|
+
match = false
|
35
|
+
current_schema.schema['patternProperties'].each do |property,property_schema|
|
36
|
+
r = Regexp.new(property)
|
37
|
+
if r.match(k)
|
38
|
+
match = true
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
!current_schema.schema['properties'].has_key?(k.to_s) && !current_schema.schema['properties'].has_key?(k.to_sym) && !match
|
44
|
+
else
|
45
|
+
!current_schema.schema['properties'].has_key?(k.to_s) && !current_schema.schema['properties'].has_key?(k.to_sym)
|
46
|
+
end
|
34
47
|
end
|
35
48
|
|
36
49
|
if diff.size > 0
|
@@ -30,7 +30,20 @@ module JSON
|
|
30
30
|
# When strict is true, ensure no undefined properties exist in the data
|
31
31
|
if (options[:strict] == true && !current_schema.schema.has_key?('additionalProperties'))
|
32
32
|
diff = data.select do |k,v|
|
33
|
-
|
33
|
+
if current_schema.schema.has_key?('patternProperties')
|
34
|
+
match = false
|
35
|
+
current_schema.schema['patternProperties'].each do |property,property_schema|
|
36
|
+
r = Regexp.new(property)
|
37
|
+
if r.match(k)
|
38
|
+
match = true
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
!current_schema.schema['properties'].has_key?(k.to_s) && !current_schema.schema['properties'].has_key?(k.to_sym) && !match
|
44
|
+
else
|
45
|
+
!current_schema.schema['properties'].has_key?(k.to_s) && !current_schema.schema['properties'].has_key?(k.to_sym)
|
46
|
+
end
|
34
47
|
end
|
35
48
|
|
36
49
|
if diff.size > 0
|
@@ -528,7 +528,37 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
|
|
528
528
|
assert(JSON::Validator.validate(schema,data,:strict => true))
|
529
529
|
end
|
530
530
|
|
531
|
+
def test_strict_properties_pattern_props
|
532
|
+
schema = {
|
533
|
+
"$schema" => "http://json-schema.org/draft-03/schema#",
|
534
|
+
"properties" => {
|
535
|
+
"a" => {"type" => "string"},
|
536
|
+
"b" => {"type" => "string"}
|
537
|
+
},
|
538
|
+
"patternProperties" => {"\\d+ taco" => {"type" => "integer"}}
|
539
|
+
}
|
540
|
+
|
541
|
+
data = {"a" => "a"}
|
542
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
543
|
+
|
544
|
+
data = {"b" => "b"}
|
545
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
531
546
|
|
547
|
+
data = {"a" => "a", "b" => "b"}
|
548
|
+
assert(JSON::Validator.validate(schema,data,:strict => true))
|
549
|
+
|
550
|
+
data = {"a" => "a", "b" => "b", "c" => "c"}
|
551
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
552
|
+
|
553
|
+
data = {"a" => "a", "b" => "b", "c" => 3}
|
554
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
555
|
+
|
556
|
+
data = {"a" => "a", "b" => "b", "23 taco" => 3}
|
557
|
+
assert(JSON::Validator.validate(schema,data,:strict => true))
|
558
|
+
|
559
|
+
data = {"a" => "a", "b" => "b", "23 taco" => "cheese"}
|
560
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
561
|
+
end
|
532
562
|
|
533
563
|
def test_pattern
|
534
564
|
# Set up the default datatype
|
@@ -463,7 +463,37 @@ class JSONSchemaDraft4Test < Test::Unit::TestCase
|
|
463
463
|
assert(JSON::Validator.validate(schema,data,:strict => true))
|
464
464
|
end
|
465
465
|
|
466
|
+
def test_strict_properties_pattern_props
|
467
|
+
schema = {
|
468
|
+
"$schema" => "http://json-schema.org/draft-03/schema#",
|
469
|
+
"properties" => {
|
470
|
+
"a" => {"type" => "string"},
|
471
|
+
"b" => {"type" => "string"}
|
472
|
+
},
|
473
|
+
"patternProperties" => {"\\d+ taco" => {"type" => "integer"}}
|
474
|
+
}
|
466
475
|
|
476
|
+
data = {"a" => "a"}
|
477
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
478
|
+
|
479
|
+
data = {"b" => "b"}
|
480
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
481
|
+
|
482
|
+
data = {"a" => "a", "b" => "b"}
|
483
|
+
assert(JSON::Validator.validate(schema,data,:strict => true))
|
484
|
+
|
485
|
+
data = {"a" => "a", "b" => "b", "c" => "c"}
|
486
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
487
|
+
|
488
|
+
data = {"a" => "a", "b" => "b", "c" => 3}
|
489
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
490
|
+
|
491
|
+
data = {"a" => "a", "b" => "b", "23 taco" => 3}
|
492
|
+
assert(JSON::Validator.validate(schema,data,:strict => true))
|
493
|
+
|
494
|
+
data = {"a" => "a", "b" => "b", "23 taco" => "cheese"}
|
495
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
496
|
+
end
|
467
497
|
|
468
498
|
def test_unique_items
|
469
499
|
# Set up the default datatype
|