diff --git a/CHANGELOG.md b/CHANGELOG.md index bbd78151..cd1b1f34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Made sure we really do clear the cache when instructed to +- It's now possible to use reserved words in property names +- Removed support for setting "extends" to a string (it's invalid json-schema - use a "$ref" instead) ### Changed - Made all `validate*` methods on `JSON::Validator` ultimately call `validate!` diff --git a/lib/json-schema/attributes/additionalproperties.rb b/lib/json-schema/attributes/additionalproperties.rb index 331e681c..82793beb 100644 --- a/lib/json-schema/attributes/additionalproperties.rb +++ b/lib/json-schema/attributes/additionalproperties.rb @@ -14,7 +14,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options if addprop.is_a?(Hash) matching_properties = extra_properties # & addprop.keys matching_properties.each do |key| - additional_property_schema = JSON::Schema.new(addprop[key] || addprop, current_schema.uri, validator) + additional_property_schema = JSON::Schema.new(addprop, current_schema.uri, validator) additional_property_schema.validate(data[key], fragments + [key], processor, options) end extra_properties -= matching_properties diff --git a/lib/json-schema/attributes/extends.rb b/lib/json-schema/attributes/extends.rb index 38040f16..992b18d4 100644 --- a/lib/json-schema/attributes/extends.rb +++ b/lib/json-schema/attributes/extends.rb @@ -24,8 +24,6 @@ def self.validate(current_schema, data, fragments, processor, validator, options def self.get_extended_uri_and_schema(s, current_schema, validator) uri,schema = nil,nil - s = {'$ref' => s} if s.is_a?(String) - if s.is_a?(Hash) uri = current_schema.uri if s['$ref'] diff --git a/test/draft4_test.rb b/test/draft4_test.rb index c27995a7..a93b4b12 100644 --- a/test/draft4_test.rb +++ b/test/draft4_test.rb @@ -284,6 +284,20 @@ def test_self_reference refute_valid schema, {"a" => 5, "b" => {"b" => {"a" => 'taco'}}} end + def test_property_named_ref + schema = { + "$schema" => "http://json-schema.org/draft-04/schema#", + "properties" => { + "$ref" => { + "type" => "integer" + } + } + } + + assert_valid schema, { "$ref" => 1 } + refute_valid schema, { "$ref" => "#" } + end + def test_format_datetime schema = { "$schema" => "http://json-schema.org/draft-04/schema#", diff --git a/test/extends_nested_test.rb b/test/extends_nested_test.rb index 2e409e04..dec3f9ab 100644 --- a/test/extends_nested_test.rb +++ b/test/extends_nested_test.rb @@ -4,7 +4,7 @@ class ExtendsNestedTest < Minitest::Test def assert_validity(valid, schema_name, data, msg) msg = "Schema should be #{valid ? :valid : :invalid}.\n(#{schema_name}) #{msg}" - schema = schema_fixture_path("#{schema_name}.schema.json") + schema = schema_fixture_path("#{schema_name}_schema.json") errors = JSON::Validator.fully_validate(schema, data) if valid @@ -15,10 +15,8 @@ def assert_validity(valid, schema_name, data, msg) end %w[ - extends_and_additionalProperties-1-filename - extends_and_additionalProperties-1-ref - extends_and_additionalProperties-2-filename - extends_and_additionalProperties-2-ref + extends_and_additionalProperties_false + extends_and_patternProperties ].each do |schema_name| test_prefix = 'test_' + schema_name.gsub('-','_') @@ -40,7 +38,7 @@ def #{test_prefix}_invalid_inner end EOB - if schema_name['extends_and_additionalProperties-1'] + if schema_name['extends_and_additionalProperties_false'] class_eval <<-EOB def #{test_prefix}_invalid_outer assert_validity false, '#{schema_name}', {"whaaaaat"=>true}, "Outer defn allowing anything when it shouldn't" diff --git a/test/schemas/extends_and_additionalProperties-1-ref.schema.json b/test/schemas/extends_and_additionalProperties-1-ref.schema.json deleted file mode 100644 index 9be3b235..00000000 --- a/test/schemas/extends_and_additionalProperties-1-ref.schema.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "extends": {"$ref":"inner.schema.json#"}, - "properties": { - "outerA": { - "description": "blah", - "required": false, - "additionalProperties": false, - "properties": { - "outerA1": { - "type":"boolean", - "required": false - } - } - }, - "outerB": { - "required": false, - "type": "array", - "minItems": 1, - "maxItems": 50, - "items": { - "extends": {"$ref":"inner.schema.json#"}, - "additionalProperties": false - } - }, - "outerC": { - "description": "blah", - "type":"boolean", - "required": false - } - }, - "additionalProperties": false -} diff --git a/test/schemas/extends_and_additionalProperties-2-ref.schema.json b/test/schemas/extends_and_additionalProperties-2-ref.schema.json deleted file mode 100644 index 0b05c9be..00000000 --- a/test/schemas/extends_and_additionalProperties-2-ref.schema.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "extends": {"$ref":"inner.schema.json#"}, - "additionalProperties": { - "outerA": { - "description": "blah", - "required": false, - "additionalProperties": false, - "properties": { - "outerA1": { - "type":"boolean", - "required": false - } - } - }, - "outerB": { - "required": false, - "type": "array", - "minItems": 1, - "maxItems": 50, - "items": { - "extends": {"$ref":"inner.schema.json#"}, - "additionalProperties": false - } - }, - "outerC": { - "description": "blah", - "type":"boolean", - "required": false - } - } -} diff --git a/test/schemas/extends_and_additionalProperties-1-filename.schema.json b/test/schemas/extends_and_additionalProperties_false_schema.json similarity index 87% rename from test/schemas/extends_and_additionalProperties-1-filename.schema.json rename to test/schemas/extends_and_additionalProperties_false_schema.json index 507d9cc8..70dc901f 100644 --- a/test/schemas/extends_and_additionalProperties-1-filename.schema.json +++ b/test/schemas/extends_and_additionalProperties_false_schema.json @@ -1,7 +1,7 @@ { "$schema": "http://json-schema.org/draft-03/schema#", "type": "object", - "extends": "inner.schema.json", + "extends": {"$ref":"inner_schema.json#"}, "properties": { "outerA": { "description": "blah", @@ -20,7 +20,7 @@ "minItems": 1, "maxItems": 50, "items": { - "extends": "inner.schema.json", + "extends": {"$ref":"inner_schema.json#"}, "additionalProperties": false } }, diff --git a/test/schemas/extends_and_additionalProperties-2-filename.schema.json b/test/schemas/extends_and_patternProperties_schema.json similarity index 83% rename from test/schemas/extends_and_additionalProperties-2-filename.schema.json rename to test/schemas/extends_and_patternProperties_schema.json index ec6363c8..0d9799a0 100644 --- a/test/schemas/extends_and_additionalProperties-2-filename.schema.json +++ b/test/schemas/extends_and_patternProperties_schema.json @@ -1,8 +1,8 @@ { "$schema": "http://json-schema.org/draft-03/schema#", "type": "object", - "extends": "inner.schema.json", - "additionalProperties": { + "extends": {"$ref":"inner_schema.json#"}, + "patternProperties": { "outerA": { "description": "blah", "required": false, @@ -20,7 +20,7 @@ "minItems": 1, "maxItems": 50, "items": { - "extends": "inner.schema.json", + "extends": {"$ref":"inner_schema.json#"}, "additionalProperties": false } }, diff --git a/test/schemas/inner.schema.json b/test/schemas/inner_schema.json similarity index 100% rename from test/schemas/inner.schema.json rename to test/schemas/inner_schema.json diff --git a/test/test-suite b/test/test-suite index 9355965c..5fb3d9f1 160000 --- a/test/test-suite +++ b/test/test-suite @@ -1 +1 @@ -Subproject commit 9355965c517b91ec586aaaf301cc619d0e3001d2 +Subproject commit 5fb3d9f1a1c4136f544fbd0029942ea559732f8e