From d921a08d5d5230ba2e5a212c92971812aba6cf01 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 12:26:35 +0100 Subject: [PATCH 1/8] rubocop: Fix Layout/HashAlignment --- .rubocop_todo.yml | 13 ------------- test/draft4_test.rb | 20 ++++++++++---------- test/support/string_validation.rb | 2 +- test/support/type_validation.rb | 10 +++++----- test/uri_parsing_test.rb | 24 ++++++++++++------------ 5 files changed, 28 insertions(+), 41 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4c5c26bb..485ccc1c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,19 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 28 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'test/draft4_test.rb' - - 'test/support/string_validation.rb' - - 'test/support/type_validation.rb' - - 'test/uri_parsing_test.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/test/draft4_test.rb b/test/draft4_test.rb index b91bf61b..df256cb3 100644 --- a/test/draft4_test.rb +++ b/test/draft4_test.rb @@ -391,18 +391,18 @@ def test_dependency def test_schema_dependency schema = { - 'type'=> 'object', - 'properties'=> { - 'name'=> { 'type'=> 'string' }, - 'credit_card'=> { 'type'=> 'number' }, + 'type' => 'object', + 'properties' => { + 'name' => { 'type'=> 'string' }, + 'credit_card' => { 'type'=> 'number' }, }, - 'required'=> ['name'], - 'dependencies'=> { - 'credit_card'=> { - 'properties'=> { - 'billing_address'=> { 'type'=> 'string' }, + 'required' => ['name'], + 'dependencies' => { + 'credit_card' => { + 'properties' => { + 'billing_address' => { 'type'=> 'string' }, }, - 'required'=> ['billing_address'], + 'required' => ['billing_address'], }, }, } diff --git a/test/support/string_validation.rb b/test/support/string_validation.rb index d374c537..f1c49871 100644 --- a/test/support/string_validation.rb +++ b/test/support/string_validation.rb @@ -65,7 +65,7 @@ def test_format_union schema = { 'properties' => { 'a' => { - 'type' => ['string', 'null'], + 'type' => ['string', 'null'], 'format' => 'date-time', }, }, diff --git a/test/support/type_validation.rb b/test/support/type_validation.rb index 35fba77f..0d229b55 100644 --- a/test/support/type_validation.rb +++ b/test/support/type_validation.rb @@ -4,12 +4,12 @@ module TypeValidation module SimpleTypeTests TYPES = { 'integer' => 5, - 'number' => 5.0, - 'string' => 'str', + 'number' => 5.0, + 'string' => 'str', 'boolean' => true, - 'object' => {}, - 'array' => [], - 'null' => nil, + 'object' => {}, + 'array' => [], + 'null' => nil, } TYPES.each do |name, value| diff --git a/test/uri_parsing_test.rb b/test/uri_parsing_test.rb index 4141ca4a..3637c8f9 100644 --- a/test/uri_parsing_test.rb +++ b/test/uri_parsing_test.rb @@ -5,8 +5,8 @@ class UriParsingTest < Minitest::Test def test_asian_characters schema = { - '$schema'=> 'http://json-schema.org/draft-04/schema#', - 'id'=> 'http://俺:鍵@例え.テスト/p?条件#ここ#', + '$schema' => 'http://json-schema.org/draft-04/schema#', + 'id' => 'http://俺:鍵@例え.テスト/p?条件#ここ#', 'type' => 'object', 'required' => ['a'], 'properties' => { @@ -25,11 +25,11 @@ def test_schema_ref_with_empty_fragment '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'required' => ['names'], - 'properties'=> { - 'names'=> { - 'type'=> 'array', - 'items'=> { - 'anyOf'=> [ + 'properties' => { + 'names' => { + 'type' => 'array', + 'items' => { + 'anyOf' => [ { '$ref' => 'test/schemas/ref john with spaces schema.json#' }, ], }, @@ -45,11 +45,11 @@ def test_schema_ref_from_file_with_spaces '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'required' => ['names'], - 'properties'=> { - 'names'=> { - 'type'=> 'array', - 'items'=> { - 'anyOf'=> [ + 'properties' => { + 'names' => { + 'type' => 'array', + 'items' => { + 'anyOf' => [ { '$ref' => 'test/schemas/ref john with spaces schema.json' }, ], }, From 5eb8ee1a437b8309282b773701fb23c3adb068a2 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 12:27:13 +0100 Subject: [PATCH 2/8] rubocop: Fix Layout/MultilineOperationIndentation --- .rubocop_todo.yml | 8 -------- lib/json-schema/attributes/properties.rb | 6 +++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 485ccc1c..e6637bd6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,14 +14,6 @@ Layout/MultilineMethodCallBraceLayout: Exclude: - 'test/common_test_suite_test.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented -Layout/MultilineOperationIndentation: - Exclude: - - 'lib/json-schema/attributes/properties.rb' - # Offense count: 18 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/lib/json-schema/attributes/properties.rb b/lib/json-schema/attributes/properties.rb index d731eac8..ecd8def2 100644 --- a/lib/json-schema/attributes/properties.rb +++ b/lib/json-schema/attributes/properties.rb @@ -15,9 +15,9 @@ def self.validate(current_schema, data, fragments, processor, validator, options property = property.to_s if !data.key?(property) && - options[:insert_defaults] && - property_schema.has_key?('default') && - !property_schema['readonly'] + options[:insert_defaults] && + property_schema.has_key?('default') && + !property_schema['readonly'] default = property_schema['default'] data[property] = default.is_a?(Hash) ? default.clone : default end From 8b5b842ba0ee87f631779050fb8534579bb167a0 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 12:28:02 +0100 Subject: [PATCH 3/8] rubocop: Fix Layout/SpaceAroundEqualsInParameterDefault --- .rubocop_todo.yml | 10 ---------- lib/json-schema/schema.rb | 2 +- lib/json-schema/util/uuid.rb | 2 +- lib/json-schema/validator.rb | 28 ++++++++++++++-------------- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e6637bd6..4c944ddd 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,16 +14,6 @@ Layout/MultilineMethodCallBraceLayout: Exclude: - 'test/common_test_suite_test.rb' -# Offense count: 18 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Exclude: - - 'lib/json-schema/schema.rb' - - 'lib/json-schema/util/uuid.rb' - - 'lib/json-schema/validator.rb' - # Offense count: 48 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. diff --git a/lib/json-schema/schema.rb b/lib/json-schema/schema.rb index add672a8..d9d0c341 100644 --- a/lib/json-schema/schema.rb +++ b/lib/json-schema/schema.rb @@ -4,7 +4,7 @@ module JSON class Schema attr_accessor :schema, :uri, :validator - def initialize(schema, uri, parent_validator=nil) + def initialize(schema, uri, parent_validator = nil) @schema = schema @uri = uri diff --git a/lib/json-schema/util/uuid.rb b/lib/json-schema/util/uuid.rb index 56ce44c7..042ed855 100644 --- a/lib/json-schema/util/uuid.rb +++ b/lib/json-schema/util/uuid.rb @@ -137,7 +137,7 @@ def write_state fp, c, m # :nodoc: # invokation. If you want to speed this up, try remounting tmpdir with a # memory based filesystem (such as tmpfs). STILL slow? then no way but # rewrite it with c :) - def create clock=nil, time=nil, mac_addr=nil + def create clock = nil, time = nil, mac_addr = nil c = t = m = nil Dir.chdir Dir.tmpdir do unless FileTest.exist? STATE_FILE then diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index 780979df..07f53987 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -36,7 +36,7 @@ class Validator @@serializer = nil @@mutex = Mutex.new - def initialize(schema_data, opts={}) + def initialize(schema_data, opts = {}) @options = @@default_opts.clone.merge(opts) @errors = [] @@ -228,7 +228,7 @@ def validation_errors end class << self - def validate(schema, data, opts={}) + def validate(schema, data, opts = {}) begin validate!(schema, data, opts) rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError @@ -236,47 +236,47 @@ def validate(schema, data, opts={}) end end - def validate_json(schema, data, opts={}) + def validate_json(schema, data, opts = {}) validate(schema, data, opts.merge(json: true)) end - def validate_uri(schema, data, opts={}) + def validate_uri(schema, data, opts = {}) validate(schema, data, opts.merge(uri: true)) end - def validate!(schema, data, opts={}) + def validate!(schema, data, opts = {}) validator = new(schema, opts) validator.validate(data) end - def validate2(schema, data, opts={}) + def validate2(schema, data, opts = {}) warn '[DEPRECATION NOTICE] JSON::Validator#validate2 has been replaced by JSON::Validator#validate! and will be removed in version >= 3. Please use the #validate! method instead.' validate!(schema, data, opts) end - def validate_json!(schema, data, opts={}) + def validate_json!(schema, data, opts = {}) validate!(schema, data, opts.merge(json: true)) end - def validate_uri!(schema, data, opts={}) + def validate_uri!(schema, data, opts = {}) validate!(schema, data, opts.merge(uri: true)) end - def fully_validate(schema, data, opts={}) + def fully_validate(schema, data, opts = {}) validate!(schema, data, opts.merge(record_errors: true)) end - def fully_validate_schema(schema, opts={}) + def fully_validate_schema(schema, opts = {}) data = schema schema = validator_for_name(opts[:version]).metaschema fully_validate(schema, data, opts) end - def fully_validate_json(schema, data, opts={}) + def fully_validate_json(schema, data, opts = {}) fully_validate(schema, data, opts.merge(json: true)) end - def fully_validate_uri(schema, data, opts={}) + def fully_validate_uri(schema, data, opts = {}) fully_validate(schema, data, opts.merge(uri: true)) end @@ -329,7 +329,7 @@ def default_validator @@default_validator end - def validator_for_uri(schema_uri, raise_not_found=true) + def validator_for_uri(schema_uri, raise_not_found = true) return default_validator unless schema_uri u = JSON::Util::URI.parse(schema_uri) @@ -341,7 +341,7 @@ def validator_for_uri(schema_uri, raise_not_found=true) end end - def validator_for_name(schema_name, raise_not_found=true) + def validator_for_name(schema_name, raise_not_found = true) return default_validator unless schema_name schema_name = schema_name.to_s From 3ca2de9ab89028dd66cc175b4ad4c6c743438b80 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 12:28:42 +0100 Subject: [PATCH 4/8] rubocop: Fix Layout/SpaceAroundOperators --- .rubocop_todo.yml | 13 ------------- Gemfile | 2 +- lib/json-schema/util/uuid.rb | 2 +- test/common_test_suite_test.rb | 2 +- test/draft4_test.rb | 6 +++--- test/full_validation_test.rb | 26 +++++++++++++------------- 6 files changed, 19 insertions(+), 32 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4c944ddd..322cf2db 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,19 +14,6 @@ Layout/MultilineMethodCallBraceLayout: Exclude: - 'test/common_test_suite_test.rb' -# Offense count: 48 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. -# SupportedStylesForExponentOperator: space, no_space -Layout/SpaceAroundOperators: - Exclude: - - 'Gemfile' - - 'lib/json-schema/util/uuid.rb' - - 'test/common_test_suite_test.rb' - - 'test/draft4_test.rb' - - 'test/full_validation_test.rb' - - 'test/uri_parsing_test.rb' - # Offense count: 11 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. diff --git a/Gemfile b/Gemfile index ee9671af..a7eb6560 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ group :release do gem 'github_changelog_generator', require: false end -group :coverage, optional: ENV['COVERAGE']!='yes' do +group :coverage, optional: ENV['COVERAGE'] != 'yes' do gem 'codecov', require: false gem 'simplecov-console', require: false end diff --git a/lib/json-schema/util/uuid.rb b/lib/json-schema/util/uuid.rb index 042ed855..32ba901e 100644 --- a/lib/json-schema/util/uuid.rb +++ b/lib/json-schema/util/uuid.rb @@ -177,7 +177,7 @@ def create clock = nil, time = nil, mac_addr = nil if t.nil? then # UUID epoch is 1582/Oct/15 tt = Time.now - t = tt.to_i*10000000 + tt.tv_usec*10 + 0x01B21DD213814000 + t = tt.to_i * 10000000 + tt.tv_usec * 10 + 0x01B21DD213814000 end c = c.succ # important; increment here write_state fp, c, m diff --git a/test/common_test_suite_test.rb b/test/common_test_suite_test.rb index e823ed9c..a6a2374f 100644 --- a/test/common_test_suite_test.rb +++ b/test/common_test_suite_test.rb @@ -26,7 +26,7 @@ def self.skip?(current_test, file_path) version = File.basename(suite).to_sym Dir["#{suite}/**/*.json"].each do |tfile| test_list = JSON.parse(File.read(tfile)) - rel_file = tfile[TEST_DIR.length+1..-1] + rel_file = tfile[TEST_DIR.length + 1..-1] test_list.each do |test| schema = test['schema'] diff --git a/test/draft4_test.rb b/test/draft4_test.rb index df256cb3..e557eef2 100644 --- a/test/draft4_test.rb +++ b/test/draft4_test.rb @@ -393,14 +393,14 @@ def test_schema_dependency schema = { 'type' => 'object', 'properties' => { - 'name' => { 'type'=> 'string' }, - 'credit_card' => { 'type'=> 'number' }, + 'name' => { 'type' => 'string' }, + 'credit_card' => { 'type' => 'number' }, }, 'required' => ['name'], 'dependencies' => { 'credit_card' => { 'properties' => { - 'billing_address' => { 'type'=> 'string' }, + 'billing_address' => { 'type' => 'string' }, }, 'required' => ['billing_address'], }, diff --git a/test/full_validation_test.rb b/test/full_validation_test.rb index 4c6987a0..bf6ae519 100644 --- a/test/full_validation_test.rb +++ b/test/full_validation_test.rb @@ -182,16 +182,16 @@ def test_full_validation_with_nested_required_properties 'type' => 'object', 'required' => ['a', 'b'], 'properties' => { - 'a' => {'type'=>'integer'}, - 'b' => {'type'=>'integer'}, - 'c' => {'type'=>'integer'}, - 'd' => {'type'=>'integer'}, - 'e' => {'type'=>'integer'}, + 'a' => {'type' => 'integer'}, + 'b' => {'type' => 'integer'}, + 'c' => {'type' => 'integer'}, + 'd' => {'type' => 'integer'}, + 'e' => {'type' => 'integer'}, }, }, }, } - data = {'x' => {'a'=>5, 'd'=>5, 'e'=>'what?'}} + data = {'x' => {'a' => 5, 'd' => 5, 'e' => 'what?'}} errors = JSON::Validator.fully_validate(schema, data, errors_as_objects: true) assert_equal 2, errors.length @@ -212,18 +212,18 @@ def test_full_validation_with_nested_required_propertiesin_array 'type' => 'object', 'required' => ['a', 'b'], 'properties' => { - 'a' => {'type'=>'integer'}, - 'b' => {'type'=>'integer'}, - 'c' => {'type'=>'integer'}, - 'd' => {'type'=>'integer'}, - 'e' => {'type'=>'integer'}, + 'a' => {'type' => 'integer'}, + 'b' => {'type' => 'integer'}, + 'c' => {'type' => 'integer'}, + 'd' => {'type' => 'integer'}, + 'e' => {'type' => 'integer'}, }, }, }, }, } - missing_b= {'a'=>5} - e_is_wrong_type= {'a'=>5, 'b'=>5, 'e'=>'what?'} + missing_b = {'a' => 5} + e_is_wrong_type = {'a' => 5, 'b' => 5, 'e' => 'what?'} data = {'x' => [missing_b, e_is_wrong_type]} errors = JSON::Validator.fully_validate(schema, data, errors_as_objects: true) From 5b3f5e272c38b0b91b73765c06da76bce9e2aa37 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 12:29:14 +0100 Subject: [PATCH 5/8] rubocop: Fix Layout/SpaceBeforeBlockBraces --- .rubocop_todo.yml | 10 ---------- lib/json-schema/errors/validation_error.rb | 2 +- lib/json-schema/validator.rb | 20 ++++++++++---------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 322cf2db..d2e14210 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,16 +14,6 @@ Layout/MultilineMethodCallBraceLayout: Exclude: - 'test/common_test_suite_test.rb' -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceBeforeBlockBraces: - Exclude: - - 'lib/json-schema/errors/validation_error.rb' - - 'lib/json-schema/validator.rb' - # Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. diff --git a/lib/json-schema/errors/validation_error.rb b/lib/json-schema/errors/validation_error.rb index 2b1e2de0..2c7bfa2d 100644 --- a/lib/json-schema/errors/validation_error.rb +++ b/lib/json-schema/errors/validation_error.rb @@ -31,7 +31,7 @@ def to_hash if !@sub_errors.empty? base[:errors] = @sub_errors.each_with_object({}) do |(subschema, errors), hsh| subschema_sym = subschema.downcase.gsub(/\W+/, '_').to_sym - hsh[subschema_sym] = Array(errors).map{|e| e.to_hash} + hsh[subschema_sym] = Array(errors).map {|e| e.to_hash} end end base diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index 07f53987..d4b6b478 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -106,9 +106,9 @@ def validate(data) if @options[:record_errors] if @options[:errors_as_objects] - @errors.map{|e| e.to_hash} + @errors.map {|e| e.to_hash} else - @errors.map{|e| e.to_string} + @errors.map {|e| e.to_string} end else true @@ -368,7 +368,7 @@ def register_default_validator(v) @@default_validator = v end - def register_format_validator(format, validation_proc, versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil])) + def register_format_validator(format, validation_proc, versions = (@@validators.flat_map { |k, v| v.names.first } + [nil])) custom_format_validator = JSON::Schema::CustomFormat.new(validation_proc) versions.each do |version| validator = validator_for_name(version) @@ -376,14 +376,14 @@ def register_format_validator(format, validation_proc, versions = (@@validators. end end - def deregister_format_validator(format, versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil])) + def deregister_format_validator(format, versions = (@@validators.flat_map { |k, v| v.names.first } + [nil])) versions.each do |version| validator = validator_for_name(version) validator.formats[format.to_s] = validator.default_formats[format.to_s] end end - def restore_default_formats(versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil])) + def restore_default_formats(versions = (@@validators.flat_map { |k, v| v.names.first } + [nil])) versions.each do |version| validator = validator_for_name(version) validator.formats = validator.default_formats.clone @@ -482,11 +482,11 @@ def merge_missing_values(source, destination) end if @@json_backend == 'yajl' - @@serializer = lambda{|o| Yajl::Encoder.encode(o) } + @@serializer = lambda {|o| Yajl::Encoder.encode(o) } elsif @@json_backend == 'json' - @@serializer = lambda{|o| JSON.dump(o) } + @@serializer = lambda {|o| JSON.dump(o) } else - @@serializer = lambda{|o| YAML.dump(o) } + @@serializer = lambda {|o| YAML.dump(o) } end end end @@ -495,10 +495,10 @@ def merge_missing_values(source, destination) if Gem::Specification::find_all_by_name('uuidtools').any? require 'uuidtools' - @@fake_uuid_generator = lambda{|s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s } + @@fake_uuid_generator = lambda {|s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s } else require 'json-schema/util/uuid' - @@fake_uuid_generator = lambda{|s| JSON::Util::UUID.create_v5(s, JSON::Util::UUID::Nil).to_s } + @@fake_uuid_generator = lambda {|s| JSON::Util::UUID.create_v5(s, JSON::Util::UUID::Nil).to_s } end def serialize schema From 595885851e8dce2d7d37b6708c47263981f36f07 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 12:30:18 +0100 Subject: [PATCH 6/8] rubocop: Fix Layout/SpaceInsideBlockBraces --- .rubocop_todo.yml | 11 ----------- lib/json-schema.rb | 4 ++-- lib/json-schema/errors/validation_error.rb | 2 +- lib/json-schema/validator.rb | 14 +++++++------- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d2e14210..c41adcb5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,17 +14,6 @@ Layout/MultilineMethodCallBraceLayout: Exclude: - 'test/common_test_suite_test.rb' -# Offense count: 13 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/json-schema.rb' - - 'lib/json-schema/errors/validation_error.rb' - - 'lib/json-schema/validator.rb' - # Offense count: 1103 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. diff --git a/lib/json-schema.rb b/lib/json-schema.rb index f199e5cb..8d7c1d35 100644 --- a/lib/json-schema.rb +++ b/lib/json-schema.rb @@ -14,5 +14,5 @@ require 'json-schema/schema/reader' require 'json-schema/validator' -Dir[File.join(File.dirname(__FILE__), 'json-schema/attributes/**/*.rb')].each {|file| require file } -Dir[File.join(File.dirname(__FILE__), 'json-schema/validators/*.rb')].sort!.each {|file| require file } +Dir[File.join(File.dirname(__FILE__), 'json-schema/attributes/**/*.rb')].each { |file| require file } +Dir[File.join(File.dirname(__FILE__), 'json-schema/validators/*.rb')].sort!.each { |file| require file } diff --git a/lib/json-schema/errors/validation_error.rb b/lib/json-schema/errors/validation_error.rb index 2c7bfa2d..53a2e0bc 100644 --- a/lib/json-schema/errors/validation_error.rb +++ b/lib/json-schema/errors/validation_error.rb @@ -31,7 +31,7 @@ def to_hash if !@sub_errors.empty? base[:errors] = @sub_errors.each_with_object({}) do |(subschema, errors), hsh| subschema_sym = subschema.downcase.gsub(/\W+/, '_').to_sym - hsh[subschema_sym] = Array(errors).map {|e| e.to_hash} + hsh[subschema_sym] = Array(errors).map { |e| e.to_hash } end end base diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index d4b6b478..a4eb1a64 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -106,9 +106,9 @@ def validate(data) if @options[:record_errors] if @options[:errors_as_objects] - @errors.map {|e| e.to_hash} + @errors.map { |e| e.to_hash } else - @errors.map {|e| e.to_string} + @errors.map { |e| e.to_string } end else true @@ -482,11 +482,11 @@ def merge_missing_values(source, destination) end if @@json_backend == 'yajl' - @@serializer = lambda {|o| Yajl::Encoder.encode(o) } + @@serializer = lambda { |o| Yajl::Encoder.encode(o) } elsif @@json_backend == 'json' - @@serializer = lambda {|o| JSON.dump(o) } + @@serializer = lambda { |o| JSON.dump(o) } else - @@serializer = lambda {|o| YAML.dump(o) } + @@serializer = lambda { |o| YAML.dump(o) } end end end @@ -495,10 +495,10 @@ def merge_missing_values(source, destination) if Gem::Specification::find_all_by_name('uuidtools').any? require 'uuidtools' - @@fake_uuid_generator = lambda {|s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s } + @@fake_uuid_generator = lambda { |s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s } else require 'json-schema/util/uuid' - @@fake_uuid_generator = lambda {|s| JSON::Util::UUID.create_v5(s, JSON::Util::UUID::Nil).to_s } + @@fake_uuid_generator = lambda { |s| JSON::Util::UUID.create_v5(s, JSON::Util::UUID::Nil).to_s } end def serialize schema From 260dd837bd1c2488bcc52edf2e2aab5b2ca06096 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 12:31:03 +0100 Subject: [PATCH 7/8] rubocop: Fix Layout/SpaceInsideHashLiteralBraces --- .rubocop_todo.yml | 8 - lib/json-schema/errors/validation_error.rb | 2 +- lib/json-schema/validator.rb | 4 +- test/bad_schema_ref_test.rb | 4 +- test/draft1_test.rb | 28 +-- test/draft2_test.rb | 26 +-- test/draft3_test.rb | 176 +++++++-------- test/draft4_test.rb | 236 ++++++++++----------- test/draft6_test.rb | 16 +- test/extended_schema_test.rb | 16 +- test/files_test.rb | 8 +- test/fragment_resolution_test.rb | 20 +- test/fragment_validation_with_ref_test.rb | 4 +- test/full_validation_test.rb | 54 ++--- test/initialize_data_test.rb | 32 +-- test/list_option_test.rb | 4 +- test/merge_missing_values_test.rb | 18 +- test/one_of_test.rb | 18 +- test/relative_definition_test.rb | 8 +- test/ruby_schema_test.rb | 8 +- test/schema_validation_test.rb | 8 +- test/stringify_test.rb | 8 +- test/support/array_validation.rb | 8 +- test/support/enum_validation.rb | 10 +- test/support/number_validation.rb | 38 ++-- test/support/object_validation.rb | 28 +-- test/support/strict_validation.rb | 48 ++--- test/support/string_validation.rb | 96 ++++----- test/support/type_validation.rb | 16 +- test/uri_parsing_test.rb | 6 +- test/uri_util_test.rb | 4 +- 31 files changed, 476 insertions(+), 484 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c41adcb5..ffe7dad8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,14 +14,6 @@ Layout/MultilineMethodCallBraceLayout: Exclude: - 'test/common_test_suite_test.rb' -# Offense count: 1103 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Enabled: false - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. diff --git a/lib/json-schema/errors/validation_error.rb b/lib/json-schema/errors/validation_error.rb index 53a2e0bc..b6b728af 100644 --- a/lib/json-schema/errors/validation_error.rb +++ b/lib/json-schema/errors/validation_error.rb @@ -27,7 +27,7 @@ def to_string(subschema_level = 0) end def to_hash - base = {schema: @schema.uri, fragment: ::JSON::Schema::Attribute.build_fragment(fragments), message: message_with_schema, failed_attribute: @failed_attribute.to_s.split(':').last.split('Attribute').first} + base = { schema: @schema.uri, fragment: ::JSON::Schema::Attribute.build_fragment(fragments), message: message_with_schema, failed_attribute: @failed_attribute.to_s.split(':').last.split('Attribute').first } if !@sub_errors.empty? base[:errors] = @sub_errors.each_with_object({}) do |(subschema, errors), hsh| subschema_sym = subschema.downcase.gsub(/\W+/, '_').to_sym diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index a4eb1a64..32fcd2c8 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -43,7 +43,7 @@ def initialize(schema_data, opts = {}) configured_validator = self.class.validator_for_name(@options[:version]) @options[:schema_reader] ||= self.class.schema_reader - @validation_options = @options[:record_errors] ? {record_errors: true} : {} + @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 !@@cache_schemas || @options[:clear_cache] @@ -54,7 +54,7 @@ def initialize(schema_data, opts = {}) # validate the schema, if requested if @options[:validate_schema] # Don't clear the cache during metaschema validation! - meta_validator = self.class.new(@base_schema.validator.metaschema, {clear_cache: false}) + meta_validator = self.class.new(@base_schema.validator.metaschema, { clear_cache: false }) meta_validator.validate(@base_schema.schema) end diff --git a/test/bad_schema_ref_test.rb b/test/bad_schema_ref_test.rb index c742d940..c294ad27 100644 --- a/test/bad_schema_ref_test.rb +++ b/test/bad_schema_ref_test.rb @@ -14,7 +14,7 @@ def test_bad_uri_ref schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'array', - 'items' => { '$ref' => '../google.json'}, + 'items' => { '$ref' => '../google.json' }, } data = [1, 2, 3] @@ -33,7 +33,7 @@ def test_bad_host_ref schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'array', - 'items' => { '$ref' => 'http://ppcheesecheseunicornnuuuurrrrr.example.invalid/json.schema'}, + 'items' => { '$ref' => 'http://ppcheesecheseunicornnuuuurrrrr.example.invalid/json.schema' }, } data = [1, 2, 3] diff --git a/test/draft1_test.rb b/test/draft1_test.rb index 1fc0cffe..6c77cb62 100644 --- a/test/draft1_test.rb +++ b/test/draft1_test.rb @@ -36,7 +36,7 @@ def test_optional # Set up the default datatype schema = { 'properties' => { - 'a' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, }, } data = {} @@ -47,7 +47,7 @@ def test_optional schema = { 'properties' => { - 'a' => {'type' => 'integer', 'optional' => 'true'}, + 'a' => { 'type' => 'integer', 'optional' => 'true' }, }, } @@ -59,7 +59,7 @@ def test_max_decimal # Set up the default datatype schema = { 'properties' => { - 'a' => {'maxDecimal' => 2}, + 'a' => { 'maxDecimal' => 2 }, }, } @@ -89,7 +89,7 @@ def test_disallow # Set up the default datatype schema = { 'properties' => { - 'a' => {'disallow' => 'integer'}, + 'a' => { 'disallow' => 'integer' }, }, } @@ -117,17 +117,17 @@ def test_disallow def test_format_datetime schema = { 'type' => 'object', - 'properties' => { 'a' => {'type' => 'string', 'format' => 'date-time'}}, + 'properties' => { 'a' => { 'type' => 'string', 'format' => 'date-time' } }, } - assert_valid schema, {'a' => '2010-01-01T12:00:00Z'} - refute_valid schema, {'a' => '2010-01-32T12:00:00Z'} - refute_valid schema, {'a' => '2010-13-01T12:00:00Z'} - refute_valid schema, {'a' => '2010-01-01T24:00:00Z'} - refute_valid schema, {'a' => '2010-01-01T12:60:00Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:60Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:00z'} - refute_valid schema, {'a' => '2010-01-0112:00:00Z'} - refute_valid schema, {'a' => "2010-01-01T12:00:00Z\nabc"} + assert_valid schema, { 'a' => '2010-01-01T12:00:00Z' } + refute_valid schema, { 'a' => '2010-01-32T12:00:00Z' } + refute_valid schema, { 'a' => '2010-13-01T12:00:00Z' } + refute_valid schema, { 'a' => '2010-01-01T24:00:00Z' } + refute_valid schema, { 'a' => '2010-01-01T12:60:00Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:60Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00z' } + refute_valid schema, { 'a' => '2010-01-0112:00:00Z' } + refute_valid schema, { 'a' => "2010-01-01T12:00:00Z\nabc" } end end diff --git a/test/draft2_test.rb b/test/draft2_test.rb index d0e9c1a7..2e21e582 100644 --- a/test/draft2_test.rb +++ b/test/draft2_test.rb @@ -42,7 +42,7 @@ def test_optional # Set up the default datatype schema = { 'properties' => { - 'a' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, }, } data = {} @@ -53,7 +53,7 @@ def test_optional schema = { 'properties' => { - 'a' => {'type' => 'integer', 'optional' => 'true'}, + 'a' => { 'type' => 'integer', 'optional' => 'true' }, }, } @@ -65,7 +65,7 @@ def test_disallow # Set up the default datatype schema = { 'properties' => { - 'a' => {'disallow' => 'integer'}, + 'a' => { 'disallow' => 'integer' }, }, } @@ -93,17 +93,17 @@ def test_disallow def test_format_datetime schema = { 'type' => 'object', - 'properties' => { 'a' => {'type' => 'string', 'format' => 'date-time'}}, + 'properties' => { 'a' => { 'type' => 'string', 'format' => 'date-time' } }, } - assert_valid schema, {'a' => '2010-01-01T12:00:00Z'} - refute_valid schema, {'a' => '2010-01-32T12:00:00Z'} - refute_valid schema, {'a' => '2010-13-01T12:00:00Z'} - refute_valid schema, {'a' => '2010-01-01T24:00:00Z'} - refute_valid schema, {'a' => '2010-01-01T12:60:00Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:60Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:00z'} - refute_valid schema, {'a' => '2010-01-0112:00:00Z'} - refute_valid schema, {'a' => "2010-01-01T12:00:00Z\nabc"} + assert_valid schema, { 'a' => '2010-01-01T12:00:00Z' } + refute_valid schema, { 'a' => '2010-01-32T12:00:00Z' } + refute_valid schema, { 'a' => '2010-13-01T12:00:00Z' } + refute_valid schema, { 'a' => '2010-01-01T24:00:00Z' } + refute_valid schema, { 'a' => '2010-01-01T12:60:00Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:60Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00z' } + refute_valid schema, { 'a' => '2010-01-0112:00:00Z' } + refute_valid schema, { 'a' => "2010-01-01T12:00:00Z\nabc" } end end diff --git a/test/draft3_test.rb b/test/draft3_test.rb index 56c0fe70..cee0de39 100644 --- a/test/draft3_test.rb +++ b/test/draft3_test.rb @@ -66,12 +66,12 @@ def test_types }, } - data['a'] = [{'b' => 5}, {'c' => 'foo'}] + data['a'] = [{ 'b' => 5 }, { 'c' => 'foo' }] errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?, errors.join("\n")) # This should actually pass, because this matches the first schema in the union - data['a'] << {'c' => false} + data['a'] << { 'c' => false } assert_valid schema, data end @@ -80,7 +80,7 @@ def test_required schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'properties' => { - 'a' => {'required' => true}, + 'a' => { 'required' => true }, }, } data = {} @@ -92,7 +92,7 @@ def test_required schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'properties' => { - 'a' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, }, } @@ -104,18 +104,18 @@ def test_strict_properties_required_props schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'properties' => { - 'a' => {'type' => 'string', 'required' => true}, - 'b' => {'type' => 'string', 'required' => false}, + 'a' => { 'type' => 'string', 'required' => true }, + 'b' => { 'type' => 'string', 'required' => false }, }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) end @@ -123,25 +123,25 @@ def test_strict_properties_additional_props schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'properties' => { - 'a' => {'type' => 'string'}, - 'b' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, + 'b' => { 'type' => 'string' }, }, - 'additionalProperties' => {'type' => 'integer'}, + 'additionalProperties' => { 'type' => 'integer' }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 'c'} + data = { 'a' => 'a', 'b' => 'b', 'c' => 'c' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 3} + data = { 'a' => 'a', 'b' => 'b', 'c' => 3 } assert(JSON::Validator.validate(schema, data, strict: true)) end @@ -149,31 +149,31 @@ def test_strict_properties_pattern_props schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'properties' => { - 'a' => {'type' => 'string'}, - 'b' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, + 'b' => { 'type' => 'string' }, }, - 'patternProperties' => {'\\d+ taco' => {'type' => 'integer'}}, + 'patternProperties' => { '\\d+ taco' => { 'type' => 'integer' } }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 'c'} + data = { 'a' => 'a', 'b' => 'b', 'c' => 'c' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 3} + data = { 'a' => 'a', 'b' => 'b', 'c' => 3 } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', '23 taco' => 3} + data = { 'a' => 'a', 'b' => 'b', '23 taco' => 3 } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', '23 taco' => 'cheese'} + data = { 'a' => 'a', 'b' => 'b', '23 taco' => 'cheese' } assert(!JSON::Validator.validate(schema, data, strict: true)) end @@ -182,7 +182,7 @@ def test_disallow schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'properties' => { - 'a' => {'disallow' => 'integer'}, + 'a' => { 'disallow' => 'integer' }, }, } @@ -211,7 +211,7 @@ def test_extends schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'properties' => { - 'a' => { 'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, }, } @@ -238,17 +238,17 @@ def test_list_option schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', - 'properties' => { 'a' => {'type' => 'integer', 'required' => true} }, + 'properties' => { 'a' => { 'type' => 'integer', 'required' => true } }, } - data = [{'a' => 1}, {'a' => 2}, {'a' => 3}] + data = [{ 'a' => 1 }, { 'a' => 2 }, { 'a' => 3 }] assert(JSON::Validator.validate(schema, data, list: true)) refute_valid schema, data - data = {'a' => 1} + data = { 'a' => 1 } assert(!JSON::Validator.validate(schema, data, list: true)) - data = [{'a' => 1}, {'b' => 2}, {'a' => 3}] + data = [{ 'a' => 1 }, { 'b' => 2 }, { 'a' => 3 }] assert(!JSON::Validator.validate(schema, data, list: true)) end @@ -256,61 +256,61 @@ def test_self_reference schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', - 'properties' => { 'a' => {'type' => 'integer'}, 'b' => {'$ref' => '#'}}, + 'properties' => { 'a' => { 'type' => 'integer' }, 'b' => { '$ref' => '#' } }, } - assert_valid schema, {'a' => 5, 'b' => {'b' => {'a' => 1}}} - refute_valid schema, {'a' => 5, 'b' => {'b' => {'a' => 'taco'}}} + assert_valid schema, { 'a' => 5, 'b' => { 'b' => { 'a' => 1 } } } + refute_valid schema, { 'a' => 5, 'b' => { 'b' => { 'a' => 'taco' } } } end def test_format_datetime schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', - 'properties' => { 'a' => {'type' => 'string', 'format' => 'date-time'}}, + 'properties' => { 'a' => { 'type' => 'string', 'format' => 'date-time' } }, } - assert_valid schema, {'a' => '2010-01-01T12:00:00Z'} - assert_valid schema, {'a' => '2010-01-01T12:00:00.1Z'} - assert_valid schema, {'a' => '2010-01-01T12:00:00,1Z'} - refute_valid schema, {'a' => '2010-01-32T12:00:00Z'} - refute_valid schema, {'a' => '2010-13-01T12:00:00Z'} - refute_valid schema, {'a' => '2010-01-01T24:00:00Z'} - refute_valid schema, {'a' => '2010-01-01T12:60:00Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:60Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:00z'} - refute_valid schema, {'a' => '2010-01-0112:00:00Z'} - refute_valid schema, {'a' => "2010-01-01T12:00:00.1Z\nabc"} + assert_valid schema, { 'a' => '2010-01-01T12:00:00Z' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00.1Z' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00,1Z' } + refute_valid schema, { 'a' => '2010-01-32T12:00:00Z' } + refute_valid schema, { 'a' => '2010-13-01T12:00:00Z' } + refute_valid schema, { 'a' => '2010-01-01T24:00:00Z' } + refute_valid schema, { 'a' => '2010-01-01T12:60:00Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:60Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00z' } + refute_valid schema, { 'a' => '2010-01-0112:00:00Z' } + refute_valid schema, { 'a' => "2010-01-01T12:00:00.1Z\nabc" } # test with a specific timezone - assert_valid schema, {'a' => '2010-01-01T12:00:00+01'} - assert_valid schema, {'a' => '2010-01-01T12:00:00+01:00'} - assert_valid schema, {'a' => '2010-01-01T12:00:00+01:30'} - assert_valid schema, {'a' => '2010-01-01T12:00:00+0234'} - refute_valid schema, {'a' => '2010-01-01T12:00:00+01:'} - refute_valid schema, {'a' => '2010-01-01T12:00:00+0'} + assert_valid schema, { 'a' => '2010-01-01T12:00:00+01' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00+01:00' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00+01:30' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00+0234' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00+01:' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00+0' } # do not allow mixing Z and specific timezone - refute_valid schema, {'a' => '2010-01-01T12:00:00Z+01'} - refute_valid schema, {'a' => '2010-01-01T12:00:00+01Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:00+01:30Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:00+0Z'} + refute_valid schema, { 'a' => '2010-01-01T12:00:00Z+01' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00+01Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00+01:30Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00+0Z' } # test without any timezone - assert_valid schema, {'a' => '2010-01-01T12:00:00'} - assert_valid schema, {'a' => '2010-01-01T12:00:00.12345'} - assert_valid schema, {'a' => '2010-01-01T12:00:00,12345'} - assert_valid schema, {'a' => '2010-01-01T12:00:00.12345'} + assert_valid schema, { 'a' => '2010-01-01T12:00:00' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00.12345' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00,12345' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00.12345' } end def test_format_uri - data1 = {'a' => 'http://gitbuh.com'} - data2 = {'a' => '::boo'} - data3 = {'a' => 'http://ja.wikipedia.org/wiki/メインページ'} + data1 = { 'a' => 'http://gitbuh.com' } + data2 = { 'a' => '::boo' } + data3 = { 'a' => 'http://ja.wikipedia.org/wiki/メインページ' } schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', - 'properties' => { 'a' => {'type' => 'string', 'format' => 'uri'}}, + 'properties' => { 'a' => { 'type' => 'string', 'format' => 'uri' } }, } assert(JSON::Validator.validate(schema, data1)) @@ -324,7 +324,7 @@ def test_schema 'type' => 'object', } - data = {'a' => 'taco'} + data = { 'a' => 'taco' } assert(!JSON::Validator.validate(schema, data)) schema = { @@ -339,35 +339,35 @@ def test_dependency '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer'}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, + 'b' => { 'type' => 'integer' }, }, 'dependencies' => { 'a' => 'b', }, } - data = {'a' => 1, 'b' => 2} + data = { 'a' => 1, 'b' => 2 } assert_valid schema, data - data = {'a' => 1} + data = { 'a' => 1 } refute_valid schema, data schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer'}, - 'b' => {'type' => 'integer'}, - 'c' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, + 'b' => { 'type' => 'integer' }, + 'c' => { 'type' => 'integer' }, }, 'dependencies' => { 'a' => ['b', 'c'], }, } - data = {'a' => 1, 'c' => 2} + data = { 'a' => 1, 'c' => 2 } refute_valid schema, data - data = {'a' => 1, 'b' => 2, 'c' => 3} + data = { 'a' => 1, 'b' => 2, 'c' => 3 } assert_valid schema, data end @@ -376,12 +376,12 @@ def test_default '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer', 'default' => 42}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => 42 }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } assert_valid schema, data assert_nil(data['a']) assert(JSON::Validator.validate(schema, data, insert_defaults: true)) @@ -392,12 +392,12 @@ def test_default '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer', 'default' => 42, 'required' => true}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => 42, 'required' => true }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } refute_valid schema, data assert_nil(data['a']) assert(JSON::Validator.validate(schema, data, insert_defaults: true)) @@ -408,12 +408,12 @@ def test_default '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer', 'default' => 42, 'required' => true, 'readonly' => true}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => 42, 'required' => true, 'readonly' => true }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } refute_valid schema, data assert_nil(data['a']) assert(!JSON::Validator.validate(schema, data, insert_defaults: true)) @@ -424,12 +424,12 @@ def test_default '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer', 'default' => '42'}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => '42' }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } assert_valid schema, data assert_nil(data['a']) assert(!JSON::Validator.validate(schema, data, insert_defaults: true)) diff --git a/test/draft4_test.rb b/test/draft4_test.rb index e557eef2..3f951a6e 100644 --- a/test/draft4_test.rb +++ b/test/draft4_test.rb @@ -57,7 +57,7 @@ def test_required schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'properties' => { - 'a' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, }, } @@ -68,42 +68,42 @@ def test_required def test_min_properties schema = { 'minProperties' => 2 } - assert_valid schema, {'a' => 1, 'b' => 2} - assert_valid schema, {'a' => 1, 'b' => 2, 'c' => 3} + assert_valid schema, { 'a' => 1, 'b' => 2 } + assert_valid schema, { 'a' => 1, 'b' => 2, 'c' => 3 } - refute_valid schema, {'a' => 1} + refute_valid schema, { 'a' => 1 } refute_valid schema, {} end def test_max_properties schema = { 'maxProperties' => 2 } - assert_valid schema, {'a' => 1, 'b' => 2} - assert_valid schema, {'a' => 1} + assert_valid schema, { 'a' => 1, 'b' => 2 } + assert_valid schema, { 'a' => 1 } assert_valid schema, {} - refute_valid schema, {'a' => 1, 'b' => 2, 'c' => 3} + refute_valid schema, { 'a' => 1, 'b' => 2, 'c' => 3 } end def test_strict_properties schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'properties' => { - 'a' => {'type' => 'string'}, - 'b' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, + 'b' => { 'type' => 'string' }, }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 'c'} + data = { 'a' => 'a', 'b' => 'b', 'c' => 'c' } assert(!JSON::Validator.validate(schema, data, strict: true)) end @@ -111,25 +111,25 @@ def test_strict_properties_additional_props schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'properties' => { - 'a' => {'type' => 'string'}, - 'b' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, + 'b' => { 'type' => 'string' }, }, - 'additionalProperties' => {'type' => 'integer'}, + 'additionalProperties' => { 'type' => 'integer' }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 'c'} + data = { 'a' => 'a', 'b' => 'b', 'c' => 'c' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 3} + data = { 'a' => 'a', 'b' => 'b', 'c' => 3 } assert(JSON::Validator.validate(schema, data, strict: true)) end @@ -137,31 +137,31 @@ def test_strict_properties_pattern_props schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'properties' => { - 'a' => {'type' => 'string'}, - 'b' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, + 'b' => { 'type' => 'string' }, }, - 'patternProperties' => {'\\d+ taco' => {'type' => 'integer'}}, + 'patternProperties' => { '\\d+ taco' => { 'type' => 'integer' } }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 'c'} + data = { 'a' => 'a', 'b' => 'b', 'c' => 'c' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 3} + data = { 'a' => 'a', 'b' => 'b', 'c' => 3 } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', '23 taco' => 3} + data = { 'a' => 'a', 'b' => 'b', '23 taco' => 3 } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', '23 taco' => 'cheese'} + data = { 'a' => 'a', 'b' => 'b', '23 taco' => 'cheese' } assert(!JSON::Validator.validate(schema, data, strict: true)) end @@ -170,17 +170,17 @@ def test_list_option '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'required' => ['a'], - 'properties' => { 'a' => {'type' => 'integer'} }, + 'properties' => { 'a' => { 'type' => 'integer' } }, } - data = [{'a' => 1}, {'a' => 2}, {'a' => 3}] + data = [{ 'a' => 1 }, { 'a' => 2 }, { 'a' => 3 }] assert(JSON::Validator.validate(schema, data, list: true)) refute_valid schema, data - data = {'a' => 1} + data = { 'a' => 1 } assert(!JSON::Validator.validate(schema, data, list: true)) - data = [{'a' => 1}, {'b' => 2}, {'a' => 3}] + data = [{ 'a' => 1 }, { 'b' => 2 }, { 'a' => 3 }] assert(!JSON::Validator.validate(schema, data, list: true)) end @@ -278,11 +278,11 @@ def test_self_reference schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', - 'properties' => { 'a' => {'type' => 'integer'}, 'b' => {'$ref' => '#'}}, + 'properties' => { 'a' => { 'type' => 'integer' }, 'b' => { '$ref' => '#' } }, } - assert_valid schema, {'a' => 5, 'b' => {'b' => {'a' => 1}}} - refute_valid schema, {'a' => 5, 'b' => {'b' => {'a' => 'taco'}}} + assert_valid schema, { 'a' => 5, 'b' => { 'b' => { 'a' => 1 } } } + refute_valid schema, { 'a' => 5, 'b' => { 'b' => { 'a' => 'taco' } } } end def test_property_named_ref @@ -303,32 +303,32 @@ def test_format_datetime schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', - 'properties' => { 'a' => {'type' => 'string', 'format' => 'date-time'}}, - } - - assert_valid schema, {'a' => '2010-01-01T12:00:00Z'} - assert_valid schema, {'a' => '2010-01-01T12:00:00.1Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:00,1Z'} - refute_valid schema, {'a' => '2010-01-01T12:00:00+0000'} - assert_valid schema, {'a' => '2010-01-01T12:00:00+00:00'} - refute_valid schema, {'a' => '2010-01-32T12:00:00Z'} - refute_valid schema, {'a' => '2010-13-01T12:00:00Z'} - assert_valid schema, {'a' => '2010-01-01T24:00:00Z'} - refute_valid schema, {'a' => '2010-01-01T12:60:00Z'} - assert_valid schema, {'a' => '2010-01-01T12:00:60Z'} - assert_valid schema, {'a' => '2010-01-01T12:00:00z'} - refute_valid schema, {'a' => '2010-01-0112:00:00Z'} + 'properties' => { 'a' => { 'type' => 'string', 'format' => 'date-time' } }, + } + + assert_valid schema, { 'a' => '2010-01-01T12:00:00Z' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00.1Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00,1Z' } + refute_valid schema, { 'a' => '2010-01-01T12:00:00+0000' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00+00:00' } + refute_valid schema, { 'a' => '2010-01-32T12:00:00Z' } + refute_valid schema, { 'a' => '2010-13-01T12:00:00Z' } + assert_valid schema, { 'a' => '2010-01-01T24:00:00Z' } + refute_valid schema, { 'a' => '2010-01-01T12:60:00Z' } + assert_valid schema, { 'a' => '2010-01-01T12:00:60Z' } + assert_valid schema, { 'a' => '2010-01-01T12:00:00z' } + refute_valid schema, { 'a' => '2010-01-0112:00:00Z' } end def test_format_uri - data1 = {'a' => 'http://gitbuh.com'} - data2 = {'a' => '::boo'} - data3 = {'a' => 'http://ja.wikipedia.org/wiki/メインページ'} + data1 = { 'a' => 'http://gitbuh.com' } + data2 = { 'a' => '::boo' } + data3 = { 'a' => 'http://ja.wikipedia.org/wiki/メインページ' } schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', - 'properties' => { 'a' => {'type' => 'string', 'format' => 'uri'}}, + 'properties' => { 'a' => { 'type' => 'string', 'format' => 'uri' } }, } assert(JSON::Validator.validate(schema, data1)) @@ -342,7 +342,7 @@ def test_schema 'type' => 'object', } - data = {'a' => 'taco'} + data = { 'a' => 'taco' } assert(!JSON::Validator.validate(schema, data)) schema = { @@ -357,35 +357,35 @@ def test_dependency '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer'}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, + 'b' => { 'type' => 'integer' }, }, 'dependencies' => { 'a' => ['b'], }, } - data = {'a' => 1, 'b' => 2} + data = { 'a' => 1, 'b' => 2 } assert_valid schema, data - data = {'a' => 1} + data = { 'a' => 1 } refute_valid schema, data schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer'}, - 'b' => {'type' => 'integer'}, - 'c' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, + 'b' => { 'type' => 'integer' }, + 'c' => { 'type' => 'integer' }, }, 'dependencies' => { 'a' => ['b', 'c'], }, } - data = {'a' => 1, 'c' => 2} + data = { 'a' => 1, 'c' => 2 } refute_valid schema, data - data = {'a' => 1, 'b' => 2, 'c' => 3} + data = { 'a' => 1, 'b' => 2, 'c' => 3 } assert_valid schema, data end @@ -420,12 +420,12 @@ def test_default '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer', 'default' => 42}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => 42 }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } assert_valid schema, data assert_nil(data['a']) assert(JSON::Validator.validate(schema, data, insert_defaults: true)) @@ -437,12 +437,12 @@ def test_default 'type' => 'object', 'required' => ['a'], 'properties' => { - 'a' => {'type' => 'integer', 'default' => 42}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => 42 }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } refute_valid schema, data assert_nil(data['a']) assert(JSON::Validator.validate(schema, data, insert_defaults: true)) @@ -454,12 +454,12 @@ def test_default 'type' => 'object', 'required' => ['a'], 'properties' => { - 'a' => {'type' => 'integer', 'default' => 42, 'readonly' => true}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => 42, 'readonly' => true }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } refute_valid schema, data assert_nil(data['a']) assert(!JSON::Validator.validate(schema, data, insert_defaults: true)) @@ -470,12 +470,12 @@ def test_default '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => { - 'a' => {'type' => 'integer', 'default' => '42'}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => '42' }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } assert_valid schema, data assert_nil(data['a']) assert(!JSON::Validator.validate(schema, data, insert_defaults: true)) @@ -489,12 +489,12 @@ def test_boolean_false_default 'type' => 'object', 'required' => ['a'], 'properties' => { - 'a' => {'type' => 'boolean', 'default' => false}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'boolean', 'default' => false }, + 'b' => { 'type' => 'integer' }, }, } - data = {b: 2} + data = { b: 2 } refute_valid schema, data assert_nil(data['a']) assert(JSON::Validator.validate(schema, data, insert_defaults: true)) @@ -507,25 +507,25 @@ def test_all_of '$schema' => 'http://json-schema.org/draft-04/schema#', 'allOf' => [ { - 'properties' => {'a' => {'type' => 'string'}}, + 'properties' => { 'a' => { 'type' => 'string' } }, 'required' => ['a'], }, { - 'properties' => {'b' => {'type' => 'integer'}}, + 'properties' => { 'b' => { 'type' => 'integer' } }, }, ], } - data = {'a' => 'hello', 'b' => 5} + data = { 'a' => 'hello', 'b' => 5 } assert_valid schema, data - data = {'a' => 'hello'} + data = { 'a' => 'hello' } assert_valid schema, data - data = {'a' => 'hello', 'b' => 'taco'} + data = { 'a' => 'hello', 'b' => 'taco' } refute_valid schema, data - data = {'b' => 5} + data = { 'b' => 5 } refute_valid schema, data end @@ -534,28 +534,28 @@ def test_any_of '$schema' => 'http://json-schema.org/draft-04/schema#', 'anyOf' => [ { - 'properties' => {'a' => {'type' => 'string'}}, + 'properties' => { 'a' => { 'type' => 'string' } }, 'required' => ['a'], }, { - 'properties' => {'b' => {'type' => 'integer'}}, + 'properties' => { 'b' => { 'type' => 'integer' } }, }, ], } - data = {'a' => 'hello', 'b' => 5} + data = { 'a' => 'hello', 'b' => 5 } assert_valid schema, data - data = {'a' => 'hello'} + data = { 'a' => 'hello' } assert_valid schema, data - data = {'a' => 'hello', 'b' => 'taco'} + data = { 'a' => 'hello', 'b' => 'taco' } assert_valid schema, data - data = {'b' => 5} + data = { 'b' => 5 } assert_valid schema, data - data = {'a' => 5, 'b' => 'taco'} + data = { 'a' => 5, 'b' => 'taco' } refute_valid schema, data end @@ -564,29 +564,29 @@ def test_one_of '$schema' => 'http://json-schema.org/draft-04/schema#', 'oneOf' => [ { - 'properties' => {'a' => {'type' => 'string'}}, + 'properties' => { 'a' => { 'type' => 'string' } }, 'required' => ['a'], }, { - 'properties' => {'b' => {'type' => 'integer'}}, + 'properties' => { 'b' => { 'type' => 'integer' } }, }, ], } - data = {'a' => 'hello', 'b' => 5} + data = { 'a' => 'hello', 'b' => 5 } refute_valid schema, data # This passes because b is not required, thus matches both schemas - data = {'a' => 'hello'} + data = { 'a' => 'hello' } refute_valid schema, data - data = {'a' => 'hello', 'b' => 'taco'} + data = { 'a' => 'hello', 'b' => 'taco' } assert_valid schema, data - data = {'b' => 5} + data = { 'b' => 5 } assert_valid schema, data - data = {'a' => 5, 'b' => 'taco'} + data = { 'a' => 5, 'b' => 'taco' } refute_valid schema, data end @@ -595,50 +595,50 @@ def test_not schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'properties' => { - 'a' => {'not' => { 'type' => ['string', 'boolean']}}, + 'a' => { 'not' => { 'type' => ['string', 'boolean'] } }, }, } - data = {'a' => 1} + data = { 'a' => 1 } assert_valid schema, data - data = {'a' => 'hi!'} + data = { 'a' => 'hi!' } refute_valid schema, data - data = {'a' => true} + data = { 'a' => true } refute_valid schema, data # Sub-schema not schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'properties' => { - 'a' => {'not' => {'anyOf' => [ + 'a' => { 'not' => { 'anyOf' => [ { 'type' => ['string', 'boolean'], }, { 'type' => 'object', 'properties' => { - 'b' => {'type' => 'boolean'}, + 'b' => { 'type' => 'boolean' }, }, }, - ]} }, + ] } }, }, } - data = {'a' => 1} + data = { 'a' => 1 } assert_valid schema, data - data = {'a' => 'hi!'} + data = { 'a' => 'hi!' } refute_valid schema, data - data = {'a' => true} + data = { 'a' => true } refute_valid schema, data - data = {'a' => {'b' => true}} + data = { 'a' => { 'b' => true } } refute_valid schema, data - data = {'a' => {'b' => 5}} + data = { 'a' => { 'b' => 5 } } assert_valid schema, data end @@ -647,15 +647,15 @@ def test_not_fully_validate schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'properties' => { - 'a' => {'not' => { 'type' => ['string', 'boolean']}}, + 'a' => { 'not' => { 'type' => ['string', 'boolean'] } }, }, } - data = {'a' => 1} + data = { 'a' => 1 } errors = JSON::Validator.fully_validate(schema, data) assert_equal(0, errors.length) - data = {'a' => 'taco'} + data = { 'a' => 'taco' } errors = JSON::Validator.fully_validate(schema, data) assert_equal(1, errors.length) end @@ -664,7 +664,7 @@ def test_definitions schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'array', - 'items' => { '$ref' => '#/definitions/positiveInteger'}, + 'items' => { '$ref' => '#/definitions/positiveInteger' }, 'definitions' => { 'positiveInteger' => { 'type' => 'integer', diff --git a/test/draft6_test.rb b/test/draft6_test.rb index eb5419c9..b1eba824 100644 --- a/test/draft6_test.rb +++ b/test/draft6_test.rb @@ -11,28 +11,28 @@ def test_const_attribute schema = { 'type' => 'object', 'properties' => { - 'a' => {'const' => 'foo'}, - 'b' => {'const' => 6}, + 'a' => { 'const' => 'foo' }, + 'b' => { 'const' => 6 }, }, } - data = {a: 'foo', b: 6} + data = { a: 'foo', b: 6 } assert_valid schema, data - data = {a: 6, b: 'foo'} + data = { a: 6, b: 'foo' } refute_valid schema, data end def test_property_names schema = { 'type' => 'object', - 'propertyNames' => {'const' => 'foo'}, + 'propertyNames' => { 'const' => 'foo' }, } - data = {'foo' => 'value'} + data = { 'foo' => 'value' } assert_valid schema, data - data = {'bar' => 'value'} + data = { 'bar' => 'value' } refute_valid schema, data schema = { @@ -43,7 +43,7 @@ def test_property_names data = {} assert_valid schema, data - data = {'foo' => 'value'} + data = { 'foo' => 'value' } refute_valid schema, data end end diff --git a/test/extended_schema_test.rb b/test/extended_schema_test.rb index de9562ab..0ba7b237 100644 --- a/test/extended_schema_test.rb +++ b/test/extended_schema_test.rb @@ -37,9 +37,9 @@ def test_extended_schema_validation }, } - assert_valid schema, {'a' => 1, 'b' => 'taco'} - refute_valid schema, {'a' => 0, 'b' => 'taco'} - refute_valid schema, {'a' => 1, 'b' => 5} + assert_valid schema, { 'a' => 1, 'b' => 'taco' } + refute_valid schema, { 'a' => 0, 'b' => 'taco' } + refute_valid schema, { 'a' => 1, 'b' => 5 } end def test_extended_schema_validation_with_fragment @@ -56,8 +56,8 @@ def test_extended_schema_validation_with_fragment }, } - assert_valid schema, {'a' => 1}, fragment: '#/definitions/odd-a' - refute_valid schema, {'a' => 0}, fragment: '#/definitions/odd-a' + assert_valid schema, { 'a' => 1 }, fragment: '#/definitions/odd-a' + refute_valid schema, { 'a' => 0 }, fragment: '#/definitions/odd-a' end def test_unextended_schema @@ -73,8 +73,8 @@ def test_unextended_schema }, } - assert_valid schema, {'a' => 0, 'b' => 'taco'} - assert_valid schema, {'a' => 1, 'b' => 'taco'} - refute_valid schema, {'a' => 1, 'b' => 5} + assert_valid schema, { 'a' => 0, 'b' => 'taco' } + assert_valid schema, { 'a' => 1, 'b' => 'taco' } + refute_valid schema, { 'a' => 1, 'b' => 5 } end end diff --git a/test/files_test.rb b/test/files_test.rb index 695a75c6..c34b8275 100644 --- a/test/files_test.rb +++ b/test/files_test.rb @@ -11,25 +11,25 @@ def test_schema_from_file end def test_data_from_file_v3 - schema = {'$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => {'a' => {'type' => 'integer'}}} + schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { 'a' => { 'type' => 'integer' } } } assert_valid schema, data_fixture_path('good_data_1.json'), uri: true refute_valid schema, data_fixture_path('bad_data_1.json'), uri: true end def test_data_from_json_v3 - schema = {'$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => {'a' => {'type' => 'integer'}}} + schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { 'a' => { 'type' => 'integer' } } } assert_valid schema, %Q({"a": 5}), json: true refute_valid schema, %Q({"a": "poop"}), json: true end def test_data_from_file_v4 - schema = {'$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => {'a' => {'type' => 'integer'}}} + schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => { 'a' => { 'type' => 'integer' } } } assert_valid schema, data_fixture_path('good_data_1.json'), uri: true refute_valid schema, data_fixture_path('bad_data_1.json'), uri: true end def test_data_from_json_v4 - schema = {'$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => {'a' => {'type' => 'integer'}}} + schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => { 'a' => { 'type' => 'integer' } } } assert_valid schema, %Q({"a": 5}), json: true refute_valid schema, %Q({"a": "poop"}), json: true end diff --git a/test/fragment_resolution_test.rb b/test/fragment_resolution_test.rb index 29cc6d20..51e3f99e 100644 --- a/test/fragment_resolution_test.rb +++ b/test/fragment_resolution_test.rb @@ -9,13 +9,13 @@ def test_fragment_resolution 'a' => { 'type' => 'object', 'properties' => { - 'b' => {'type' => 'integer' }, + 'b' => { 'type' => 'integer' }, }, }, }, } - data = {'b' => 5} + data = { 'b' => 5 } refute_valid schema, data assert_valid schema, data, fragment: '#/properties/a' @@ -34,12 +34,12 @@ def test_odd_level_fragment_resolution 'type' => 'object', 'required' => ['a'], 'properties' => { - 'a' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, }, }, } - assert_valid schema, {'a' => 1}, fragment: '#/foo' + assert_valid schema, { 'a' => 1 }, fragment: '#/foo' refute_valid schema, {}, fragment: '#/foo' end @@ -50,13 +50,13 @@ def test_even_level_fragment_resolution 'type' => 'object', 'required' => ['a'], 'properties' => { - 'a' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, }, }, }, } - assert_valid schema, {'a' => 1}, fragment: '#/foo/bar' + assert_valid schema, { 'a' => 1 }, fragment: '#/foo/bar' refute_valid schema, {}, fragment: '#/foo/bar' end @@ -67,8 +67,8 @@ def test_array_fragment_resolution 'properties' => { 'a' => { 'anyOf' => [ - {'type' => 'integer'}, - {'type' => 'string'}, + { 'type' => 'integer' }, + { 'type' => 'string' }, ], }, }, @@ -88,13 +88,13 @@ def test_fragment_with_escape_sequences_resolution 'type' => 'object', 'required' => ['a'], 'properties' => { - 'a' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, }, }, }, } - assert_valid schema, {'a' => 1}, fragment: '#/content/application~1json' + assert_valid schema, { 'a' => 1 }, fragment: '#/content/application~1json' refute_valid schema, {}, fragment: '#/content/application~1json' end end diff --git a/test/fragment_validation_with_ref_test.rb b/test/fragment_validation_with_ref_test.rb index dfc73e2f..63f8d7cb 100644 --- a/test/fragment_validation_with_ref_test.rb +++ b/test/fragment_validation_with_ref_test.rb @@ -55,12 +55,12 @@ def whole_schema_with_array end def test_validation_of_fragment - data = [{'content' => 'ohai', 'author' => 'Bob'}] + data = [{ 'content' => 'ohai', 'author' => 'Bob' }] assert_valid whole_schema, data, fragment: '#/definitions/posts' end def test_validation_of_fragment_with_array - data = {'content' => 'ohai', 'author' => 'Bob'} + data = { 'content' => 'ohai', 'author' => 'Bob' } assert_valid(whole_schema_with_array, data, fragment: '#/definitions/omg/links/0/schema',) end diff --git a/test/full_validation_test.rb b/test/full_validation_test.rb index bf6ae519..6b9643a8 100644 --- a/test/full_validation_test.rb +++ b/test/full_validation_test.rb @@ -2,7 +2,7 @@ class FullValidationTest < Minitest::Test def test_full_validation - data = {'b' => {'a' => 5}} + data = { 'b' => { 'a' => 5 } } schema = { 'type' => 'object', 'required' => ['b'], @@ -15,7 +15,7 @@ def test_full_validation errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) - data = {'c' => 5} + data = { 'c' => 5 } schema = { 'type' => 'object', 'required' => ['b'], @@ -33,7 +33,7 @@ def test_full_validation end def test_full_validation_with_instantiated_validator - data = {'b' => {'a' => 5}} + data = { 'b' => { 'a' => 5 } } schema = { 'type' => 'object', 'required' => ['b'], @@ -48,7 +48,7 @@ def test_full_validation_with_instantiated_validator assert(validator.validate(data).empty?) assert(validator.validate(data).empty?) - data = {'c' => 5} + data = { 'c' => 5 } schema = { 'type' => 'object', 'required' => ['b'], @@ -68,7 +68,7 @@ def test_full_validation_with_instantiated_validator end def test_full_validation_with_union_types - data = {'b' => 5} + data = { 'b' => 5 } schema = { 'type' => 'object', 'properties' => { @@ -93,7 +93,7 @@ def test_full_validation_with_union_types errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) - data = {'b' => 'a string'} + data = { 'b' => 'a string' } errors = JSON::Validator.fully_validate(schema, data) assert(errors.length == 1) @@ -107,13 +107,13 @@ def test_full_validation_with_union_types { 'type' => 'object', 'properties' => { - 'c' => {'type' => 'string'}, + 'c' => { 'type' => 'string' }, }, }, { 'type' => 'object', 'properties' => { - 'd' => {'type' => 'integer'}, + 'd' => { 'type' => 'integer' }, }, }, ], @@ -121,24 +121,24 @@ def test_full_validation_with_union_types }, } - data = {'b' => {'c' => 'taco'}} + data = { 'b' => { 'c' => 'taco' } } errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) - data = {'b' => {'d' => 6}} + data = { 'b' => { 'd' => 6 } } errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) - data = {'b' => {'c' => 6, 'd' => 'OH GOD'}} + data = { 'b' => { 'c' => 6, 'd' => 'OH GOD' } } errors = JSON::Validator.fully_validate(schema, data) assert(errors.length == 1) end def test_full_validation_with_object_errors - data = {'b' => {'a' => 5}} + data = { 'b' => { 'a' => 5 } } schema = { 'type' => 'object', 'required' => ['b'], @@ -151,7 +151,7 @@ def test_full_validation_with_object_errors errors = JSON::Validator.fully_validate(schema, data, errors_as_objects: true) assert(errors.empty?) - data = {'c' => 5} + data = { 'c' => 5 } schema = { 'type' => 'object', 'required' => ['b'], @@ -182,16 +182,16 @@ def test_full_validation_with_nested_required_properties 'type' => 'object', 'required' => ['a', 'b'], 'properties' => { - 'a' => {'type' => 'integer'}, - 'b' => {'type' => 'integer'}, - 'c' => {'type' => 'integer'}, - 'd' => {'type' => 'integer'}, - 'e' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, + 'b' => { 'type' => 'integer' }, + 'c' => { 'type' => 'integer' }, + 'd' => { 'type' => 'integer' }, + 'e' => { 'type' => 'integer' }, }, }, }, } - data = {'x' => {'a' => 5, 'd' => 5, 'e' => 'what?'}} + data = { 'x' => { 'a' => 5, 'd' => 5, 'e' => 'what?' } } errors = JSON::Validator.fully_validate(schema, data, errors_as_objects: true) assert_equal 2, errors.length @@ -212,19 +212,19 @@ def test_full_validation_with_nested_required_propertiesin_array 'type' => 'object', 'required' => ['a', 'b'], 'properties' => { - 'a' => {'type' => 'integer'}, - 'b' => {'type' => 'integer'}, - 'c' => {'type' => 'integer'}, - 'd' => {'type' => 'integer'}, - 'e' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer' }, + 'b' => { 'type' => 'integer' }, + 'c' => { 'type' => 'integer' }, + 'd' => { 'type' => 'integer' }, + 'e' => { 'type' => 'integer' }, }, }, }, }, } - missing_b = {'a' => 5} - e_is_wrong_type = {'a' => 5, 'b' => 5, 'e' => 'what?'} - data = {'x' => [missing_b, e_is_wrong_type]} + missing_b = { 'a' => 5 } + e_is_wrong_type = { 'a' => 5, 'b' => 5, 'e' => 'what?' } + data = { 'x' => [missing_b, e_is_wrong_type] } errors = JSON::Validator.fully_validate(schema, data, errors_as_objects: true) assert_equal 2, errors.length diff --git a/test/initialize_data_test.rb b/test/initialize_data_test.rb index 74558e19..4b6c9635 100644 --- a/test/initialize_data_test.rb +++ b/test/initialize_data_test.rb @@ -2,7 +2,7 @@ class InitializeDataTest < Minitest::Test def test_parse_character_string - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'hello world' assert(JSON::Validator.validate(schema, data)) @@ -17,7 +17,7 @@ def test_parse_character_string end def test_parse_integer_string - schema = {'type' => 'integer'} + schema = { 'type' => 'integer' } data = '42' assert(JSON::Validator.validate(schema, data)) @@ -43,7 +43,7 @@ def test_parse_hash_string end def test_parse_json_string - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = '"hello world"' assert(JSON::Validator.validate(schema, data)) @@ -56,7 +56,7 @@ def test_parse_json_string end def test_parse_plain_text_string - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'kapow' assert(JSON::Validator.validate(schema, data)) @@ -71,7 +71,7 @@ def test_parse_plain_text_string end def test_parse_valid_uri_string - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'http://foo.bar/' stub_request(:get, 'foo.bar').to_return(body: '"hello world"', status: 200) @@ -88,7 +88,7 @@ def test_parse_valid_uri_string end def test_parse_invalid_uri_string - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'http://foo.bar/' stub_request(:get, 'foo.bar').to_timeout @@ -111,7 +111,7 @@ def test_parse_invalid_uri_string end def test_parse_invalid_scheme_string - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'pick one: [1, 2, 3]' assert(JSON::Validator.validate(schema, data)) @@ -126,7 +126,7 @@ def test_parse_invalid_scheme_string end def test_parse_integer - schema = {'type' => 'integer'} + schema = { 'type' => 'integer' } data = 42 assert(JSON::Validator.validate(schema, data)) @@ -152,7 +152,7 @@ def test_parse_hash end def test_parse_character_string_with_instantiated_validator - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'hello world' v = JSON::Validator.new(schema) @@ -173,7 +173,7 @@ def test_parse_character_string_with_instantiated_validator end def test_parse_integer_string_with_instantiated_validator - schema = {'type' => 'integer'} + schema = { 'type' => 'integer' } data = '42' v = JSON::Validator.new(schema) @@ -215,7 +215,7 @@ def test_parse_hash_string_with_instantiated_validator end def test_parse_json_string_with_instantiated_validator - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = '"hello world"' v = JSON::Validator.new(schema) @@ -236,7 +236,7 @@ def test_parse_json_string_with_instantiated_validator end def test_parse_plain_text_string_with_instantiated_validator - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'kapow' v = JSON::Validator.new(schema) @@ -257,7 +257,7 @@ def test_parse_plain_text_string_with_instantiated_validator end def test_parse_valid_uri_string_with_instantiated_validator - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'http://foo.bar/' stub_request(:get, 'foo.bar').to_return(body: '"hello world"', status: 200) @@ -280,7 +280,7 @@ def test_parse_valid_uri_string_with_instantiated_validator end def test_parse_invalid_uri_string_with_instantiated_validator - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'http://foo.bar/' stub_request(:get, 'foo.bar').to_timeout @@ -312,7 +312,7 @@ def test_parse_invalid_uri_string_with_instantiated_validator end def test_parse_invalid_scheme_string_with_instantiated_validator - schema = {'type' => 'string'} + schema = { 'type' => 'string' } data = 'pick one: [1, 2, 3]' v = JSON::Validator.new(schema) @@ -333,7 +333,7 @@ def test_parse_invalid_scheme_string_with_instantiated_validator end def test_parse_integer_with_instantiated_validator - schema = {'type' => 'integer'} + schema = { 'type' => 'integer' } data = 42 v = JSON::Validator.new(schema) diff --git a/test/list_option_test.rb b/test/list_option_test.rb index 82bb97b7..5750e6b9 100644 --- a/test/list_option_test.rb +++ b/test/list_option_test.rb @@ -12,10 +12,10 @@ def test_list_option_reusing_schemas schema = JSON::Schema.new(schema_hash, uri) JSON::Validator.add_schema(schema) - data = {'a' => 1} + data = { 'a' => 1 } assert_valid uri.to_s, data, clear_cache: false - data = [{'a' => 1}] + data = [{ 'a' => 1 }] assert_valid uri.to_s, data, list: true end end diff --git a/test/merge_missing_values_test.rb b/test/merge_missing_values_test.rb index fac5fee7..21ec91db 100644 --- a/test/merge_missing_values_test.rb +++ b/test/merge_missing_values_test.rb @@ -23,23 +23,23 @@ def test_merge_missing_values_for_empty_hash end def test_merge_missing_values_for_new_values - original = {hello: 'world'} - updated = {'hello' => 'world', 'foo' => 'bar'} + original = { hello: 'world' } + updated = { 'hello' => 'world', 'foo' => 'bar' } JSON::Validator.merge_missing_values(updated, original) - assert_equal({:hello => 'world', 'foo' => 'bar'}, original) + assert_equal({ :hello => 'world', 'foo' => 'bar' }, original) end def test_merge_missing_values_for_nested_array - original = [:hello, 'world', 1, 2, 3, {:foo => :bar, 'baz' => 'qux'}] - updated = ['hello', 'world', 1, 2, 3, {'foo' => 'bar', 'baz' => 'qux', 'this_is' => 'new'}] + original = [:hello, 'world', 1, 2, 3, { :foo => :bar, 'baz' => 'qux' }] + updated = ['hello', 'world', 1, 2, 3, { 'foo' => 'bar', 'baz' => 'qux', 'this_is' => 'new' }] JSON::Validator.merge_missing_values(updated, original) - assert_equal([:hello, 'world', 1, 2, 3, {:foo => :bar, 'baz' => 'qux', 'this_is' => 'new'}], original) + assert_equal([:hello, 'world', 1, 2, 3, { :foo => :bar, 'baz' => 'qux', 'this_is' => 'new' }], original) end def test_merge_missing_values_for_nested_hash - original = {hello: 'world', foo: ['bar', :baz, {uno: {due: 3}}]} - updated = {'hello' => 'world', 'foo' => ['bar', 'baz', {'uno' => {'due' => 3, 'this_is' => 'new'}}], 'ack' => 'sed'} + original = { hello: 'world', foo: ['bar', :baz, { uno: { due: 3 } }] } + updated = { 'hello' => 'world', 'foo' => ['bar', 'baz', { 'uno' => { 'due' => 3, 'this_is' => 'new' } }], 'ack' => 'sed' } JSON::Validator.merge_missing_values(updated, original) - assert_equal({:hello => 'world', :foo => ['bar', :baz, {uno: {:due => 3, 'this_is' => 'new'}}], 'ack' => 'sed'}, original) + assert_equal({ :hello => 'world', :foo => ['bar', :baz, { uno: { :due => 3, 'this_is' => 'new' } }], 'ack' => 'sed' }, original) end end diff --git a/test/one_of_test.rb b/test/one_of_test.rb index 21184209..2e965a1d 100644 --- a/test/one_of_test.rb +++ b/test/one_of_test.rb @@ -12,13 +12,13 @@ def test_one_of_with_string_patterns '$schema' => 'http://json-schema.org/draft-04/schema#', 'oneOf' => [ { - 'properties' => {'a' => {'type' => 'string', 'pattern' => 'foo'}}, + 'properties' => { 'a' => { 'type' => 'string', 'pattern' => 'foo' } }, }, { - 'properties' => {'a' => {'type' => 'string', 'pattern' => 'bar'}}, + 'properties' => { 'a' => { 'type' => 'string', 'pattern' => 'bar' } }, }, { - 'properties' => {'a' => {'type' => 'string', 'pattern' => 'baz'}}, + 'properties' => { 'a' => { 'type' => 'string', 'pattern' => 'baz' } }, }, ], } @@ -34,13 +34,13 @@ def test_one_of_sub_errors '$schema' => 'http://json-schema.org/draft-04/schema#', 'oneOf' => [ { - 'properties' => {'a' => {'type' => 'string', 'pattern' => 'foo'}}, + 'properties' => { 'a' => { 'type' => 'string', 'pattern' => 'foo' } }, }, { - 'properties' => {'a' => {'type' => 'string', 'pattern' => 'bar'}}, + 'properties' => { 'a' => { 'type' => 'string', 'pattern' => 'bar' } }, }, { - 'properties' => {'a' => {'type' => 'number', 'minimum' => 10}}, + 'properties' => { 'a' => { 'type' => 'number', 'minimum' => 10 } }, }, ], } @@ -57,13 +57,13 @@ def test_one_of_sub_errors_message '$schema' => 'http://json-schema.org/draft-04/schema#', 'oneOf' => [ { - 'properties' => {'a' => {'type' => 'string', 'pattern' => 'foo'}}, + 'properties' => { 'a' => { 'type' => 'string', 'pattern' => 'foo' } }, }, { - 'properties' => {'a' => {'type' => 'string', 'pattern' => 'bar'}}, + 'properties' => { 'a' => { 'type' => 'string', 'pattern' => 'bar' } }, }, { - 'properties' => {'a' => {'type' => 'number', 'minimum' => 10}}, + 'properties' => { 'a' => { 'type' => 'number', 'minimum' => 10 } }, }, ], } diff --git a/test/relative_definition_test.rb b/test/relative_definition_test.rb index cc2c9793..a50379ca 100644 --- a/test/relative_definition_test.rb +++ b/test/relative_definition_test.rb @@ -2,16 +2,16 @@ class RelativeDefinitionTest < Minitest::Test def test_definition_schema - assert_valid schema_fixture_path('definition_schema.json'), {'a' => 5} + assert_valid schema_fixture_path('definition_schema.json'), { 'a' => 5 } end def test_definition_schema_with_special_characters - assert_valid schema_fixture_path('definition_schema_with_special_characters.json'), {'a' => 5} + assert_valid schema_fixture_path('definition_schema_with_special_characters.json'), { 'a' => 5 } end def test_relative_definition schema = schema_fixture_path('relative_definition_schema.json') - assert_valid schema, {'a' => 5} - refute_valid schema, {'a' => 'foo'} + assert_valid schema, { 'a' => 5 } + refute_valid schema, { 'a' => 'foo' } end end diff --git a/test/ruby_schema_test.rb b/test/ruby_schema_test.rb index 5b756fd9..7304c894 100644 --- a/test/ruby_schema_test.rb +++ b/test/ruby_schema_test.rb @@ -6,8 +6,8 @@ def test_string_keys 'type' => 'object', 'required' => ['a'], 'properties' => { - 'a' => {'type' => 'integer', 'default' => 42}, - 'b' => {'type' => 'integer'}, + 'a' => { 'type' => 'integer', 'default' => 42 }, + 'b' => { 'type' => 'integer' }, }, } @@ -19,8 +19,8 @@ def test_symbol_keys type: 'object', required: ['a'], properties: { - a: {type: 'integer', default: 42}, - b: {type: 'integer'}, + a: { type: 'integer', default: 42 }, + b: { type: 'integer' }, }, } diff --git a/test/schema_validation_test.rb b/test/schema_validation_test.rb index 1d66865b..7106c78a 100644 --- a/test/schema_validation_test.rb +++ b/test/schema_validation_test.rb @@ -123,7 +123,7 @@ def symbolized_schema end def test_draft03_validation - data = {'b' => {'a' => 5}} + data = { 'b' => { 'a' => 5 } } assert(JSON::Validator.validate(valid_schema_v3, data, validate_schema: true, version: :draft3)) assert(!JSON::Validator.validate(invalid_schema_v3, data, validate_schema: true, version: :draft3)) end @@ -138,7 +138,7 @@ def test_validate_just_schema_draft03 end def test_draft04_validation - data = {'b' => {'a' => 5}} + data = { 'b' => { 'a' => 5 } } assert(JSON::Validator.validate(valid_schema_v4, data, validate_schema: true, version: :draft4)) assert(!JSON::Validator.validate(invalid_schema_v4, data, validate_schema: true, version: :draft4)) end @@ -153,7 +153,7 @@ def test_validate_just_schema_draft04 end def test_validate_schema_3_without_version_option - data = {'b' => {'a' => 5}} + data = { 'b' => { 'a' => 5 } } assert(JSON::Validator.validate(valid_schema_v3, data, validate_schema: true)) assert(!JSON::Validator.validate(invalid_schema_v3, data, validate_schema: true)) end @@ -161,7 +161,7 @@ def test_validate_schema_3_without_version_option def test_schema_validation_from_different_directory Dir.mktmpdir do |tmpdir| Dir.chdir(tmpdir) do - data = {'b' => {'a' => 5}} + data = { 'b' => { 'a' => 5 } } assert(JSON::Validator.validate(valid_schema_v4, data, validate_schema: true, version: :draft4)) assert(!JSON::Validator.validate(invalid_schema_v4, data, validate_schema: true, version: :draft4)) end diff --git a/test/stringify_test.rb b/test/stringify_test.rb index d0315898..78003fb9 100644 --- a/test/stringify_test.rb +++ b/test/stringify_test.rb @@ -6,7 +6,7 @@ def test_stringify_on_hash :a => 'foo', 'b' => :bar, } - assert_equal({'a' => 'foo', 'b' => 'bar'}, JSON::Schema.stringify(hash), 'symbol keys should be converted to strings') + assert_equal({ 'a' => 'foo', 'b' => 'bar' }, JSON::Schema.stringify(hash), 'symbol keys should be converted to strings') end def test_stringify_on_array @@ -22,7 +22,7 @@ def test_stringify_on_hash_of_arrays :a => [:foo], 'b' => :bar, } - assert_equal({'a' => ['foo'], 'b' => 'bar'}, JSON::Schema.stringify(hash), 'symbols in a nested array should be converted to strings') + assert_equal({ 'a' => ['foo'], 'b' => 'bar' }, JSON::Schema.stringify(hash), 'symbols in a nested array should be converted to strings') end def test_stringify_on_array_of_hashes @@ -32,7 +32,7 @@ def test_stringify_on_array_of_hashes b: :bar, }, ] - assert_equal(['a', {'b' => 'bar'}], JSON::Schema.stringify(array), 'symbols keys in a nested hash should be converted to strings') + assert_equal(['a', { 'b' => 'bar' }], JSON::Schema.stringify(array), 'symbols keys in a nested hash should be converted to strings') end def test_stringify_on_hash_of_hashes @@ -43,6 +43,6 @@ def test_stringify_on_hash_of_hashes }, }, } - assert_equal({'a' => {'b' => {'foo' => 'bar'} } }, JSON::Schema.stringify(hash), 'symbols in a nested hash of hashes should be converted to strings') + assert_equal({ 'a' => { 'b' => { 'foo' => 'bar' } } }, JSON::Schema.stringify(hash), 'symbols in a nested hash of hashes should be converted to strings') end end diff --git a/test/support/array_validation.rb b/test/support/array_validation.rb index edc54064..bcad9d25 100644 --- a/test/support/array_validation.rb +++ b/test/support/array_validation.rb @@ -11,7 +11,7 @@ def test_items_single_schema refute_valid schema, ['a', 1] # other types are disregarded - assert_valid schema, {'a' => 'foo'} + assert_valid schema, { 'a' => 'foo' } end def test_items_multiple_schemas @@ -104,9 +104,9 @@ def test_unique_items assert_valid schema, [[1], [2]] refute_valid schema, [[1], [1]] - assert_valid schema, [{'b' => 1}, {'c' => 2}] - assert_valid schema, [{'b' => 1}, {'c' => 1}] - refute_valid schema, [{'b' => 1}, {'b' => 1}] + assert_valid schema, [{ 'b' => 1 }, { 'c' => 2 }] + assert_valid schema, [{ 'b' => 1 }, { 'c' => 1 }] + refute_valid schema, [{ 'b' => 1 }, { 'b' => 1 }] end end end diff --git a/test/support/enum_validation.rb b/test/support/enum_validation.rb index c473ea04..2538f8bf 100644 --- a/test/support/enum_validation.rb +++ b/test/support/enum_validation.rb @@ -3,7 +3,7 @@ module V1_V2 def test_enum_optional schema = { 'properties' => { - 'a' => {'enum' => [1, 'boo', [1, 2, 3], {'a' => 'b'}], 'optional' => true}, + 'a' => { 'enum' => [1, 'boo', [1, 2, 3], { 'a' => 'b' }], 'optional' => true }, }, } @@ -16,7 +16,7 @@ module V3_V4 def test_enum_optional schema = { 'properties' => { - 'a' => {'enum' => [1, 'boo', [1, 2, 3], {'a' => 'b'}]}, + 'a' => { 'enum' => [1, 'boo', [1, 2, 3], { 'a' => 'b' }] }, }, } @@ -29,7 +29,7 @@ module General def test_enum_general schema = { 'properties' => { - 'a' => {'enum' => [1, 'boo', [1, 2, 3], {'a' => 'b'}]}, + 'a' => { 'enum' => [1, 'boo', [1, 2, 3], { 'a' => 'b' }] }, }, } @@ -42,7 +42,7 @@ def test_enum_general data['a'] = [1, 2, 3] assert_valid schema, data - data['a'] = {'a' => 'b'} + data['a'] = { 'a' => 'b' } assert_valid schema, data data['a'] = 'taco' @@ -121,7 +121,7 @@ def test_enum_integer_excludes_float def test_enum_with_schema_validation schema = { 'properties' => { - 'a' => {'enum' => [1, 'boo', [1, 2, 3], {'a' => 'b'}]}, + 'a' => { 'enum' => [1, 'boo', [1, 2, 3], { 'a' => 'b' }] }, }, } data = { 'a' => 1 } diff --git a/test/support/number_validation.rb b/test/support/number_validation.rb index 3605b7db..7d387eef 100644 --- a/test/support/number_validation.rb +++ b/test/support/number_validation.rb @@ -7,14 +7,14 @@ def test_minimum }, } - assert_valid schema, {'a' => 5} - assert_valid schema, {'a' => 6} + assert_valid schema, { 'a' => 5 } + assert_valid schema, { 'a' => 6 } - refute_valid schema, {'a' => 4} - refute_valid schema, {'a' => 4.99999} + refute_valid schema, { 'a' => 4 } + refute_valid schema, { 'a' => 4.99999 } # other types are disregarded - assert_valid schema, {'a' => 'str'} + assert_valid schema, { 'a' => 'str' } end def test_exclusive_minimum @@ -24,9 +24,9 @@ def test_exclusive_minimum }, } - assert_valid schema, {'a' => 6} - assert_valid schema, {'a' => 5.0001} - refute_valid schema, {'a' => 5} + assert_valid schema, { 'a' => 6 } + assert_valid schema, { 'a' => 5.0001 } + refute_valid schema, { 'a' => 5 } end def test_maximum @@ -36,11 +36,11 @@ def test_maximum }, } - assert_valid schema, {'a' => 4} - assert_valid schema, {'a' => 5} + assert_valid schema, { 'a' => 4 } + assert_valid schema, { 'a' => 5 } - refute_valid schema, {'a' => 6} - refute_valid schema, {'a' => 5.0001} + refute_valid schema, { 'a' => 6 } + refute_valid schema, { 'a' => 5.0001 } end def test_exclusive_maximum @@ -50,9 +50,9 @@ def test_exclusive_maximum }, } - assert_valid schema, {'a' => 4} - assert_valid schema, {'a' => 4.99999} - refute_valid schema, {'a' => 5} + assert_valid schema, { 'a' => 4 } + assert_valid schema, { 'a' => 4.99999 } + refute_valid schema, { 'a' => 5 } end end @@ -70,13 +70,13 @@ def test_multiple_of }, } - assert_valid schema, {'a' => 0} + assert_valid schema, { 'a' => 0 } - assert_valid schema, {'a' => 2.2} - refute_valid schema, {'a' => 3.4} + assert_valid schema, { 'a' => 2.2 } + refute_valid schema, { 'a' => 3.4 } # other types are disregarded - assert_valid schema, {'a' => 'hi'} + assert_valid schema, { 'a' => 'hi' } end end end diff --git a/test/support/object_validation.rb b/test/support/object_validation.rb index b60a57e9..96c80740 100644 --- a/test/support/object_validation.rb +++ b/test/support/object_validation.rb @@ -8,8 +8,8 @@ def test_additional_properties_false 'additionalProperties' => false, } - assert_valid schema, {'a' => 1} - refute_valid schema, {'a' => 1, 'b' => 2} + assert_valid schema, { 'a' => 1 } + refute_valid schema, { 'a' => 1, 'b' => 2 } end def test_additional_properties_schema @@ -20,9 +20,9 @@ def test_additional_properties_schema 'additionalProperties' => { 'type' => 'string' }, } - assert_valid schema, {'a' => 1} - assert_valid schema, {'a' => 1, 'b' => 'hi'} - refute_valid schema, {'a' => 1, 'b' => 2} + assert_valid schema, { 'a' => 1 } + assert_valid schema, { 'a' => 1, 'b' => 'hi' } + refute_valid schema, { 'a' => 1, 'b' => 2 } end end @@ -34,9 +34,9 @@ def test_pattern_properties }, } - assert_valid schema, {'1 taco' => 1, '20 taco' => 20} - assert_valid schema, {'foo' => true, '1 taco' => 1} - refute_valid schema, {'1 taco' => 'yum'} + assert_valid schema, { '1 taco' => 1, '20 taco' => 20 } + assert_valid schema, { 'foo' => true, '1 taco' => 1 } + refute_valid schema, { '1 taco' => 'yum' } end def test_pattern_properties_additional_properties_false @@ -47,9 +47,9 @@ def test_pattern_properties_additional_properties_false 'additionalProperties' => false, } - assert_valid schema, {'1 taco' => 1} - refute_valid schema, {'1 taco' => 'yum'} - refute_valid schema, {'1 taco' => 1, 'foo' => true} + assert_valid schema, { '1 taco' => 1 } + refute_valid schema, { '1 taco' => 'yum' } + refute_valid schema, { '1 taco' => 1, 'foo' => true } end def test_pattern_properties_additional_properties_schema @@ -60,9 +60,9 @@ def test_pattern_properties_additional_properties_schema 'additionalProperties' => { 'type' => 'string' }, } - assert_valid schema, {'1 taco' => 1} - assert_valid schema, {'1 taco' => 1, 'foo' => 'bar'} - refute_valid schema, {'1 taco' => 1, 'foo' => 2} + assert_valid schema, { '1 taco' => 1 } + assert_valid schema, { '1 taco' => 1, 'foo' => 'bar' } + refute_valid schema, { '1 taco' => 1, 'foo' => 2 } end end end diff --git a/test/support/strict_validation.rb b/test/support/strict_validation.rb index 079bc7b4..e0608e42 100644 --- a/test/support/strict_validation.rb +++ b/test/support/strict_validation.rb @@ -3,21 +3,21 @@ def test_strict_properties schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'properties' => { - 'a' => {'type' => 'string'}, - 'b' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, + 'b' => { 'type' => 'string' }, }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 'c'} + data = { 'a' => 'a', 'b' => 'b', 'c' => 'c' } assert(!JSON::Validator.validate(schema, data, strict: true)) end @@ -32,56 +32,56 @@ def test_strict_properties_additional_props schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'properties' => { - 'a' => {'type' => 'string'}, - 'b' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, + 'b' => { 'type' => 'string' }, }, - 'additionalProperties' => {'type' => 'integer'}, + 'additionalProperties' => { 'type' => 'integer' }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 'c'} + data = { 'a' => 'a', 'b' => 'b', 'c' => 'c' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 3} + data = { 'a' => 'a', 'b' => 'b', 'c' => 3 } assert(JSON::Validator.validate(schema, data, strict: true)) end def test_strict_properties_pattern_props schema = { 'properties' => { - 'a' => {'type' => 'string'}, - 'b' => {'type' => 'string'}, + 'a' => { 'type' => 'string' }, + 'b' => { 'type' => 'string' }, }, - 'patternProperties' => {'\\d+ taco' => {'type' => 'integer'}}, + 'patternProperties' => { '\\d+ taco' => { 'type' => 'integer' } }, } - data = {'a' => 'a'} + data = { 'a' => 'a' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'b' => 'b'} + data = { 'b' => 'b' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b'} + data = { 'a' => 'a', 'b' => 'b' } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 'c'} + data = { 'a' => 'a', 'b' => 'b', 'c' => 'c' } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', 'c' => 3} + data = { 'a' => 'a', 'b' => 'b', 'c' => 3 } assert(!JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', '23 taco' => 3} + data = { 'a' => 'a', 'b' => 'b', '23 taco' => 3 } assert(JSON::Validator.validate(schema, data, strict: true)) - data = {'a' => 'a', 'b' => 'b', '23 taco' => 'cheese'} + data = { 'a' => 'a', 'b' => 'b', '23 taco' => 'cheese' } assert(!JSON::Validator.validate(schema, data, strict: true)) end end diff --git a/test/support/string_validation.rb b/test/support/string_validation.rb index f1c49871..f6b5a815 100644 --- a/test/support/string_validation.rb +++ b/test/support/string_validation.rb @@ -7,11 +7,11 @@ def test_minlength }, } - assert_valid schema, {'a' => 't'} - refute_valid schema, {'a' => ''} + assert_valid schema, { 'a' => 't' } + refute_valid schema, { 'a' => '' } # other types are disregarded - assert_valid schema, {'a' => 5} + assert_valid schema, { 'a' => 5 } end def test_maxlength @@ -21,12 +21,12 @@ def test_maxlength }, } - assert_valid schema, {'a' => 'tt'} - assert_valid schema, {'a' => ''} - refute_valid schema, {'a' => 'ttt'} + assert_valid schema, { 'a' => 'tt' } + assert_valid schema, { 'a' => '' } + refute_valid schema, { 'a' => 'ttt' } # other types are disregarded - assert_valid schema, {'a' => 5} + assert_valid schema, { 'a' => 5 } end def test_pattern @@ -36,11 +36,11 @@ def test_pattern }, } - assert_valid schema, {'a' => '156 taco bell'} - refute_valid schema, {'a' => 'x taco'} + assert_valid schema, { 'a' => '156 taco bell' } + refute_valid schema, { 'a' => 'x taco' } # other types are disregarded - assert_valid schema, {'a' => 5} + assert_valid schema, { 'a' => 5 } end end @@ -57,8 +57,8 @@ def test_format_unknown }, } - assert_valid schema, {'a' => 'absolutely anything!'} - assert_valid schema, {'a' => ''} + assert_valid schema, { 'a' => 'absolutely anything!' } + assert_valid schema, { 'a' => '' } end def test_format_union @@ -71,8 +71,8 @@ def test_format_union }, } - assert_valid schema, {'a' => nil} - refute_valid schema, {'a' => 'wrong'} + assert_valid schema, { 'a' => nil } + refute_valid schema, { 'a' => 'wrong' } end def test_format_ipv4 @@ -82,14 +82,14 @@ def test_format_ipv4 }, } - assert_valid schema, {'a' => '1.1.1.1'} - refute_valid schema, {'a' => '1.1.1'} - refute_valid schema, {'a' => '1.1.1.300'} - refute_valid schema, {'a' => '1.1.1'} - refute_valid schema, {'a' => '1.1.1.1b'} + assert_valid schema, { 'a' => '1.1.1.1' } + refute_valid schema, { 'a' => '1.1.1' } + refute_valid schema, { 'a' => '1.1.1.300' } + refute_valid schema, { 'a' => '1.1.1' } + refute_valid schema, { 'a' => '1.1.1.1b' } # other types are disregarded - assert_valid schema, {'a' => 5} + assert_valid schema, { 'a' => 5 } end def test_format_ipv6 @@ -99,17 +99,17 @@ def test_format_ipv6 }, } - assert_valid schema, {'a' => '1111:2222:8888:9999:aaaa:cccc:eeee:ffff'} - assert_valid schema, {'a' => '1111:0:8888:0:0:0:eeee:ffff'} - assert_valid schema, {'a' => '1111:2222:8888::eeee:ffff'} - assert_valid schema, {'a' => '::1'} - - refute_valid schema, {'a' => '1111:2222:8888:99999:aaaa:cccc:eeee:ffff'} - refute_valid schema, {'a' => '1111:2222:8888:9999:aaaa:cccc:eeee:gggg'} - refute_valid schema, {'a' => '1111:2222::9999::cccc:eeee:ffff'} - refute_valid schema, {'a' => '1111:2222:8888:9999:aaaa:cccc:eeee:ffff:bbbb'} - refute_valid schema, {'a' => '42'} - refute_valid schema, {'a' => 'b'} + assert_valid schema, { 'a' => '1111:2222:8888:9999:aaaa:cccc:eeee:ffff' } + assert_valid schema, { 'a' => '1111:0:8888:0:0:0:eeee:ffff' } + assert_valid schema, { 'a' => '1111:2222:8888::eeee:ffff' } + assert_valid schema, { 'a' => '::1' } + + refute_valid schema, { 'a' => '1111:2222:8888:99999:aaaa:cccc:eeee:ffff' } + refute_valid schema, { 'a' => '1111:2222:8888:9999:aaaa:cccc:eeee:gggg' } + refute_valid schema, { 'a' => '1111:2222::9999::cccc:eeee:ffff' } + refute_valid schema, { 'a' => '1111:2222:8888:9999:aaaa:cccc:eeee:ffff:bbbb' } + refute_valid schema, { 'a' => '42' } + refute_valid schema, { 'a' => 'b' } end end @@ -123,16 +123,16 @@ def test_format_time }, } - assert_valid schema, {'a' => '12:00:00'} - refute_valid schema, {'a' => '12:00'} - refute_valid schema, {'a' => '12:00:60'} - refute_valid schema, {'a' => '12:60:00'} - refute_valid schema, {'a' => '24:00:00'} - refute_valid schema, {'a' => '0:00:00'} - refute_valid schema, {'a' => '-12:00:00'} - refute_valid schema, {'a' => '12:00:00b'} - assert_valid schema, {'a' => '12:00:00'} - refute_valid schema, {'a' => "12:00:00\nabc"} + assert_valid schema, { 'a' => '12:00:00' } + refute_valid schema, { 'a' => '12:00' } + refute_valid schema, { 'a' => '12:00:60' } + refute_valid schema, { 'a' => '12:60:00' } + refute_valid schema, { 'a' => '24:00:00' } + refute_valid schema, { 'a' => '0:00:00' } + refute_valid schema, { 'a' => '-12:00:00' } + refute_valid schema, { 'a' => '12:00:00b' } + assert_valid schema, { 'a' => '12:00:00' } + refute_valid schema, { 'a' => "12:00:00\nabc" } end def test_format_date @@ -142,13 +142,13 @@ def test_format_date }, } - assert_valid schema, {'a' => '2010-01-01'} - refute_valid schema, {'a' => '2010-01-32'} - refute_valid schema, {'a' => 'n2010-01-01'} - refute_valid schema, {'a' => '2010-1-01'} - refute_valid schema, {'a' => '2010-01-1'} - refute_valid schema, {'a' => '2010-01-01n'} - refute_valid schema, {'a' => "2010-01-01\nabc"} + assert_valid schema, { 'a' => '2010-01-01' } + refute_valid schema, { 'a' => '2010-01-32' } + refute_valid schema, { 'a' => 'n2010-01-01' } + refute_valid schema, { 'a' => '2010-1-01' } + refute_valid schema, { 'a' => '2010-01-1' } + refute_valid schema, { 'a' => '2010-01-01n' } + refute_valid schema, { 'a' => "2010-01-01\nabc" } end end end diff --git a/test/support/type_validation.rb b/test/support/type_validation.rb index 0d229b55..1202a9e0 100644 --- a/test/support/type_validation.rb +++ b/test/support/type_validation.rb @@ -19,10 +19,10 @@ module SimpleTypeTests schema = { 'properties' => { 'a' => { 'type' => name } }, } - assert_valid schema, {'a' => value} + assert_valid schema, { 'a' => value } other_values.each do |other_value| - refute_valid schema, {'a' => other_value} + refute_valid schema, { 'a' => other_value } end end @@ -64,18 +64,18 @@ def test_union_type_with_schemas 'properties' => { 'a' => { 'type' => [ - {'type' => 'string'}, - {'type' => 'object', 'properties' => { 'b' => { 'type' => 'integer' }}}, + { 'type' => 'string' }, + { 'type' => 'object', 'properties' => { 'b' => { 'type' => 'integer' } } }, ], }, }, } - assert_valid schema, {'a' => 'test'} - refute_valid schema, {'a' => 5} + assert_valid schema, { 'a' => 'test' } + refute_valid schema, { 'a' => 5 } - assert_valid schema, {'a' => {'b' => 5}} - refute_valid schema, {'a' => {'b' => 'taco'}} + assert_valid schema, { 'a' => { 'b' => 5 } } + refute_valid schema, { 'a' => { 'b' => 'taco' } } end end end diff --git a/test/uri_parsing_test.rb b/test/uri_parsing_test.rb index 3637c8f9..d9b87eca 100644 --- a/test/uri_parsing_test.rb +++ b/test/uri_parsing_test.rb @@ -36,7 +36,7 @@ def test_schema_ref_with_empty_fragment }, }, } - data = {'names' => [{'first' => 'john'}]} + data = { 'names' => [{ 'first' => 'john' }] } assert_valid schema, data end @@ -56,12 +56,12 @@ def test_schema_ref_from_file_with_spaces }, }, } - data = {'names' => [{'first' => 'john'}]} + data = { 'names' => [{ 'first' => 'john' }] } assert_valid schema, data end def test_schema_from_file_with_spaces - data = {'first' => 'john'} + data = { 'first' => 'john' } schema = 'test/schemas/ref john with spaces schema.json' assert_valid schema, data end diff --git a/test/uri_util_test.rb b/test/uri_util_test.rb index 831750a1..d962cae6 100644 --- a/test/uri_util_test.rb +++ b/test/uri_util_test.rb @@ -107,7 +107,7 @@ def test_validator_clear_cache_for_normalized_uri assert_equal(cached_uri, JSON::Util::URI.normalized_uri('foo')) - validation_errors({'type' => 'string'}, 'foo', clear_cache: true) + validation_errors({ 'type' => 'string' }, 'foo', clear_cache: true) refute_equal(cached_uri, JSON::Util::URI.normalized_uri('foo')) end @@ -119,7 +119,7 @@ def test_validator_clear_cache_for_parse assert_equal(cached_uri, JSON::Util::URI.parse('foo')) - validation_errors({'type' => 'string'}, 'foo', clear_cache: true) + validation_errors({ 'type' => 'string' }, 'foo', clear_cache: true) refute_equal(cached_uri, JSON::Util::URI.parse('foo')) end From 110ec696f2a6937fd0b7acc62bad1bf13de4b338 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 12:31:27 +0100 Subject: [PATCH 8/8] rubocop: Fix Layout/SpaceInsideReferenceBrackets --- .rubocop_todo.yml | 9 --------- json-schema.gemspec | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ffe7dad8..191683f0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,15 +14,6 @@ Layout/MultilineMethodCallBraceLayout: Exclude: - 'test/common_test_suite_test.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBrackets: space, no_space -Layout/SpaceInsideReferenceBrackets: - Exclude: - - 'json-schema.gemspec' - # Offense count: 1 Lint/AmbiguousBlockAssociation: Exclude: diff --git a/json-schema.gemspec b/json-schema.gemspec index 52c4aea5..5a371aed 100644 --- a/json-schema.gemspec +++ b/json-schema.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.email = 'voxpupuli@groups.io' s.homepage = 'http://github.com/voxpupuli/json-schema/' s.summary = 'Ruby JSON Schema Validator' - s.files = Dir[ 'lib/**/*', 'resources/*.json' ] + s.files = Dir['lib/**/*', 'resources/*.json'] s.require_path = 'lib' s.extra_rdoc_files = ['README.md', 'LICENSE.md'] s.required_ruby_version = '>= 2.5'