json-schema 0.9.10 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -1
- data/lib/json-schema/attributes/dependencies.rb +5 -3
- data/test/test_jsonschema_draft3.rb +35 -0
- metadata +4 -16
data/README.textile
CHANGED
@@ -5,9 +5,11 @@ module JSON
|
|
5
5
|
if data.is_a?(Hash)
|
6
6
|
current_schema.schema['dependencies'].each do |property,dependency_value|
|
7
7
|
if data.has_key?(property)
|
8
|
-
if dependency_value.is_a?(String)
|
9
|
-
|
10
|
-
|
8
|
+
if dependency_value.is_a?(String)
|
9
|
+
if !data.has_key?(dependency_value)
|
10
|
+
message = "The property '#{build_fragment(fragments)}' has a property '#{property}' that depends on a missing property '#{dependency_value}'"
|
11
|
+
raise ValidationError.new(message, fragments, current_schema)
|
12
|
+
end
|
11
13
|
elsif dependency_value.is_a?(Array)
|
12
14
|
dependency_value.each do |value|
|
13
15
|
if !data.has_key?(value)
|
@@ -932,6 +932,41 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
|
|
932
932
|
assert(JSON::Validator.validate(schema,data))
|
933
933
|
end
|
934
934
|
|
935
|
+
def test_dependency
|
936
|
+
schema = {
|
937
|
+
"type" => "object",
|
938
|
+
"properties" => {
|
939
|
+
"a" => {"type" => "integer"},
|
940
|
+
"b" => {"type" => "integer"}
|
941
|
+
},
|
942
|
+
"dependencies" => {
|
943
|
+
"a" => "b"
|
944
|
+
}
|
945
|
+
}
|
946
|
+
|
947
|
+
data = {"a" => 1, "b" => 2}
|
948
|
+
assert(JSON::Validator.validate(schema,data))
|
949
|
+
data = {"a" => 1}
|
950
|
+
assert(!JSON::Validator.validate(schema,data))
|
951
|
+
|
952
|
+
schema = {
|
953
|
+
"type" => "object",
|
954
|
+
"properties" => {
|
955
|
+
"a" => {"type" => "integer"},
|
956
|
+
"b" => {"type" => "integer"},
|
957
|
+
"c" => {"type" => "integer"}
|
958
|
+
},
|
959
|
+
"dependencies" => {
|
960
|
+
"a" => ["b","c"]
|
961
|
+
}
|
962
|
+
}
|
963
|
+
|
964
|
+
data = {"a" => 1, "c" => 2}
|
965
|
+
assert(!JSON::Validator.validate(schema,data))
|
966
|
+
data = {"a" => 1, "b" => 2, "c" => 3}
|
967
|
+
assert(JSON::Validator.validate(schema,data))
|
968
|
+
end
|
969
|
+
|
935
970
|
|
936
971
|
end
|
937
972
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 11
|
9
|
+
version: 0.9.11
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kenny Hoxworth
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-10-24 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -64,16 +64,6 @@ files:
|
|
64
64
|
- resources/draft-02.json
|
65
65
|
- resources/draft-03.json
|
66
66
|
- README.textile
|
67
|
-
- test/test_extended_schema.rb
|
68
|
-
- test/test_files.rb
|
69
|
-
- test/test_jsonschema_draft1.rb
|
70
|
-
- test/test_jsonschema_draft2.rb
|
71
|
-
- test/test_jsonschema_draft3.rb
|
72
|
-
- test/test_schema_validation.rb
|
73
|
-
- test/data/bad_data_1.json
|
74
|
-
- test/data/good_data_1.json
|
75
|
-
- test/schemas/good_schema_1.json
|
76
|
-
- test/schemas/good_schema_2.json
|
77
67
|
has_rdoc: true
|
78
68
|
homepage: http://github.com/hoxworth/json-schema/tree/master
|
79
69
|
licenses: []
|
@@ -84,7 +74,6 @@ rdoc_options: []
|
|
84
74
|
require_paths:
|
85
75
|
- lib
|
86
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
77
|
requirements:
|
89
78
|
- - ">="
|
90
79
|
- !ruby/object:Gem::Version
|
@@ -92,7 +81,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
81
|
- 0
|
93
82
|
version: "0"
|
94
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
84
|
requirements:
|
97
85
|
- - ">="
|
98
86
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
90
|
requirements: []
|
103
91
|
|
104
92
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.3.
|
93
|
+
rubygems_version: 1.3.6
|
106
94
|
signing_key:
|
107
95
|
specification_version: 3
|
108
96
|
summary: Ruby JSON Schema Validator
|