From 680174bd8a108280f97de5d8ba80883191d1d000 Mon Sep 17 00:00:00 2001 From: Daniel Draper Date: Thu, 26 Feb 2015 14:18:56 +1000 Subject: [PATCH 01/14] Expose clear_cache option --- lib/json-schema/validator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index c20971b7..a6544f22 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -46,6 +46,7 @@ def initialize(schema_data, data, opts={}) @validation_options = @options[:record_errors] ? {:record_errors => true} : {} @validation_options[:insert_defaults] = true if @options[:insert_defaults] @validation_options[:strict] = true if @options[:strict] == true + @validation_options[:clear_cache] = true if @options[:clear_cache] == true @@mutex.synchronize { @base_schema = initialize_schema(schema_data) } @original_data = data From fa316dc9d39b922935aed8ec9fa0e4139b724ef5 Mon Sep 17 00:00:00 2001 From: Daniel Draper Date: Fri, 27 Feb 2015 10:25:38 +1000 Subject: [PATCH 02/14] clear cache is true by default, changed assignment --- lib/json-schema/validator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index a6544f22..6453dade 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -46,7 +46,7 @@ def initialize(schema_data, data, opts={}) @validation_options = @options[:record_errors] ? {:record_errors => true} : {} @validation_options[:insert_defaults] = true if @options[:insert_defaults] @validation_options[:strict] = true if @options[:strict] == true - @validation_options[:clear_cache] = true if @options[:clear_cache] == true + @validation_options[:clear_cache] = false if @options[:clear_cache] == false @@mutex.synchronize { @base_schema = initialize_schema(schema_data) } @original_data = data From 6f76498f7f366e78af021484111ba7224f95eaa3 Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Sat, 28 Feb 2015 09:34:47 +0000 Subject: [PATCH 03/14] Removed test files from gemspec Should reduce the size of the gem. The default for new gems (created by bundler) is not to include test files. See https://github.com/bundler/bundler/pull/3207 --- json-schema.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/json-schema.gemspec b/json-schema.gemspec index 126153c3..1cc71dd7 100644 --- a/json-schema.gemspec +++ b/json-schema.gemspec @@ -13,7 +13,6 @@ Gem::Specification.new do |s| s.summary = "Ruby JSON Schema Validator" s.files = Dir[ "lib/**/*", "resources/*.json" ] s.require_path = "lib" - s.test_files = Dir[ "test/**/test*", "test/{data,schemas}/*.json" ] s.extra_rdoc_files = ["README.textile","LICENSE.md"] s.required_ruby_version = ">= 1.8.7" s.license = "MIT" From d5ffdad11b40922abfa64133e8d069d94e6440e0 Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Fri, 6 Mar 2015 17:18:21 +0900 Subject: [PATCH 04/14] Allow boolean false as a default property. --- lib/json-schema/attributes/properties.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/json-schema/attributes/properties.rb b/lib/json-schema/attributes/properties.rb index efa7249a..13c0f252 100644 --- a/lib/json-schema/attributes/properties.rb +++ b/lib/json-schema/attributes/properties.rb @@ -16,7 +16,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options if !data.key?(property) && options[:insert_defaults] && - property_schema['default'] && + property_schema.has_key?('default') && !property_schema['readonly'] default = property_schema['default'] data[property] = default.is_a?(Hash) ? default.clone : default From 637f89c74ea00e3aec084b7cb031ca922b00671a Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Fri, 6 Mar 2015 13:27:14 +0000 Subject: [PATCH 05/14] Use old hash syntax in tests Otherwise the ruby 1.8 travis build fails --- test/support/strict_validation.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/support/strict_validation.rb b/test/support/strict_validation.rb index cee8f9cc..06d9fd65 100644 --- a/test/support/strict_validation.rb +++ b/test/support/strict_validation.rb @@ -22,9 +22,9 @@ def test_strict_properties end def test_strict_error_message - schema = { type: 'object', properties: { a: { type: 'string' } } } - data = { a: 'abc', b: 'abc' } - errors = JSON::Validator.fully_validate(schema,data,strict: true) + schema = { :type => 'object', :properties => { :a => { :type => 'string' } } } + data = { :a => 'abc', :b => 'abc' } + errors = JSON::Validator.fully_validate(schema,data,:strict => true) assert_match("The property '#/' contained undefined properties: 'b' in schema", errors[0]) end From b1fa9c0491201b90c57e90cc4abd4945426e9fda Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Mon, 9 Mar 2015 17:13:13 +0900 Subject: [PATCH 06/14] Add test for boolean false as a default value --- test/test_jsonschema_draft4.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_jsonschema_draft4.rb b/test/test_jsonschema_draft4.rb index cdaf4f93..8ddb7e10 100644 --- a/test/test_jsonschema_draft4.rb +++ b/test/test_jsonschema_draft4.rb @@ -469,6 +469,24 @@ def test_default end + def test_boolean_false_default + schema = { + "$schema" => "http://json-schema.org/draft-04/schema#", + "type" => "object", + "required" => ["a"], + "properties" => { + "a" => {"type" => "boolean", "default" => false}, + "b" => {"type" => "integer"} + } + } + + data = {:b => 2} + refute_valid schema, data + assert_nil(data["a"]) + assert(JSON::Validator.validate(schema, data, :insert_defaults => true)) + assert_equal(false, data["a"]) + assert_equal(2, data[:b]) + end def test_all_of schema = { From 701a6e27b5c2be94fac3f39da8122ba8d38a2cf3 Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Tue, 10 Feb 2015 08:24:52 +0000 Subject: [PATCH 07/14] Enabled warnings when running tests --- Rakefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Rakefile b/Rakefile index a6a66259..55704a5b 100644 --- a/Rakefile +++ b/Rakefile @@ -14,6 +14,8 @@ end Rake::TestTask.new do |t| t.libs << "." + t.warning = true + t.verbose = true t.test_files = FileList['test/test*.rb'] end From c7dd2fcef1c0ffa85b9a21087b80512e388e27d5 Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Sun, 29 Mar 2015 09:34:51 +0100 Subject: [PATCH 08/14] Excluded test_helper.rb from the test files being run --- Rakefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 55704a5b..76591dd9 100644 --- a/Rakefile +++ b/Rakefile @@ -16,7 +16,9 @@ Rake::TestTask.new do |t| t.libs << "." t.warning = true t.verbose = true - t.test_files = FileList['test/test*.rb'] + t.test_files = FileList.new('test/test*.rb') do |fl| + fl.exclude(/test_helper\.rb$/) + end end task :test => :update_common_tests From 6905dcb295a8c1f46594f3fb29914fbb20e2b034 Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Sun, 29 Mar 2015 09:36:38 +0100 Subject: [PATCH 09/14] Specified addressable 2.3.8 as a dev dependency Older versions raised ruby warnings --- json-schema.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json-schema.gemspec b/json-schema.gemspec index 1cc71dd7..4c144529 100644 --- a/json-schema.gemspec +++ b/json-schema.gemspec @@ -23,5 +23,5 @@ Gem::Specification.new do |s| s.add_development_dependency "webmock" s.add_development_dependency "bundler" - s.add_runtime_dependency "addressable", '~> 2.3.7' + s.add_runtime_dependency "addressable", '~> 2.3.8' end From a71b74f7f25e8bea1f125ce45163da13a9ae372e Mon Sep 17 00:00:00 2001 From: JKGisMe Date: Fri, 10 Apr 2015 15:01:38 -0500 Subject: [PATCH 10/14] Explicitly notes :strict mode overrides any required properties set in the schema --- README.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.textile b/README.textile index d3acf465..42827d67 100644 --- a/README.textile +++ b/README.textile @@ -82,7 +82,7 @@ JSON::Validator.validate('user.json', data, :list => true) h3. Strictly validate an object's properties -With the :strict option, validation fails when an object contains properties that are not defined in the schema's property list or doesn't match the additionalProperties property. Furthermore, all properties are treated as required by default. +With the :strict option, validation fails when an object contains properties that are not defined in the schema's property list or doesn't match the additionalProperties property. Furthermore, all properties are treated as required regardless of required properties set in the schema.
 require 'rubygems'

From 21d22e4fd31d42683a535513bc36852fe29580fd Mon Sep 17 00:00:00 2001
From: James McKinney 
Date: Tue, 24 Nov 2015 03:08:24 -0500
Subject: [PATCH 11/14] Demonstrate failure to #register_format_validator on
 default_validator

---
 test/test_custom_format.rb | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/test/test_custom_format.rb b/test/test_custom_format.rb
index e7ab3cc6..a53f165a 100644
--- a/test/test_custom_format.rb
+++ b/test/test_custom_format.rb
@@ -3,7 +3,7 @@
 
 class JSONSchemaCustomFormatTest < Minitest::Test
   def setup
-    @all_versions = ['draft1', 'draft2', 'draft3', 'draft4']
+    @all_versions = ['draft1', 'draft2', 'draft3', 'draft4', nil]
     @format_proc = lambda { |value| raise JSON::Schema::CustomFormatError.new("must be 42") unless value == "42" }
     @schema_4 = {
       "$schema" => "http://json-schema.org/draft-04/schema#",
@@ -20,36 +20,37 @@ def setup
     @schema_2["$schema"] = "http://json-schema.org/draft-02/schema#"
     @schema_1 = @schema_4.clone
     @schema_1["$schema"] = "http://json-schema.org/draft-01/schema#"
+    @default = @schema_4.clone
     @schemas = {
       "draft1" => @schema_1,
       "draft2" => @schema_2,
       "draft3" => @schema_3,
-      "draft4" => @schema_4
+      "draft4" => @schema_4,
     }
     JSON::Validator.restore_default_formats
   end
 
   def test_single_registration
     @all_versions.each do |version|
-      assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' for #{version} should be nil")
+      assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' for #{version || 'default'} should be nil")
       JSON::Validator.register_format_validator("custom", @format_proc, [version])
-      assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version}")
+      assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version || 'default'}")
       (@all_versions - [version]).each do |other_version|
-        assert(JSON::Validator.validator_for_name(other_version).formats['custom'].nil?, "Format 'custom' should still be nil for #{other_version}")
+        assert(JSON::Validator.validator_for_name(other_version).formats['custom'].nil?, "Format 'custom' should still be nil for #{other_version || 'default'}")
       end
       JSON::Validator.deregister_format_validator("custom", [version])
-      assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' should be deregistered for #{version}")
+      assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' should be deregistered for #{version || 'default'}")
     end
   end
 
   def test_register_for_all_by_default
     JSON::Validator.register_format_validator("custom", @format_proc)
     @all_versions.each do |version|
-      assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version}")
+      assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version || 'default'}")
     end
     JSON::Validator.restore_default_formats
     @all_versions.each do |version|
-      assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' should still be nil for #{version}")
+      assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' should still be nil for #{version || 'default'}")
     end
   end
 
@@ -57,18 +58,18 @@ def test_multi_registration
     unregistered_version = @all_versions.delete("draft1")
     JSON::Validator.register_format_validator("custom", @format_proc, @all_versions)
     @all_versions.each do |version|
-      assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version}")
+      assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version || 'default'}")
     end
     assert(JSON::Validator.validator_for_name(unregistered_version).formats['custom'].nil?, "Format 'custom' should still be nil for #{unregistered_version}")
   end
 
   def test_format_validation
-    @all_versions.each do |version|
+    (@all_versions - [nil]).each do |version|
       data = {
         "a" => "23"
       }
       schema = @schemas[version]
-      prefix = "Validation for '#{version}'"
+      prefix = "Validation for '#{version || 'default'}'"
 
       assert(JSON::Validator.validate(schema, data), "#{prefix} succeeds with no 'custom' format validator registered")
 
@@ -89,13 +90,13 @@ def test_format_validation
   end
 
   def test_override_default_format
-    @all_versions.each do |version|
+    (@all_versions - [nil]).each do |version|
       data = {
         "a" => "2001:db8:85a3:0:0:8a2e:370:7334"
       }
       schema = @schemas[version]
       schema["properties"]["a"]["format"] = "ipv6"
-      prefix = "Validation for '#{version}'"
+      prefix = "Validation for '#{version || 'default'}'"
 
       assert(JSON::Validator.validate(schema, data), "#{prefix} succeeds for default format with correct data")
 

From 84012d872b21d9be584aeba16a3e7fae6c0ff11d Mon Sep 17 00:00:00 2001
From: James McKinney 
Date: Tue, 24 Nov 2015 03:09:01 -0500
Subject: [PATCH 12/14] register_format_validator on default_validator

---
 lib/json-schema/validator.rb | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb
index 6453dade..e22943ee 100644
--- a/lib/json-schema/validator.rb
+++ b/lib/json-schema/validator.rb
@@ -373,20 +373,20 @@ def register_default_validator(v)
         @@default_validator = v
       end
 
-      def register_format_validator(format, validation_proc, versions = ["draft1", "draft2", "draft3", "draft4"])
+      def register_format_validator(format, validation_proc, versions = ["draft1", "draft2", "draft3", "draft4", nil])
         custom_format_validator = JSON::Schema::CustomFormat.new(validation_proc)
         validators_for_names(versions).each do |validator|
           validator.formats[format.to_s] = custom_format_validator
         end
       end
 
-      def deregister_format_validator(format, versions = ["draft1", "draft2", "draft3", "draft4"])
+      def deregister_format_validator(format, versions = ["draft1", "draft2", "draft3", "draft4", nil])
         validators_for_names(versions).each do |validator|
           validator.formats[format.to_s] = validator.default_formats[format.to_s]
         end
       end
 
-      def restore_default_formats(versions = ["draft1", "draft2", "draft3", "draft4"])
+      def restore_default_formats(versions = ["draft1", "draft2", "draft3", "draft4", nil])
         validators_for_names(versions).each do |validator|
           validator.formats = validator.default_formats.clone
         end
@@ -482,9 +482,16 @@ def merge_missing_values(source, destination)
       private
 
       def validators_for_names(names)
-        names.map! { |name| name.to_s }
-        validators.reduce([]) do |memo, (_, validator)|
-          memo.tap { |m| m << validator if (validator.names & names).any? }
+        names = names.map { |name| name.to_s }
+        [].tap do |memo|
+          validators.each do |_, validator|
+            if (validator.names & names).any?
+              memo << validator
+            end
+          end
+          if names.include?('')
+            memo << default_validator
+          end
         end
       end
     end

From 8960753d88011afdfc9c0f2b9e4c78cbbb00309b Mon Sep 17 00:00:00 2001
From: James McKinney 
Date: Tue, 24 Nov 2015 03:31:12 -0500
Subject: [PATCH 13/14] Add a schema for default_validator in
 test_custom_format

---
 test/test-suite            | 2 +-
 test/test_custom_format.rb | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/test/test-suite b/test/test-suite
index 8f867168..5bcf11a5 160000
--- a/test/test-suite
+++ b/test/test-suite
@@ -1 +1 @@
-Subproject commit 8f867168d17497a775141704960906db83634a04
+Subproject commit 5bcf11a510da88290375a6cbacf957f33bffa6de
diff --git a/test/test_custom_format.rb b/test/test_custom_format.rb
index a53f165a..fb689646 100644
--- a/test/test_custom_format.rb
+++ b/test/test_custom_format.rb
@@ -21,11 +21,13 @@ def setup
     @schema_1 = @schema_4.clone
     @schema_1["$schema"] = "http://json-schema.org/draft-01/schema#"
     @default = @schema_4.clone
+    @default.delete("$schema")
     @schemas = {
       "draft1" => @schema_1,
       "draft2" => @schema_2,
       "draft3" => @schema_3,
       "draft4" => @schema_4,
+      nil => @default,
     }
     JSON::Validator.restore_default_formats
   end

From fa7776dd7eaadd49ec43093ae9fcfbcedf698af1 Mon Sep 17 00:00:00 2001
From: Kenny Hoxworth 
Date: Tue, 24 Nov 2015 08:38:25 -0800
Subject: [PATCH 14/14] Bump version

---
 README.textile  | 2 +-
 VERSION.yml     | 2 +-
 test/test-suite | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/README.textile b/README.textile
index 42827d67..0f207b7f 100644
--- a/README.textile
+++ b/README.textile
@@ -26,7 +26,7 @@ From the git repo:
 
 
 $ gem build json-schema.gemspec
-$ gem install json-schema-2.5.0.gem
+$ gem install json-schema-2.5.2.gem
 
diff --git a/VERSION.yml b/VERSION.yml index 10e76f93..1d7cbb09 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,3 +1,3 @@ major: 2 minor: 5 -patch: 1 +patch: 2 diff --git a/test/test-suite b/test/test-suite index 5bcf11a5..c73cf222 160000 --- a/test/test-suite +++ b/test/test-suite @@ -1 +1 @@ -Subproject commit 5bcf11a510da88290375a6cbacf957f33bffa6de +Subproject commit c73cf2225e3be05ba0a455e990309539c49ebc51