json-schema 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
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.0.4.gem
25
+ $ gem install json-schema-2.0.5.gem
26
26
  </pre>
27
27
 
28
28
 
@@ -4,12 +4,16 @@ module JSON
4
4
  class Schema
5
5
  class AdditionalPropertiesAttribute < Attribute
6
6
  def self.validate(current_schema, data, fragments, processor, validator, options = {})
7
- if data.is_a?(Hash)
7
+ if data.is_a?(Hash) && (
8
+ current_schema.schema['type'].nil? || (
9
+ current_schema.schema['type'].is_a?(String) &&
10
+ current_schema.schema['type'].downcase == 'object'
11
+ )
12
+ )
8
13
  extra_properties = data.keys
9
-
10
14
  extra_properties = remove_valid_properties(extra_properties, current_schema, validator)
11
15
 
12
- addprop= current_schema.schema['additionalProperties']
16
+ addprop = current_schema.schema['additionalProperties']
13
17
  if addprop.is_a?(Hash)
14
18
  matching_properties= extra_properties # & addprop.keys
15
19
  matching_properties.each do |key|
@@ -57,6 +61,7 @@ module JSON
57
61
 
58
62
  extra_properties
59
63
  end
64
+
60
65
  end
61
66
  end
62
67
  end
@@ -204,9 +204,27 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
204
204
 
205
205
  data["a"] = {"b" => "taco"}
206
206
  assert(!JSON::Validator.validate(schema,data))
207
- end
208
207
 
208
+ # Test an array of unioned-type objects that prevent additionalProperties
209
+ schema["properties"]["a"] = {
210
+ 'type' => 'array',
211
+ 'items' => {
212
+ 'type' => [
213
+ { 'type' => 'object', 'properties' => { "b" => { "type" => "integer" } } },
214
+ { 'type' => 'object', 'properties' => { "c" => { "type" => "string" } } }
215
+ ],
216
+ 'additionalProperties' => false
217
+ }
218
+ }
219
+
220
+ data["a"] = [{"b" => 5}, {"c" => "foo"}]
221
+ errors = JSON::Validator.fully_validate(schema, data)
222
+ assert(errors.empty?, errors.join("\n"))
209
223
 
224
+ # This should actually pass, because this matches the first schema in the union
225
+ data["a"] << {"c" => false}
226
+ assert(JSON::Validator.validate(schema,data))
227
+ end
210
228
 
211
229
  def test_required
212
230
  # Set up the default datatype
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: 2.0.4
4
+ version: 2.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: