From 934e0bf6c557d2eff712042aef92860ae92e959b Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 09:59:55 +0100 Subject: [PATCH 1/5] rubocop: Fix Style/ZeroLengthPredicate --- .rubocop_todo.yml | 6 ------ lib/json-schema/attributes/properties.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 97186c62..437596bc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -889,12 +889,6 @@ Style/WordArray: EnforcedStyle: percent MinSize: 3 -# Offense count: 1 -# Cop supports --auto-correct. -Style/ZeroLengthPredicate: - Exclude: - - 'lib/json-schema/attributes/properties.rb' - # Offense count: 74 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. diff --git a/lib/json-schema/attributes/properties.rb b/lib/json-schema/attributes/properties.rb index cbb81125..d731eac8 100644 --- a/lib/json-schema/attributes/properties.rb +++ b/lib/json-schema/attributes/properties.rb @@ -55,7 +55,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options end end - if diff.size > 0 + unless diff.empty? properties = diff.keys.join(', ') message = "The property '#{build_fragment(fragments)}' contained undefined properties: '#{properties}'" validation_error(processor, message, fragments, current_schema, self, options[:record_errors]) From 41ba2e324729c286bd8ae7806a95983136baa8ee Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 10:02:41 +0100 Subject: [PATCH 2/5] rubocop: Fix Style/TrailingCommaInHashLiteral --- .rubocop.yml | 4 + .rubocop_todo.yml | 11 -- Rakefile | 2 +- lib/json-schema/attribute.rb | 2 +- lib/json-schema/validator.rb | 2 +- lib/json-schema/validators/draft1.rb | 4 +- lib/json-schema/validators/draft2.rb | 4 +- lib/json-schema/validators/draft3.rb | 4 +- lib/json-schema/validators/draft4.rb | 4 +- lib/json-schema/validators/draft6.rb | 4 +- test/bad_schema_ref_test.rb | 4 +- test/custom_format_test.rb | 6 +- test/draft1_test.rb | 22 +-- test/draft2_test.rb | 16 +- test/draft3_test.rb | 86 +++++------ test/draft4_test.rb | 172 +++++++++++----------- test/draft6_test.rb | 6 +- test/extended_schema_test.rb | 26 ++-- test/fragment_resolution_test.rb | 36 ++--- test/fragment_validation_with_ref_test.rb | 32 ++-- test/full_validation_test.rb | 70 ++++----- test/list_option_test.rb | 2 +- test/load_ref_schema_test.rb | 6 +- test/min_items_test.rb | 2 +- test/one_of_test.rb | 6 +- test/ruby_schema_test.rb | 24 +-- test/schema_validation_test.rb | 46 +++--- test/stringify_test.rb | 12 +- test/support/array_validation.rb | 6 +- test/support/enum_validation.rb | 34 ++--- test/support/number_validation.rb | 20 +-- test/support/object_validation.rb | 20 +-- test/support/strict_validation.rb | 12 +- test/support/string_validation.rb | 38 ++--- test/support/type_validation.rb | 10 +- test/uri_parsing_test.rb | 22 +-- test/validator_schema_reader_test.rb | 2 +- 37 files changed, 386 insertions(+), 393 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e5ddcbef..f146f6e8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,3 +8,7 @@ require: AllCops: TargetRubyVersion: 2.5 NewCops: enable + +Style/TrailingCommaInHashLiteral: + Enabled: True + EnforcedStyleForMultiline: consistent_comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 437596bc..7e5decf7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -863,17 +863,6 @@ Style/TrailingCommaInArrayLiteral: - 'test/support/test_helper.rb' - 'test/uri_parsing_test.rb' -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'test/custom_format_test.rb' - - 'test/draft6_test.rb' - - 'test/full_validation_test.rb' - - 'test/one_of_test.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AllowNamedUnderscoreVariables. diff --git a/Rakefile b/Rakefile index f9fafbbe..aed95d60 100644 --- a/Rakefile +++ b/Rakefile @@ -24,7 +24,7 @@ task :update_meta_schemas do puts "Updating meta-schemas..." id_mappings = { - 'http://json-schema.org/draft/schema#' => 'https://raw.githubusercontent.com/json-schema-org/json-schema-spec/master/schema.json' + 'http://json-schema.org/draft/schema#' => 'https://raw.githubusercontent.com/json-schema-org/json-schema-spec/master/schema.json', } require 'open-uri' diff --git a/lib/json-schema/attribute.rb b/lib/json-schema/attribute.rb index a5fff92a..83450673 100644 --- a/lib/json-schema/attribute.rb +++ b/lib/json-schema/attribute.rb @@ -31,7 +31,7 @@ def self.validation_errors(validator) "object" => Hash, "array" => Array, "null" => NilClass, - "any" => Object + "any" => Object, } def self.data_valid_for_type?(data, type) diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index b7b36f13..8377223c 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -27,7 +27,7 @@ class Validator :insert_defaults => false, :clear_cache => false, :strict => false, - :parse_data => true + :parse_data => true, } @@validators = {} @@default_validator = nil diff --git a/lib/json-schema/validators/draft1.rb b/lib/json-schema/validators/draft1.rb index f5b63d1b..4843850b 100644 --- a/lib/json-schema/validators/draft1.rb +++ b/lib/json-schema/validators/draft1.rb @@ -21,7 +21,7 @@ def initialize "pattern" => JSON::Schema::PatternAttribute, "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute, "items" => JSON::Schema::ItemsAttribute, - "extends" => JSON::Schema::ExtendsAttribute + "extends" => JSON::Schema::ExtendsAttribute, } @default_formats = { 'date-time' => DateTimeFormat, @@ -29,7 +29,7 @@ def initialize 'time' => TimeFormat, 'ip-address' => IP4Format, 'ipv6' => IP6Format, - 'uri' => UriFormat + 'uri' => UriFormat, } @formats = @default_formats.clone @uri = JSON::Util::URI.parse("http://json-schema.org/draft-01/schema#") diff --git a/lib/json-schema/validators/draft2.rb b/lib/json-schema/validators/draft2.rb index 0a355c31..62510008 100644 --- a/lib/json-schema/validators/draft2.rb +++ b/lib/json-schema/validators/draft2.rb @@ -22,7 +22,7 @@ def initialize "pattern" => JSON::Schema::PatternAttribute, "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute, "items" => JSON::Schema::ItemsAttribute, - "extends" => JSON::Schema::ExtendsAttribute + "extends" => JSON::Schema::ExtendsAttribute, } @default_formats = { 'date-time' => DateTimeFormat, @@ -30,7 +30,7 @@ def initialize 'time' => TimeFormat, 'ip-address' => IP4Format, 'ipv6' => IP6Format, - 'uri' => UriFormat + 'uri' => UriFormat, } @formats = @default_formats.clone @uri = JSON::Util::URI.parse("http://json-schema.org/draft-02/schema#") diff --git a/lib/json-schema/validators/draft3.rb b/lib/json-schema/validators/draft3.rb index 35d76d81..a8db0aa3 100644 --- a/lib/json-schema/validators/draft3.rb +++ b/lib/json-schema/validators/draft3.rb @@ -26,7 +26,7 @@ def initialize "additionalItems" => JSON::Schema::AdditionalItemsAttribute, "dependencies" => JSON::Schema::DependenciesAttribute, "extends" => JSON::Schema::ExtendsAttribute, - "$ref" => JSON::Schema::RefAttribute + "$ref" => JSON::Schema::RefAttribute, } @default_formats = { 'date-time' => DateTimeFormat, @@ -34,7 +34,7 @@ def initialize 'ip-address' => IP4Format, 'ipv6' => IP6Format, 'time' => TimeFormat, - 'uri' => UriFormat + 'uri' => UriFormat, } @formats = @default_formats.clone @uri = JSON::Util::URI.parse("http://json-schema.org/draft-03/schema#") diff --git a/lib/json-schema/validators/draft4.rb b/lib/json-schema/validators/draft4.rb index 20fa5cba..dd82e17b 100644 --- a/lib/json-schema/validators/draft4.rb +++ b/lib/json-schema/validators/draft4.rb @@ -33,13 +33,13 @@ def initialize "additionalItems" => JSON::Schema::AdditionalItemsAttribute, "dependencies" => JSON::Schema::DependenciesV4Attribute, "extends" => JSON::Schema::ExtendsAttribute, - "$ref" => JSON::Schema::RefAttribute + "$ref" => JSON::Schema::RefAttribute, } @default_formats = { 'date-time' => DateTimeV4Format, 'ipv4' => IP4Format, 'ipv6' => IP6Format, - 'uri' => UriFormat + 'uri' => UriFormat, } @formats = @default_formats.clone @uri = JSON::Util::URI.parse("http://json-schema.org/draft-04/schema#") diff --git a/lib/json-schema/validators/draft6.rb b/lib/json-schema/validators/draft6.rb index 3c370c64..1336c019 100644 --- a/lib/json-schema/validators/draft6.rb +++ b/lib/json-schema/validators/draft6.rb @@ -35,13 +35,13 @@ def initialize "extends" => JSON::Schema::ExtendsAttribute, "const" => JSON::Schema::ConstAttribute, "$ref" => JSON::Schema::RefAttribute, - "propertyNames" => JSON::Schema::PropertyNames + "propertyNames" => JSON::Schema::PropertyNames, } @default_formats = { 'date-time' => DateTimeV4Format, 'ipv4' => IP4Format, 'ipv6' => IP6Format, - 'uri' => UriFormat + 'uri' => UriFormat, } @formats = @default_formats.clone @uri = JSON::Util::URI.parse("http://json-schema.org/draft/schema#") diff --git a/test/bad_schema_ref_test.rb b/test/bad_schema_ref_test.rb index 482d402b..e8c93a04 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/custom_format_test.rb b/test/custom_format_test.rb index a9cf340f..769ec340 100644 --- a/test/custom_format_test.rb +++ b/test/custom_format_test.rb @@ -13,7 +13,7 @@ def setup "type" => "string", "format" => "custom", }, - } + }, } @schema_4 = @schema_6.clone @schema_4["$schema"] = "http://json-schema.org/draft-04/schema#" @@ -72,7 +72,7 @@ def test_multi_registration def test_format_validation @all_versions.each do |version| data = { - "a" => "23" + "a" => "23", } schema = @schemas[version] prefix = "Validation for '#{version || 'default'}'" @@ -100,7 +100,7 @@ def test_format_validation def test_override_default_format @all_versions.each do |version| data = { - "a" => "2001:db8:85a3:0:0:8a2e:370:7334" + "a" => "2001:db8:85a3:0:0:8a2e:370:7334", } schema = @schemas[version] schema["properties"]["a"]["format"] = "ipv6" diff --git a/test/draft1_test.rb b/test/draft1_test.rb index f9088754..1308ffe0 100644 --- a/test/draft1_test.rb +++ b/test/draft1_test.rb @@ -36,8 +36,8 @@ def test_optional # Set up the default datatype schema = { "properties" => { - "a" => {"type" => "string"} - } + "a" => {"type" => "string"}, + }, } data = {} @@ -47,8 +47,8 @@ def test_optional schema = { "properties" => { - "a" => {"type" => "integer", "optional" => "true"} - } + "a" => {"type" => "integer", "optional" => "true"}, + }, } data = {} @@ -59,12 +59,12 @@ def test_max_decimal # Set up the default datatype schema = { "properties" => { - "a" => {"maxDecimal" => 2} - } + "a" => {"maxDecimal" => 2}, + }, } data = { - "a" => nil + "a" => nil, } data["a"] = 3.35 @@ -89,12 +89,12 @@ def test_disallow # Set up the default datatype schema = { "properties" => { - "a" => {"disallow" => "integer"} - } + "a" => {"disallow" => "integer"}, + }, } data = { - "a" => nil + "a" => nil, } data["a"] = 'string' @@ -117,7 +117,7 @@ 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"} diff --git a/test/draft2_test.rb b/test/draft2_test.rb index 5f3873c0..6c4cc431 100644 --- a/test/draft2_test.rb +++ b/test/draft2_test.rb @@ -42,8 +42,8 @@ def test_optional # Set up the default datatype schema = { "properties" => { - "a" => {"type" => "string"} - } + "a" => {"type" => "string"}, + }, } data = {} @@ -53,8 +53,8 @@ def test_optional schema = { "properties" => { - "a" => {"type" => "integer", "optional" => "true"} - } + "a" => {"type" => "integer", "optional" => "true"}, + }, } data = {} @@ -65,12 +65,12 @@ def test_disallow # Set up the default datatype schema = { "properties" => { - "a" => {"disallow" => "integer"} - } + "a" => {"disallow" => "integer"}, + }, } data = { - "a" => nil + "a" => nil, } data["a"] = 'string' @@ -93,7 +93,7 @@ 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"} diff --git a/test/draft3_test.rb b/test/draft3_test.rb index 5f66b24c..1b61cb76 100644 --- a/test/draft3_test.rb +++ b/test/draft3_test.rb @@ -47,11 +47,11 @@ def test_types schema = { "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { - "a" => {} - } + "a" => {}, + }, } data = { - "a" => nil + "a" => nil, } # Test an array of unioned-type objects that prevent additionalProperties @@ -62,8 +62,8 @@ def test_types { 'type' => 'object', 'properties' => { "b" => { "type" => "integer" } } }, { 'type' => 'object', 'properties' => { "c" => { "type" => "string" } } } ], - 'additionalProperties' => false - } + 'additionalProperties' => false, + }, } data["a"] = [{"b" => 5}, {"c" => "foo"}] @@ -80,8 +80,8 @@ def test_required schema = { "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { - "a" => {"required" => true} - } + "a" => {"required" => true}, + }, } data = {} @@ -92,8 +92,8 @@ def test_required schema = { "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { - "a" => {"type" => "integer"} - } + "a" => {"type" => "integer"}, + }, } data = {} @@ -105,8 +105,8 @@ def test_strict_properties_required_props "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { "a" => {"type" => "string", "required" => true}, - "b" => {"type" => "string", "required" => false} - } + "b" => {"type" => "string", "required" => false}, + }, } data = {"a" => "a"} @@ -124,9 +124,9 @@ def test_strict_properties_additional_props "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { "a" => {"type" => "string"}, - "b" => {"type" => "string"} + "b" => {"type" => "string"}, }, - "additionalProperties" => {"type" => "integer"} + "additionalProperties" => {"type" => "integer"}, } data = {"a" => "a"} @@ -150,9 +150,9 @@ def test_strict_properties_pattern_props "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { "a" => {"type" => "string"}, - "b" => {"type" => "string"} + "b" => {"type" => "string"}, }, - "patternProperties" => {"\\d+ taco" => {"type" => "integer"}} + "patternProperties" => {"\\d+ taco" => {"type" => "integer"}}, } data = {"a" => "a"} @@ -182,12 +182,12 @@ def test_disallow schema = { "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { - "a" => {"disallow" => "integer"} - } + "a" => {"disallow" => "integer"}, + }, } data = { - "a" => nil + "a" => nil, } data["a"] = 'string' @@ -211,19 +211,19 @@ def test_extends schema = { "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { - "a" => { "type" => "integer"} - } + "a" => { "type" => "integer"}, + }, } schema2 = { "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { - "a" => { "maximum" => 5 } - } + "a" => { "maximum" => 5 }, + }, } data = { - "a" => 10 + "a" => 10, } assert_valid schema, data @@ -238,7 +238,7 @@ 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}] @@ -256,7 +256,7 @@ 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}}} @@ -267,7 +267,7 @@ 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"} @@ -310,7 +310,7 @@ def test_format_uri 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)) @@ -321,7 +321,7 @@ def test_format_uri def test_schema schema = { "$schema" => "http://json-schema.org/THIS-IS-NOT-A-SCHEMA", - "type" => "object" + "type" => "object", } data = {"a" => "taco"} @@ -329,7 +329,7 @@ def test_schema schema = { "$schema" => "http://json-schema.org/draft-03/schema#", - "type" => "object" + "type" => "object", } assert_valid schema, data end @@ -340,11 +340,11 @@ def test_dependency "type" => "object", "properties" => { "a" => {"type" => "integer"}, - "b" => {"type" => "integer"} + "b" => {"type" => "integer"}, }, "dependencies" => { - "a" => "b" - } + "a" => "b", + }, } data = {"a" => 1, "b" => 2} @@ -358,11 +358,11 @@ def test_dependency "properties" => { "a" => {"type" => "integer"}, "b" => {"type" => "integer"}, - "c" => {"type" => "integer"} + "c" => {"type" => "integer"}, }, "dependencies" => { - "a" => ["b","c"] - } + "a" => ["b","c"], + }, } data = {"a" => 1, "c" => 2} @@ -377,8 +377,8 @@ def test_default "type" => "object", "properties" => { "a" => {"type" => "integer", "default" => 42}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} @@ -393,8 +393,8 @@ def test_default "type" => "object", "properties" => { "a" => {"type" => "integer", "default" => 42, "required" => true}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} @@ -409,8 +409,8 @@ def test_default "type" => "object", "properties" => { "a" => {"type" => "integer", "default" => 42, "required" => true, "readonly" => true}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} @@ -425,8 +425,8 @@ def test_default "type" => "object", "properties" => { "a" => {"type" => "integer", "default" => "42"}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} diff --git a/test/draft4_test.rb b/test/draft4_test.rb index 36310996..250843ce 100644 --- a/test/draft4_test.rb +++ b/test/draft4_test.rb @@ -45,8 +45,8 @@ def test_required "$schema" => "http://json-schema.org/draft-04/schema#", "required" => ["a"], "properties" => { - "a" => {} - } + "a" => {}, + }, } data = {} @@ -57,8 +57,8 @@ def test_required schema = { "$schema" => "http://json-schema.org/draft-04/schema#", "properties" => { - "a" => {"type" => "integer"} - } + "a" => {"type" => "integer"}, + }, } data = {} @@ -90,8 +90,8 @@ def test_strict_properties "$schema" => "http://json-schema.org/draft-04/schema#", "properties" => { "a" => {"type" => "string"}, - "b" => {"type" => "string"} - } + "b" => {"type" => "string"}, + }, } data = {"a" => "a"} @@ -112,9 +112,9 @@ def test_strict_properties_additional_props "$schema" => "http://json-schema.org/draft-04/schema#", "properties" => { "a" => {"type" => "string"}, - "b" => {"type" => "string"} + "b" => {"type" => "string"}, }, - "additionalProperties" => {"type" => "integer"} + "additionalProperties" => {"type" => "integer"}, } data = {"a" => "a"} @@ -138,9 +138,9 @@ def test_strict_properties_pattern_props "$schema" => "http://json-schema.org/draft-03/schema#", "properties" => { "a" => {"type" => "string"}, - "b" => {"type" => "string"} + "b" => {"type" => "string"}, }, - "patternProperties" => {"\\d+ taco" => {"type" => "integer"}} + "patternProperties" => {"\\d+ taco" => {"type" => "integer"}}, } data = {"a" => "a"} @@ -170,7 +170,7 @@ 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}] @@ -192,23 +192,23 @@ def test_default_with_strict_and_anyof "properties" => { "foo" => { "enum" => ["view", "search"], - "default" => "view" - } - } + "default" => "view", + }, + }, }, { "type" => "object", "properties" => { "bar" => { - "type" => "string" - } - } + "type" => "string", + }, + }, } - ] + ], } data = { - "bar" => "baz" + "bar" => "baz", } assert(JSON::Validator.validate(schema, data, :insert_defaults => true, :strict => true)) @@ -222,19 +222,19 @@ def test_default_with_anyof "properties" => { "foo" => { "enum" => ["view", "search"], - "default" => "view" - } - } + "default" => "view", + }, + }, }, { "type" => "object", "properties" => { "bar" => { - "type" => "string" - } - } + "type" => "string", + }, + }, } - ] + ], } data = {} @@ -250,24 +250,24 @@ def test_default_with_strict_and_oneof "type" => "object", "properties" => { "bar" => { - "type" => "string" - } - } + "type" => "string", + }, + }, }, { "type" => "object", "properties" => { "foo" => { "enum" => ["view", "search"], - "default" => "view" - } - } + "default" => "view", + }, + }, } - ] + ], } data = { - "bar" => "baz" + "bar" => "baz", } assert(JSON::Validator.validate(schema, data, :insert_defaults => true, :strict => true)) @@ -278,7 +278,7 @@ 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}}} @@ -290,9 +290,9 @@ def test_property_named_ref "$schema" => "http://json-schema.org/draft-04/schema#", "properties" => { "$ref" => { - "type" => "integer" - } - } + "type" => "integer", + }, + }, } assert_valid schema, { "$ref" => 1 } @@ -303,7 +303,7 @@ def test_format_datetime schema = { "$schema" => "http://json-schema.org/draft-04/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"} @@ -328,7 +328,7 @@ def test_format_uri 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)) @@ -339,7 +339,7 @@ def test_format_uri def test_schema schema = { "$schema" => "http://json-schema.org/THIS-IS-NOT-A-SCHEMA", - "type" => "object" + "type" => "object", } data = {"a" => "taco"} @@ -347,7 +347,7 @@ def test_schema schema = { "$schema" => "http://json-schema.org/draft-04/schema#", - "type" => "object" + "type" => "object", } assert_valid schema, data end @@ -358,11 +358,11 @@ def test_dependency "type" => "object", "properties" => { "a" => {"type" => "integer"}, - "b" => {"type" => "integer"} + "b" => {"type" => "integer"}, }, "dependencies" => { - "a" => ["b"] - } + "a" => ["b"], + }, } data = {"a" => 1, "b" => 2} @@ -376,11 +376,11 @@ def test_dependency "properties" => { "a" => {"type" => "integer"}, "b" => {"type" => "integer"}, - "c" => {"type" => "integer"} + "c" => {"type" => "integer"}, }, "dependencies" => { - "a" => ["b","c"] - } + "a" => ["b","c"], + }, } data = {"a" => 1, "c" => 2} @@ -394,21 +394,21 @@ def test_schema_dependency "type"=> "object", "properties"=> { "name"=> { "type"=> "string" }, - "credit_card"=> { "type"=> "number" } + "credit_card"=> { "type"=> "number" }, }, "required"=> ["name"], "dependencies"=> { "credit_card"=> { "properties"=> { - "billing_address"=> { "type"=> "string" } + "billing_address"=> { "type"=> "string" }, }, - "required"=> ["billing_address"] - } - } + "required"=> ["billing_address"], + }, + }, } data = { "name" => "John Doe", - "credit_card" => 5555555555555555 + "credit_card" => 5555555555555555, } assert(!JSON::Validator.validate(schema,data), 'test schema dependency with invalid data') data['billing_address'] = "Somewhere over the rainbow" @@ -421,8 +421,8 @@ def test_default "type" => "object", "properties" => { "a" => {"type" => "integer", "default" => 42}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} @@ -438,8 +438,8 @@ def test_default "required" => ["a"], "properties" => { "a" => {"type" => "integer", "default" => 42}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} @@ -455,8 +455,8 @@ def test_default "required" => ["a"], "properties" => { "a" => {"type" => "integer", "default" => 42, "readonly" => true}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} @@ -471,8 +471,8 @@ def test_default "type" => "object", "properties" => { "a" => {"type" => "integer", "default" => "42"}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} @@ -490,8 +490,8 @@ def test_boolean_false_default "required" => ["a"], "properties" => { "a" => {"type" => "boolean", "default" => false}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } data = {:b => 2} @@ -508,12 +508,12 @@ def test_all_of "allOf" => [ { "properties" => {"a" => {"type" => "string"}}, - "required" => ["a"] + "required" => ["a"], }, { - "properties" => {"b" => {"type" => "integer"}} + "properties" => {"b" => {"type" => "integer"}}, } - ] + ], } data = {"a" => "hello", "b" => 5} @@ -535,12 +535,12 @@ def test_any_of "anyOf" => [ { "properties" => {"a" => {"type" => "string"}}, - "required" => ["a"] + "required" => ["a"], }, { - "properties" => {"b" => {"type" => "integer"}} + "properties" => {"b" => {"type" => "integer"}}, } - ] + ], } data = {"a" => "hello", "b" => 5} @@ -565,12 +565,12 @@ def test_one_of "oneOf" => [ { "properties" => {"a" => {"type" => "string"}}, - "required" => ["a"] + "required" => ["a"], }, { - "properties" => {"b" => {"type" => "integer"}} + "properties" => {"b" => {"type" => "integer"}}, } - ] + ], } data = {"a" => "hello", "b" => 5} @@ -595,8 +595,8 @@ 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} @@ -614,17 +614,17 @@ def test_not "properties" => { "a" => {"not" => {"anyOf" => [ { - "type" => ["string","boolean"] + "type" => ["string","boolean"], }, { "type" => "object", "properties" => { - "b" => {"type" => "boolean"} - } + "b" => {"type" => "boolean"}, + }, } - ]} - } - } + ]}, + }, + }, } data = {"a" => 1} @@ -648,8 +648,8 @@ 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} @@ -670,9 +670,9 @@ def test_definitions "positiveInteger" => { "type" => "integer", "minimum" => 0, - "exclusiveMinimum" => true - } - } + "exclusiveMinimum" => true, + }, + }, } data = [1,2,3] diff --git a/test/draft6_test.rb b/test/draft6_test.rb index 739efdd2..ca43d753 100644 --- a/test/draft6_test.rb +++ b/test/draft6_test.rb @@ -13,7 +13,7 @@ def test_const_attribute "properties" => { "a" => {"const" => "foo"}, "b" => {"const" => 6}, - } + }, } data = {:a => "foo", :b => 6} @@ -26,7 +26,7 @@ def test_const_attribute def test_property_names schema = { "type" => "object", - "propertyNames" => {"const" => "foo"} + "propertyNames" => {"const" => "foo"}, } data = {"foo" => "value"} @@ -37,7 +37,7 @@ def test_property_names schema = { "type" => "object", - "propertyNames" => false + "propertyNames" => false, } data = {} diff --git a/test/extended_schema_test.rb b/test/extended_schema_test.rb index ce22f609..8f9de7cf 100644 --- a/test/extended_schema_test.rb +++ b/test/extended_schema_test.rb @@ -29,12 +29,12 @@ def test_extended_schema_validation "$schema" => "http://test.com/test.json", "properties" => { "a" => { - "bitwise-and" => 1 + "bitwise-and" => 1, }, "b" => { - "type" => "string" - } - } + "type" => "string", + }, + }, } assert_valid schema, {"a" => 1, "b" => "taco"} @@ -49,11 +49,11 @@ def test_extended_schema_validation_with_fragment "odd-a" => { "properties" => { "a" => { - "bitwise-and" => 1 - } - } - } - } + "bitwise-and" => 1, + }, + }, + }, + }, } assert_valid schema, {"a" => 1}, :fragment => "#/definitions/odd-a" @@ -65,12 +65,12 @@ def test_unextended_schema schema = { "properties" => { "a" => { - "bitwise-and" => 1 + "bitwise-and" => 1, }, "b" => { - "type" => "string" - } - } + "type" => "string", + }, + }, } assert_valid schema, {"a" => 0, "b" => "taco"} diff --git a/test/fragment_resolution_test.rb b/test/fragment_resolution_test.rb index 52d6a9e6..5e529629 100644 --- a/test/fragment_resolution_test.rb +++ b/test/fragment_resolution_test.rb @@ -9,10 +9,10 @@ def test_fragment_resolution "a" => { "type" => "object", "properties" => { - "b" => {"type" => "integer" } - } - } - } + "b" => {"type" => "integer" }, + }, + }, + }, } data = {"b" => 5} @@ -34,9 +34,9 @@ def test_odd_level_fragment_resolution "type" => "object", "required" => ["a"], "properties" => { - "a" => {"type" => "integer"} - } - } + "a" => {"type" => "integer"}, + }, + }, } assert_valid schema, {"a" => 1}, :fragment => "#/foo" @@ -50,10 +50,10 @@ 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" @@ -69,9 +69,9 @@ def test_array_fragment_resolution "anyOf" => [ {"type" => "integer"}, {"type" => "string"} - ] - } - } + ], + }, + }, } refute_valid schema, "foo", :fragment => "#/properties/a/anyOf/0" @@ -88,10 +88,10 @@ 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" diff --git a/test/fragment_validation_with_ref_test.rb b/test/fragment_validation_with_ref_test.rb index 9ed3801a..9bd78873 100644 --- a/test/fragment_validation_with_ref_test.rb +++ b/test/fragment_validation_with_ref_test.rb @@ -10,20 +10,20 @@ def whole_schema "type" => "object", "properties" => { "content" => { - "type" => "string" + "type" => "string", }, "author" => { - "type" => "string" - } - } + "type" => "string", + }, + }, }, "posts" => { "type" => "array", "items" => { - "$ref" => "#/definitions/post" - } - } - } + "$ref" => "#/definitions/post", + }, + }, + }, } end @@ -39,18 +39,18 @@ def whole_schema_with_array "schema" => { "properties" => { "content" => { - "type" => "string" + "type" => "string", }, "author" => { - "type" => "string" - } + "type" => "string", + }, }, - "required" => ["content", "author"] - } + "required" => ["content", "author"], + }, } - ] - } - } + ], + }, + }, } end diff --git a/test/full_validation_test.rb b/test/full_validation_test.rb index bb2a24c4..c0cb82e3 100644 --- a/test/full_validation_test.rb +++ b/test/full_validation_test.rb @@ -8,8 +8,8 @@ def test_full_validation "required" => ["b"], "properties" => { "b" => { - } - } + }, + }, } errors = JSON::Validator.fully_validate(schema,data) @@ -23,9 +23,9 @@ def test_full_validation "b" => { }, "c" => { - "type" => "string" - } - } + "type" => "string", + }, + }, } errors = JSON::Validator.fully_validate(schema,data) @@ -39,8 +39,8 @@ def test_full_validation_with_instantiated_validator "required" => ["b"], "properties" => { "b" => { - } - } + }, + }, } validator = JSON::Validator.new(schema, { :record_errors => true }) @@ -56,9 +56,9 @@ def test_full_validation_with_instantiated_validator "b" => { }, "c" => { - "type" => "string" - } - } + "type" => "string", + }, + }, } validator = JSON::Validator.new(schema, { :record_errors => true }) @@ -73,9 +73,9 @@ def test_full_validation_with_union_types "type" => "object", "properties" => { "b" => { - "type" => ["null","integer"] - } - } + "type" => ["null","integer"], + }, + }, } errors = JSON::Validator.fully_validate(schema,data) @@ -85,9 +85,9 @@ def test_full_validation_with_union_types "type" => "object", "properties" => { "b" => { - "type" => ["integer","null"] - } - } + "type" => ["integer","null"], + }, + }, } errors = JSON::Validator.fully_validate(schema,data) @@ -107,18 +107,18 @@ 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"}, + }, } - ] - } - } + ], + }, + }, } data = {"b" => {"c" => "taco"}} @@ -144,8 +144,8 @@ def test_full_validation_with_object_errors "required" => ["b"], "properties" => { "b" => { - } - } + }, + }, } errors = JSON::Validator.fully_validate(schema,data,:errors_as_objects => true) @@ -159,9 +159,9 @@ def test_full_validation_with_object_errors "b" => { }, "c" => { - "type" => "string" - } - } + "type" => "string", + }, + }, } errors = JSON::Validator.fully_validate(schema,data,:errors_as_objects => true) @@ -187,9 +187,9 @@ def test_full_validation_with_nested_required_properties "c" => {"type"=>"integer"}, "d" => {"type"=>"integer"}, "e" => {"type"=>"integer"}, - } - } - } + }, + }, + }, } data = {"x" => {"a"=>5, "d"=>5, "e"=>"what?"}} @@ -217,10 +217,10 @@ def test_full_validation_with_nested_required_propertiesin_array "c" => {"type"=>"integer"}, "d" => {"type"=>"integer"}, "e" => {"type"=>"integer"}, - } - } - } - } + }, + }, + }, + }, } missing_b= {"a"=>5} e_is_wrong_type= {"a"=>5,"b"=>5,"e"=>"what?"} diff --git a/test/list_option_test.rb b/test/list_option_test.rb index fc6e5aa7..e3aa77be 100644 --- a/test/list_option_test.rb +++ b/test/list_option_test.rb @@ -5,7 +5,7 @@ def test_list_option_reusing_schemas schema_hash = { "$schema" => "http://json-schema.org/draft-04/schema#", "type" => "object", - "properties" => { "a" => { "type" => "integer" } } + "properties" => { "a" => { "type" => "integer" } }, } uri = Addressable::URI.parse('http://example.com/item') diff --git a/test/load_ref_schema_test.rb b/test/load_ref_schema_test.rb index fa5418ca..8bb96617 100644 --- a/test/load_ref_schema_test.rb +++ b/test/load_ref_schema_test.rb @@ -8,9 +8,9 @@ def load_other_schema 'type' => 'object', 'properties' => { "title" => { - "type" => "string" - } - } + "type" => "string", + }, + }, }, Addressable::URI.parse("http://example.com/schema#") )) diff --git a/test/min_items_test.rb b/test/min_items_test.rb index 2ac83eaf..d8cb8fe3 100644 --- a/test/min_items_test.rb +++ b/test/min_items_test.rb @@ -5,7 +5,7 @@ def test_minitems_nils schema = { "type" => "array", "minItems" => 1, - "items" => { "type" => "object" } + "items" => { "type" => "object" }, } errors = JSON::Validator.fully_validate(schema, [nil]) diff --git a/test/one_of_test.rb b/test/one_of_test.rb index b300cbb9..0eee1ef4 100644 --- a/test/one_of_test.rb +++ b/test/one_of_test.rb @@ -20,7 +20,7 @@ def test_one_of_with_string_patterns { "properties" => {"a" => {"type" => "string", "pattern" => "baz"}}, } - ] + ], } assert_valid schema, { "a" => "foo" } @@ -42,7 +42,7 @@ def test_one_of_sub_errors { "properties" => {"a" => {"type" => "number", "minimum" => 10}}, } - ] + ], } errors = JSON::Validator.fully_validate(schema, { "a" => 5 }, :errors_as_objects => true) @@ -65,7 +65,7 @@ def test_one_of_sub_errors_message { "properties" => {"a" => {"type" => "number", "minimum" => 10}}, } - ] + ], } errors = JSON::Validator.fully_validate(schema, { "a" => 5 }) diff --git a/test/ruby_schema_test.rb b/test/ruby_schema_test.rb index fba786cb..81607e58 100644 --- a/test/ruby_schema_test.rb +++ b/test/ruby_schema_test.rb @@ -7,8 +7,8 @@ def test_string_keys "required" => ["a"], "properties" => { "a" => {"type" => "integer", "default" => 42}, - "b" => {"type" => "integer"} - } + "b" => {"type" => "integer"}, + }, } assert_valid schema, { "a" => 5 } @@ -20,8 +20,8 @@ def test_symbol_keys :required => ["a"], :properties => { :a => {:type => "integer", :default => 42}, - :b => {:type => "integer"} - } + :b => {:type => "integer"}, + }, } assert_valid schema, { :a => 5 } @@ -37,21 +37,21 @@ def test_symbol_keys_in_hash_within_array { :properties => { :b => { - :type => "integer" - } - } + :type => "integer", + }, + }, } - ] - } - } + ], + }, + }, } data = { :a => [ { - :b => 1 + :b => 1, } - ] + ], } assert_valid schema, data, :validate_schema => true diff --git a/test/schema_validation_test.rb b/test/schema_validation_test.rb index 152080bc..d8476931 100644 --- a/test/schema_validation_test.rb +++ b/test/schema_validation_test.rb @@ -8,9 +8,9 @@ def valid_schema_v3 "type" => "object", "properties" => { "b" => { - "required" => true - } - } + "required" => true, + }, + }, } end @@ -20,9 +20,9 @@ def invalid_schema_v3 "type" => "object", "properties" => { "b" => { - "required" => "true" - } - } + "required" => "true", + }, + }, } end @@ -32,7 +32,7 @@ def valid_schema_v4 "type" => "object", "required" => ["b"], "properties" => { - } + }, } end @@ -42,7 +42,7 @@ def invalid_schema_v4 "type" => "object", "required" => "b", "properties" => { - } + }, } end @@ -63,40 +63,40 @@ def symbolized_schema :id => { :type => [ :integer - ] + ], }, :name => { :type => [ :string - ] + ], }, :real_name => { :type => [ :string - ] + ], }, :role => { :type => [ :string - ] + ], }, :website => { :type => [ :string, :null - ] + ], }, :created_at => { :type => [ :string - ] + ], }, :biography => { :type => [ :string, :null - ] - } + ], + }, }, :relationships => { :demographic => { @@ -109,16 +109,16 @@ def symbolized_schema :id => { :type => [ :integer - ] + ], }, :gender => { :type => [ :string - ] - } - } - } - } + ], + }, + }, + }, + }, } end @@ -177,7 +177,7 @@ def test_validate_schema_with_symbol_keys "website" => nil, "role" => "user", "biography" => nil, - "demographic" => nil + "demographic" => nil, } assert(JSON::Validator.validate!(symbolized_schema, data, :validate_schema => true)) end diff --git a/test/stringify_test.rb b/test/stringify_test.rb index 09bbd579..8dc029c1 100644 --- a/test/stringify_test.rb +++ b/test/stringify_test.rb @@ -4,7 +4,7 @@ class StringifyTest < Minitest::Test def test_stringify_on_hash hash = { :a => 'foo', - 'b' => :bar + 'b' => :bar, } assert_equal({'a' => 'foo', 'b' => 'bar'}, JSON::Schema.stringify(hash), 'symbol keys should be converted to strings') end @@ -20,7 +20,7 @@ def test_stringify_on_array def test_stringify_on_hash_of_arrays hash = { :a => [:foo], - 'b' => :bar + 'b' => :bar, } assert_equal({'a' => ['foo'], 'b' => 'bar'}, JSON::Schema.stringify(hash), 'symbols in a nested array should be converted to strings') end @@ -29,7 +29,7 @@ def test_stringify_on_array_of_hashes array = [ :a, { - :b => :bar + :b => :bar, } ] assert_equal(['a', {'b' => 'bar'}], JSON::Schema.stringify(array), 'symbols keys in a nested hash should be converted to strings') @@ -39,9 +39,9 @@ def test_stringify_on_hash_of_hashes hash = { :a => { :b => { - :foo => :bar - } - } + :foo => :bar, + }, + }, } assert_equal({'a' => {'b' => {'foo' => 'bar'} } }, JSON::Schema.stringify(hash), 'symbols in a nested hash of hashes should be converted to strings') end diff --git a/test/support/array_validation.rb b/test/support/array_validation.rb index a9edb6c0..314b5fa9 100644 --- a/test/support/array_validation.rb +++ b/test/support/array_validation.rb @@ -19,7 +19,7 @@ def test_items_multiple_schemas 'items' => [ { 'type' => 'string' }, { 'type' => 'integer' } - ] + ], } assert_valid schema, ['b', 1] @@ -60,7 +60,7 @@ def test_additional_items_false { 'type' => 'integer' }, { 'type' => 'string' } ], - 'additionalItems' => false + 'additionalItems' => false, } assert_valid schema, [1, 'string'] @@ -76,7 +76,7 @@ def test_additional_items_schema { 'type' => 'integer' }, { 'type' => 'string' } ], - 'additionalItems' => { 'type' => 'integer' } + 'additionalItems' => { 'type' => 'integer' }, } assert_valid schema, [1, 'string'] diff --git a/test/support/enum_validation.rb b/test/support/enum_validation.rb index 376dcf5f..bf93112a 100644 --- a/test/support/enum_validation.rb +++ b/test/support/enum_validation.rb @@ -3,8 +3,8 @@ 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}, + }, } data = {} @@ -16,8 +16,8 @@ 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"}]}, + }, } data = {} @@ -29,8 +29,8 @@ 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"}]}, + }, } data = { "a" => 1 } @@ -54,9 +54,9 @@ def test_enum_number_integer_includes_float "properties" => { "a" => { "type" => "number", - "enum" => [0, 1, 2] - } - } + "enum" => [0, 1, 2], + }, + }, } data = { "a" => 0 } @@ -77,9 +77,9 @@ def test_enum_number_float_includes_integer "properties" => { "a" => { "type" => "number", - "enum" => [0.0, 1.0, 2.0] - } - } + "enum" => [0.0, 1.0, 2.0], + }, + }, } data = { "a" => 0.0 } @@ -100,9 +100,9 @@ def test_enum_integer_excludes_float "properties" => { "a" => { "type" => "integer", - "enum" => [0, 1, 2] - } - } + "enum" => [0, 1, 2], + }, + }, } data = { "a" => 0 } @@ -121,8 +121,8 @@ 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 } assert_valid(schema, data, :validate_schema => true) diff --git a/test/support/number_validation.rb b/test/support/number_validation.rb index 1ecdf012..3605b7db 100644 --- a/test/support/number_validation.rb +++ b/test/support/number_validation.rb @@ -3,8 +3,8 @@ module MinMaxTests def test_minimum schema = { 'properties' => { - 'a' => { 'minimum' => 5 } - } + 'a' => { 'minimum' => 5 }, + }, } assert_valid schema, {'a' => 5} @@ -20,8 +20,8 @@ def test_minimum def test_exclusive_minimum schema = { 'properties' => { - 'a' => { 'minimum' => 5 }.merge(exclusive_minimum) - } + 'a' => { 'minimum' => 5 }.merge(exclusive_minimum), + }, } assert_valid schema, {'a' => 6} @@ -32,8 +32,8 @@ def test_exclusive_minimum def test_maximum schema = { 'properties' => { - 'a' => { 'maximum' => 5 } - } + 'a' => { 'maximum' => 5 }, + }, } assert_valid schema, {'a' => 4} @@ -46,8 +46,8 @@ def test_maximum def test_exclusive_maximum schema = { 'properties' => { - 'a' => { 'maximum' => 5 }.merge(exclusive_maximum) - } + 'a' => { 'maximum' => 5 }.merge(exclusive_maximum), + }, } assert_valid schema, {'a' => 4} @@ -66,8 +66,8 @@ def multiple_of def test_multiple_of schema = { 'properties' => { - 'a' => { multiple_of => 1.1 } - } + 'a' => { multiple_of => 1.1 }, + }, } assert_valid schema, {'a' => 0} diff --git a/test/support/object_validation.rb b/test/support/object_validation.rb index c5e15033..62d16860 100644 --- a/test/support/object_validation.rb +++ b/test/support/object_validation.rb @@ -3,9 +3,9 @@ module AdditionalPropertiesTests def test_additional_properties_false schema = { 'properties' => { - 'a' => { 'type' => 'integer' } + 'a' => { 'type' => 'integer' }, }, - 'additionalProperties' => false + 'additionalProperties' => false, } assert_valid schema, {'a' => 1} @@ -15,9 +15,9 @@ def test_additional_properties_false def test_additional_properties_schema schema = { 'properties' => { - 'a' => { 'type' => 'integer' } + 'a' => { 'type' => 'integer' }, }, - 'additionalProperties' => { 'type' => 'string' } + 'additionalProperties' => { 'type' => 'string' }, } assert_valid schema, {'a' => 1} @@ -30,8 +30,8 @@ module PatternPropertiesTests def test_pattern_properties schema = { 'patternProperties' => { - "\\d+ taco" => { 'type' => 'integer' } - } + "\\d+ taco" => { 'type' => 'integer' }, + }, } assert_valid schema, {'1 taco' => 1, '20 taco' => 20} @@ -42,9 +42,9 @@ def test_pattern_properties def test_pattern_properties_additional_properties_false schema = { 'patternProperties' => { - "\\d+ taco" => { 'type' => 'integer' } + "\\d+ taco" => { 'type' => 'integer' }, }, - 'additionalProperties' => false + 'additionalProperties' => false, } assert_valid schema, {'1 taco' => 1} @@ -55,9 +55,9 @@ def test_pattern_properties_additional_properties_false def test_pattern_properties_additional_properties_schema schema = { 'patternProperties' => { - "\\d+ taco" => { 'type' => 'integer' } + "\\d+ taco" => { 'type' => 'integer' }, }, - 'additionalProperties' => { 'type' => 'string' } + 'additionalProperties' => { 'type' => 'string' }, } assert_valid schema, {'1 taco' => 1} diff --git a/test/support/strict_validation.rb b/test/support/strict_validation.rb index 35ee6440..3a237142 100644 --- a/test/support/strict_validation.rb +++ b/test/support/strict_validation.rb @@ -4,8 +4,8 @@ def test_strict_properties "$schema" => "http://json-schema.org/draft-04/schema#", "properties" => { "a" => {"type" => "string"}, - "b" => {"type" => "string"} - } + "b" => {"type" => "string"}, + }, } data = {"a" => "a"} @@ -33,9 +33,9 @@ def test_strict_properties_additional_props "$schema" => "http://json-schema.org/draft-04/schema#", "properties" => { "a" => {"type" => "string"}, - "b" => {"type" => "string"} + "b" => {"type" => "string"}, }, - "additionalProperties" => {"type" => "integer"} + "additionalProperties" => {"type" => "integer"}, } data = {"a" => "a"} @@ -58,9 +58,9 @@ def test_strict_properties_pattern_props schema = { "properties" => { "a" => {"type" => "string"}, - "b" => {"type" => "string"} + "b" => {"type" => "string"}, }, - "patternProperties" => {"\\d+ taco" => {"type" => "integer"}} + "patternProperties" => {"\\d+ taco" => {"type" => "integer"}}, } data = {"a" => "a"} diff --git a/test/support/string_validation.rb b/test/support/string_validation.rb index b8d911cb..436a7076 100644 --- a/test/support/string_validation.rb +++ b/test/support/string_validation.rb @@ -3,8 +3,8 @@ module ValueTests def test_minlength schema = { 'properties' => { - 'a' => { 'minLength' => 1 } - } + 'a' => { 'minLength' => 1 }, + }, } assert_valid schema, {'a' => 't'} @@ -17,8 +17,8 @@ def test_minlength def test_maxlength schema = { 'properties' => { - 'a' => { 'maxLength' => 2 } - } + 'a' => { 'maxLength' => 2 }, + }, } assert_valid schema, {'a' => 'tt'} @@ -32,8 +32,8 @@ def test_maxlength def test_pattern schema = { 'properties' => { - 'a' => { 'pattern' => "\\d+ taco" } - } + 'a' => { 'pattern' => "\\d+ taco" }, + }, } assert_valid schema, {'a' => '156 taco bell'} @@ -53,8 +53,8 @@ def ipv4_format def test_format_unknown schema = { 'properties' => { - 'a' => { 'format' => 'unknown' } - } + 'a' => { 'format' => 'unknown' }, + }, } assert_valid schema, {'a' => 'absolutely anything!'} @@ -66,9 +66,9 @@ def test_format_union 'properties' => { 'a' => { 'type' => ['string', 'null'], - 'format' => 'date-time' - } - } + 'format' => 'date-time', + }, + }, } assert_valid schema, {'a' => nil} @@ -78,8 +78,8 @@ def test_format_union def test_format_ipv4 schema = { 'properties' => { - 'a' => { 'format' => ipv4_format } - } + 'a' => { 'format' => ipv4_format }, + }, } assert_valid schema, {"a" => "1.1.1.1"} @@ -95,8 +95,8 @@ def test_format_ipv4 def test_format_ipv6 schema = { 'properties' => { - 'a' => { 'format' => 'ipv6' } - } + 'a' => { 'format' => 'ipv6' }, + }, } assert_valid schema, {"a" => "1111:2222:8888:9999:aaaa:cccc:eeee:ffff"} @@ -119,8 +119,8 @@ module DateAndTimeFormatTests def test_format_time schema = { 'properties' => { - 'a' => { 'format' => 'time' } - } + 'a' => { 'format' => 'time' }, + }, } assert_valid schema, {"a" => "12:00:00"} @@ -138,8 +138,8 @@ def test_format_time def test_format_date schema = { 'properties' => { - 'a' => { 'format' => 'date' } - } + 'a' => { 'format' => 'date' }, + }, } assert_valid schema, {"a" => "2010-01-01"} diff --git a/test/support/type_validation.rb b/test/support/type_validation.rb index 20965b7d..71e795c1 100644 --- a/test/support/type_validation.rb +++ b/test/support/type_validation.rb @@ -9,7 +9,7 @@ module SimpleTypeTests 'boolean' => true, 'object' => {}, 'array' => [], - 'null' => nil + 'null' => nil, } TYPES.each do |name, value| @@ -17,7 +17,7 @@ module SimpleTypeTests define_method(:"test_#{name}_type_property") do schema = { - 'properties' => { 'a' => { 'type' => name } } + 'properties' => { 'a' => { 'type' => name } }, } assert_valid schema, {'a' => value} @@ -66,9 +66,9 @@ def test_union_type_with_schemas 'type' => [ {'type' => 'string'}, {'type' => 'object', 'properties' => { 'b' => { 'type' => 'integer' }}} - ] - } - } + ], + }, + }, } assert_valid schema, {'a' => 'test'} diff --git a/test/uri_parsing_test.rb b/test/uri_parsing_test.rb index e82f163b..4800b03b 100644 --- a/test/uri_parsing_test.rb +++ b/test/uri_parsing_test.rb @@ -12,9 +12,9 @@ def test_asian_characters "properties" => { "a" => { "id" => "a", - "type" => "integer" - } - } + "type" => "integer", + }, + }, } data = { "a" => 5 } assert_valid schema, data @@ -31,10 +31,10 @@ def test_schema_ref_with_empty_fragment "items"=> { "anyOf"=> [ { "$ref" => "test/schemas/ref john with spaces schema.json#" }, - ] - } - } - } + ], + }, + }, + }, } data = {"names" => [{"first" => "john"}]} assert_valid schema, data @@ -51,10 +51,10 @@ def test_schema_ref_from_file_with_spaces "items"=> { "anyOf"=> [ { "$ref" => "test/schemas/ref john with spaces schema.json" } - ] - } - } - } + ], + }, + }, + }, } data = {"names" => [{"first" => "john"}]} assert_valid schema, data diff --git a/test/validator_schema_reader_test.rb b/test/validator_schema_reader_test.rb index 4fa17231..92fb1553 100644 --- a/test/validator_schema_reader_test.rb +++ b/test/validator_schema_reader_test.rb @@ -8,7 +8,7 @@ def read(location) schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'string', - 'minLength' => 2 + 'minLength' => 2, } JSON::Schema.new(schema, Addressable::URI.parse(location.to_s)) From dca00feecf72dd31061e749fde4d1e2bcbd6ee21 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 10:03:38 +0100 Subject: [PATCH 3/5] rubocop: Fix Style/TrailingCommaInArrayLiteral --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 10 ---------- test/draft3_test.rb | 2 +- test/draft4_test.rb | 14 +++++++------- test/fragment_resolution_test.rb | 2 +- test/fragment_validation_with_ref_test.rb | 2 +- test/full_validation_test.rb | 2 +- test/one_of_test.rb | 6 +++--- test/ruby_schema_test.rb | 4 ++-- test/schema_validation_test.rb | 22 +++++++++++----------- test/stringify_test.rb | 4 ++-- test/support/array_validation.rb | 6 +++--- test/support/type_validation.rb | 2 +- test/uri_parsing_test.rb | 2 +- 14 files changed, 38 insertions(+), 44 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f146f6e8..9a99f699 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,3 +12,7 @@ AllCops: Style/TrailingCommaInHashLiteral: Enabled: True EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInArrayLiteral: + Enabled: True + EnforcedStyleForMultiline: consistent_comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7e5decf7..5072e007 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -853,16 +853,6 @@ Style/SymbolProc: - 'lib/json-schema/errors/validation_error.rb' - 'lib/json-schema/validator.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArrayLiteral: - Exclude: - - 'lib/json-schema/util/uuid.rb' - - 'test/support/test_helper.rb' - - 'test/uri_parsing_test.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AllowNamedUnderscoreVariables. diff --git a/test/draft3_test.rb b/test/draft3_test.rb index 1b61cb76..f5b0cca6 100644 --- a/test/draft3_test.rb +++ b/test/draft3_test.rb @@ -60,7 +60,7 @@ def test_types 'items' => { 'type' => [ { 'type' => 'object', 'properties' => { "b" => { "type" => "integer" } } }, - { 'type' => 'object', 'properties' => { "c" => { "type" => "string" } } } + { 'type' => 'object', 'properties' => { "c" => { "type" => "string" } } }, ], 'additionalProperties' => false, }, diff --git a/test/draft4_test.rb b/test/draft4_test.rb index 250843ce..5fd03826 100644 --- a/test/draft4_test.rb +++ b/test/draft4_test.rb @@ -203,7 +203,7 @@ def test_default_with_strict_and_anyof "type" => "string", }, }, - } + }, ], } @@ -233,7 +233,7 @@ def test_default_with_anyof "type" => "string", }, }, - } + }, ], } @@ -262,7 +262,7 @@ def test_default_with_strict_and_oneof "default" => "view", }, }, - } + }, ], } @@ -512,7 +512,7 @@ def test_all_of }, { "properties" => {"b" => {"type" => "integer"}}, - } + }, ], } @@ -539,7 +539,7 @@ def test_any_of }, { "properties" => {"b" => {"type" => "integer"}}, - } + }, ], } @@ -569,7 +569,7 @@ def test_one_of }, { "properties" => {"b" => {"type" => "integer"}}, - } + }, ], } @@ -621,7 +621,7 @@ def test_not "properties" => { "b" => {"type" => "boolean"}, }, - } + }, ]}, }, }, diff --git a/test/fragment_resolution_test.rb b/test/fragment_resolution_test.rb index 5e529629..2038fb00 100644 --- a/test/fragment_resolution_test.rb +++ b/test/fragment_resolution_test.rb @@ -68,7 +68,7 @@ def test_array_fragment_resolution "a" => { "anyOf" => [ {"type" => "integer"}, - {"type" => "string"} + {"type" => "string"}, ], }, }, diff --git a/test/fragment_validation_with_ref_test.rb b/test/fragment_validation_with_ref_test.rb index 9bd78873..c3f36896 100644 --- a/test/fragment_validation_with_ref_test.rb +++ b/test/fragment_validation_with_ref_test.rb @@ -47,7 +47,7 @@ def whole_schema_with_array }, "required" => ["content", "author"], }, - } + }, ], }, }, diff --git a/test/full_validation_test.rb b/test/full_validation_test.rb index c0cb82e3..292bbd6f 100644 --- a/test/full_validation_test.rb +++ b/test/full_validation_test.rb @@ -115,7 +115,7 @@ def test_full_validation_with_union_types "properties" => { "d" => {"type" => "integer"}, }, - } + }, ], }, }, diff --git a/test/one_of_test.rb b/test/one_of_test.rb index 0eee1ef4..4ddb8f64 100644 --- a/test/one_of_test.rb +++ b/test/one_of_test.rb @@ -19,7 +19,7 @@ def test_one_of_with_string_patterns }, { "properties" => {"a" => {"type" => "string", "pattern" => "baz"}}, - } + }, ], } @@ -41,7 +41,7 @@ def test_one_of_sub_errors }, { "properties" => {"a" => {"type" => "number", "minimum" => 10}}, - } + }, ], } @@ -64,7 +64,7 @@ def test_one_of_sub_errors_message }, { "properties" => {"a" => {"type" => "number", "minimum" => 10}}, - } + }, ], } diff --git a/test/ruby_schema_test.rb b/test/ruby_schema_test.rb index 81607e58..a4992200 100644 --- a/test/ruby_schema_test.rb +++ b/test/ruby_schema_test.rb @@ -40,7 +40,7 @@ def test_symbol_keys_in_hash_within_array :type => "integer", }, }, - } + }, ], }, }, @@ -50,7 +50,7 @@ def test_symbol_keys_in_hash_within_array :a => [ { :b => 1, - } + }, ], } diff --git a/test/schema_validation_test.rb b/test/schema_validation_test.rb index d8476931..dabeb446 100644 --- a/test/schema_validation_test.rb +++ b/test/schema_validation_test.rb @@ -57,44 +57,44 @@ def symbolized_schema :website, :biography, :created_at, - :demographic + :demographic, ], :properties => { :id => { :type => [ - :integer + :integer, ], }, :name => { :type => [ - :string + :string, ], }, :real_name => { :type => [ - :string + :string, ], }, :role => { :type => [ - :string + :string, ], }, :website => { :type => [ :string, - :null + :null, ], }, :created_at => { :type => [ - :string + :string, ], }, :biography => { :type => [ :string, - :null + :null, ], }, }, @@ -103,17 +103,17 @@ def symbolized_schema :type => :object, :required => [ :id, - :gender + :gender, ], :properties => { :id => { :type => [ - :integer + :integer, ], }, :gender => { :type => [ - :string + :string, ], }, }, diff --git a/test/stringify_test.rb b/test/stringify_test.rb index 8dc029c1..4d0b0794 100644 --- a/test/stringify_test.rb +++ b/test/stringify_test.rb @@ -12,7 +12,7 @@ def test_stringify_on_hash def test_stringify_on_array array = [ :a, - 'b' + 'b', ] assert_equal(['a', 'b'], JSON::Schema.stringify(array), 'symbols in an array should be converted to strings') end @@ -30,7 +30,7 @@ def test_stringify_on_array_of_hashes :a, { :b => :bar, - } + }, ] assert_equal(['a', {'b' => 'bar'}], JSON::Schema.stringify(array), 'symbols keys in a nested hash should be converted to strings') end diff --git a/test/support/array_validation.rb b/test/support/array_validation.rb index 314b5fa9..edc54064 100644 --- a/test/support/array_validation.rb +++ b/test/support/array_validation.rb @@ -18,7 +18,7 @@ def test_items_multiple_schemas schema = { 'items' => [ { 'type' => 'string' }, - { 'type' => 'integer' } + { 'type' => 'integer' }, ], } @@ -58,7 +58,7 @@ def test_additional_items_false schema = { 'items' => [ { 'type' => 'integer' }, - { 'type' => 'string' } + { 'type' => 'string' }, ], 'additionalItems' => false, } @@ -74,7 +74,7 @@ def test_additional_items_schema schema = { 'items' => [ { 'type' => 'integer' }, - { 'type' => 'string' } + { 'type' => 'string' }, ], 'additionalItems' => { 'type' => 'integer' }, } diff --git a/test/support/type_validation.rb b/test/support/type_validation.rb index 71e795c1..a0655172 100644 --- a/test/support/type_validation.rb +++ b/test/support/type_validation.rb @@ -65,7 +65,7 @@ def test_union_type_with_schemas 'a' => { 'type' => [ {'type' => 'string'}, - {'type' => 'object', 'properties' => { 'b' => { 'type' => 'integer' }}} + {'type' => 'object', 'properties' => { 'b' => { 'type' => 'integer' }}}, ], }, }, diff --git a/test/uri_parsing_test.rb b/test/uri_parsing_test.rb index 4800b03b..f6d3d8f3 100644 --- a/test/uri_parsing_test.rb +++ b/test/uri_parsing_test.rb @@ -50,7 +50,7 @@ def test_schema_ref_from_file_with_spaces "type"=> "array", "items"=> { "anyOf"=> [ - { "$ref" => "test/schemas/ref john with spaces schema.json" } + { "$ref" => "test/schemas/ref john with spaces schema.json" }, ], }, }, From 2eeb50ed35dd873d2580d682a6fd037f431dfd39 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 10:04:55 +0100 Subject: [PATCH 4/5] rubocop: Fix Style/TrailingCommaInArguments --- .rubocop.yml | 4 ++++ lib/json-schema/attributes/type_v4.rb | 2 +- test/common_test_suite_test.rb | 2 +- test/fragment_validation_with_ref_test.rb | 2 +- test/load_ref_schema_test.rb | 2 +- test/schema_reader_test.rb | 4 ++-- test/uri_util_test.rb | 14 +++++++------- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9a99f699..82770e34 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,3 +16,7 @@ Style/TrailingCommaInHashLiteral: Style/TrailingCommaInArrayLiteral: Enabled: True EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInArguments: + Enabled: True + EnforcedStyleForMultiline: consistent_comma diff --git a/lib/json-schema/attributes/type_v4.rb b/lib/json-schema/attributes/type_v4.rb index d5f132c4..f5d5a3a7 100644 --- a/lib/json-schema/attributes/type_v4.rb +++ b/lib/json-schema/attributes/type_v4.rb @@ -19,7 +19,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options build_fragment(fragments), type_of_data(data), union ? 'one or more of the following types' : 'the following type', - types + types, ) validation_error(processor, message, fragments, current_schema, self, options[:record_errors]) diff --git a/test/common_test_suite_test.rb b/test/common_test_suite_test.rb index b081fb57..af483fb0 100644 --- a/test/common_test_suite_test.rb +++ b/test/common_test_suite_test.rb @@ -45,7 +45,7 @@ def self.skip?(current_test, file_path) t["data"], :parse_data => false, :validate_schema => true, - :version => version + :version => version, ) assert_equal t["valid"], errors.empty?, "Common test suite case failed: #{err_id}" end diff --git a/test/fragment_validation_with_ref_test.rb b/test/fragment_validation_with_ref_test.rb index c3f36896..2f4ded07 100644 --- a/test/fragment_validation_with_ref_test.rb +++ b/test/fragment_validation_with_ref_test.rb @@ -62,6 +62,6 @@ def test_validation_of_fragment def test_validation_of_fragment_with_array data = {"content" => "ohai", "author" => "Bob"} assert_valid(whole_schema_with_array, data, - :fragment => "#/definitions/omg/links/0/schema") + :fragment => "#/definitions/omg/links/0/schema",) end end diff --git a/test/load_ref_schema_test.rb b/test/load_ref_schema_test.rb index 8bb96617..423928bf 100644 --- a/test/load_ref_schema_test.rb +++ b/test/load_ref_schema_test.rb @@ -12,7 +12,7 @@ def load_other_schema }, }, }, - Addressable::URI.parse("http://example.com/schema#") + Addressable::URI.parse("http://example.com/schema#"), )) end diff --git a/test/schema_reader_test.rb b/test/schema_reader_test.rb index d1b30f15..b2c9be7d 100644 --- a/test/schema_reader_test.rb +++ b/test/schema_reader_test.rb @@ -37,7 +37,7 @@ def test_refuse_all_files def test_accept_uri_proc reader = JSON::Schema::Reader.new( - :accept_uri => proc { |uri| uri.host == 'json-schema.org' } + :accept_uri => proc { |uri| uri.host == 'json-schema.org' }, ) assert reader.accept_uri?(Addressable::URI.parse('http://json-schema.org/address')) @@ -48,7 +48,7 @@ def test_accept_file_proc test_root = Pathname.new(__FILE__).expand_path.dirname reader = JSON::Schema::Reader.new( - :accept_file => proc { |path| path.to_s.start_with?(test_root.to_s) } + :accept_file => proc { |path| path.to_s.start_with?(test_root.to_s) }, ) assert reader.accept_file?(test_root.join('anything.json')) diff --git a/test/uri_util_test.rb b/test/uri_util_test.rb index 50ebc13e..e0bb6467 100644 --- a/test/uri_util_test.rb +++ b/test/uri_util_test.rb @@ -15,7 +15,7 @@ def test_normalized_uri str = "https://www.google.com/search" uri = Addressable::URI.new(:scheme => 'https', :host => 'www.google.com', - :path => 'search') + :path => 'search',) assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end @@ -24,7 +24,7 @@ def test_normalized_uri_with_empty_fragment uri = Addressable::URI.new(:scheme => 'https', :host => 'www.google.com', :path => 'search', - :fragment => nil) + :fragment => nil,) assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end @@ -33,7 +33,7 @@ def test_normalized_uri_with_fragment uri = Addressable::URI.new(:scheme => 'https', :host => 'www.google.com', :path => 'search', - :fragment => 'foo') + :fragment => 'foo',) assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end @@ -41,7 +41,7 @@ def test_normalized_uri_for_absolute_path str = "/foo/bar.json" uri = Addressable::URI.new(:scheme => 'file', :host => '', - :path => '/foo/bar.json') + :path => '/foo/bar.json',) assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end @@ -49,7 +49,7 @@ def test_normalized_uri_for_relative_path str = "foo/bar.json" uri = Addressable::URI.new(:scheme => 'file', :host => '', - :path => '/home/foo/bar.json') + :path => '/home/foo/bar.json',) assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end @@ -57,7 +57,7 @@ def test_normalized_uri_for_file_path_with_host str = "file://localhost/foo/bar.json" uri = Addressable::URI.new(:scheme => 'file', :host => 'localhost', - :path => '/foo/bar.json') + :path => '/foo/bar.json',) assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end @@ -65,7 +65,7 @@ def test_uri_parse str = "https://www.google.com/search" uri = Addressable::URI.new(:scheme => 'https', :host => 'www.google.com', - :path => 'search') + :path => 'search',) assert_equal uri, JSON::Util::URI.parse(str) end From 42b9a8892cfbcb1e01048c60e7ebc5d8e1c1e4ea Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 17 Feb 2023 10:05:46 +0100 Subject: [PATCH 5/5] rubocop: Fix Layout/SpaceAfterComma --- .rubocop_todo.yml | 5 -- json-schema.gemspec | 2 +- lib/json-schema/attribute.rb | 2 +- lib/json-schema/attributes/allof.rb | 4 +- lib/json-schema/attributes/anyof.rb | 4 +- lib/json-schema/attributes/extends.rb | 12 ++--- lib/json-schema/attributes/not.rb | 4 +- lib/json-schema/attributes/oneof.rb | 4 +- lib/json-schema/attributes/ref.rb | 8 +-- lib/json-schema/attributes/type.rb | 4 +- lib/json-schema/schema.rb | 2 +- lib/json-schema/schema/validator.rb | 2 +- lib/json-schema/util/uri.rb | 4 +- lib/json-schema/validator.rb | 8 +-- test/bad_schema_ref_test.rb | 8 +-- test/draft1_test.rb | 2 +- test/draft2_test.rb | 2 +- test/draft3_test.rb | 62 +++++++++++----------- test/draft4_test.rb | 76 +++++++++++++-------------- test/files_test.rb | 8 +-- test/fragment_resolution_test.rb | 4 +- test/full_validation_test.rb | 30 +++++------ test/one_of_test.rb | 2 +- test/schema_validation_test.rb | 16 +++--- test/support/enum_validation.rb | 10 ++-- test/support/strict_validation.rb | 34 ++++++------ 26 files changed, 157 insertions(+), 162 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5072e007..f6c3c5d4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -83,11 +83,6 @@ Layout/MultilineOperationIndentation: Exclude: - 'lib/json-schema/attributes/properties.rb' -# Offense count: 276 -# Cop supports --auto-correct. -Layout/SpaceAfterComma: - Enabled: false - # Offense count: 18 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/json-schema.gemspec b/json-schema.gemspec index e4f97184..c649b59d 100644 --- a/json-schema.gemspec +++ b/json-schema.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.summary = "Ruby JSON Schema Validator" s.files = Dir[ "lib/**/*", "resources/*.json" ] s.require_path = "lib" - s.extra_rdoc_files = ["README.md","LICENSE.md"] + s.extra_rdoc_files = ["README.md", "LICENSE.md"] s.required_ruby_version = ">= 2.5" s.license = "MIT" s.required_rubygems_version = ">= 2.5" diff --git a/lib/json-schema/attribute.rb b/lib/json-schema/attribute.rb index 83450673..f4eb6b39 100644 --- a/lib/json-schema/attribute.rb +++ b/lib/json-schema/attribute.rb @@ -41,7 +41,7 @@ def self.data_valid_for_type?(data, type) # Lookup Schema type of given class instance def self.type_of_data(data) - type, _ = TYPE_CLASS_MAPPINGS.map { |k,v| [k,v] }.sort_by { |(_, v)| + type, _ = TYPE_CLASS_MAPPINGS.map { |k, v| [k, v] }.sort_by { |(_, v)| -Array(v).map { |klass| klass.ancestors.size }.max }.find { |(_, v)| Array(v).any? { |klass| data.kind_of?(klass) } diff --git a/lib/json-schema/attributes/allof.rb b/lib/json-schema/attributes/allof.rb index dd35d4a1..d5a64d77 100644 --- a/lib/json-schema/attributes/allof.rb +++ b/lib/json-schema/attributes/allof.rb @@ -9,14 +9,14 @@ def self.validate(current_schema, data, fragments, processor, validator, options valid = true current_schema.schema['allOf'].each_with_index do |element, schema_index| - schema = JSON::Schema.new(element,current_schema.uri,validator) + schema = JSON::Schema.new(element, current_schema.uri, validator) # We're going to add a little cruft here to try and maintain any validation errors that occur in the allOf # We'll handle this by keeping an error count before and after validation, extracting those errors and pushing them onto an error array pre_validation_error_count = validation_errors(processor).count begin - schema.validate(data,fragments,processor,options) + schema.validate(data, fragments, processor, options) rescue ValidationError valid = false end diff --git a/lib/json-schema/attributes/anyof.rb b/lib/json-schema/attributes/anyof.rb index 26b29558..f9dece68 100644 --- a/lib/json-schema/attributes/anyof.rb +++ b/lib/json-schema/attributes/anyof.rb @@ -11,14 +11,14 @@ def self.validate(current_schema, data, fragments, processor, validator, options original_data = data.is_a?(Hash) ? data.clone : data current_schema.schema['anyOf'].each_with_index do |element, schema_index| - schema = JSON::Schema.new(element,current_schema.uri,validator) + schema = JSON::Schema.new(element, current_schema.uri, validator) # We're going to add a little cruft here to try and maintain any validation errors that occur in the anyOf # We'll handle this by keeping an error count before and after validation, extracting those errors and pushing them onto a union error pre_validation_error_count = validation_errors(processor).count begin - schema.validate(data,fragments,processor,options) + schema.validate(data, fragments, processor, options) valid = true rescue ValidationError # We don't care that these schemas don't validate - we only care that one validated diff --git a/lib/json-schema/attributes/extends.rb b/lib/json-schema/attributes/extends.rb index 992b18d4..e695d884 100644 --- a/lib/json-schema/attributes/extends.rb +++ b/lib/json-schema/attributes/extends.rb @@ -8,7 +8,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options schemas = current_schema.schema['extends'] schemas = [schemas] if !schemas.is_a?(Array) schemas.each do |s| - uri,schema = get_extended_uri_and_schema(s, current_schema, validator) + uri, schema = get_extended_uri_and_schema(s, current_schema, validator) if schema schema.validate(data, fragments, processor, options) elsif uri @@ -22,15 +22,15 @@ def self.validate(current_schema, data, fragments, processor, validator, options end def self.get_extended_uri_and_schema(s, current_schema, validator) - uri,schema = nil,nil + uri, schema = nil, nil if s.is_a?(Hash) uri = current_schema.uri if s['$ref'] - ref_uri,ref_schema = JSON::Schema::RefAttribute.get_referenced_uri_and_schema(s, current_schema, validator) + ref_uri, ref_schema = JSON::Schema::RefAttribute.get_referenced_uri_and_schema(s, current_schema, validator) if ref_schema if s.size == 1 # Check if anything else apart from $ref - uri,schema = ref_uri,ref_schema + uri, schema = ref_uri, ref_schema else s = s.dup s.delete '$ref' @@ -38,10 +38,10 @@ def self.get_extended_uri_and_schema(s, current_schema, validator) end end end - schema ||= JSON::Schema.new(s,uri,validator) + schema ||= JSON::Schema.new(s, uri, validator) end - [uri,schema] + [uri, schema] end end end diff --git a/lib/json-schema/attributes/not.rb b/lib/json-schema/attributes/not.rb index 43938800..d325f167 100644 --- a/lib/json-schema/attributes/not.rb +++ b/lib/json-schema/attributes/not.rb @@ -4,12 +4,12 @@ module JSON class Schema class NotAttribute < Attribute def self.validate(current_schema, data, fragments, processor, validator, options = {}) - schema = JSON::Schema.new(current_schema.schema['not'],current_schema.uri,validator) + schema = JSON::Schema.new(current_schema.schema['not'], current_schema.uri, validator) failed = true errors_copy = processor.validation_errors.clone begin - schema.validate(data,fragments,processor,options) + schema.validate(data, fragments, processor, options) # If we're recording errors, we don't throw an exception. Instead, check the errors array length if options[:record_errors] && errors_copy.length != processor.validation_errors.length processor.validation_errors.replace(errors_copy) diff --git a/lib/json-schema/attributes/oneof.rb b/lib/json-schema/attributes/oneof.rb index fb78522e..c163fa09 100644 --- a/lib/json-schema/attributes/oneof.rb +++ b/lib/json-schema/attributes/oneof.rb @@ -15,10 +15,10 @@ def self.validate(current_schema, data, fragments, processor, validator, options valid = false one_of.each_with_index do |element, schema_index| - schema = JSON::Schema.new(element,current_schema.uri,validator) + schema = JSON::Schema.new(element, current_schema.uri, validator) pre_validation_error_count = validation_errors(processor).count begin - schema.validate(data,fragments,processor,options) + schema.validate(data, fragments, processor, options) success_data = data.is_a?(Hash) ? data.clone : data valid = true rescue ValidationError diff --git a/lib/json-schema/attributes/ref.rb b/lib/json-schema/attributes/ref.rb index 9c1f0be5..5f58f12b 100644 --- a/lib/json-schema/attributes/ref.rb +++ b/lib/json-schema/attributes/ref.rb @@ -6,7 +6,7 @@ module JSON class Schema class RefAttribute < Attribute def self.validate(current_schema, data, fragments, processor, validator, options = {}) - uri,schema = get_referenced_uri_and_schema(current_schema.schema, current_schema, validator) + uri, schema = get_referenced_uri_and_schema(current_schema.schema, current_schema, validator) if schema schema.validate(data, fragments, processor, options) @@ -20,7 +20,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options end def self.get_referenced_uri_and_schema(s, current_schema, validator) - uri,schema = nil,nil + uri, schema = nil, nil temp_uri = JSON::Util::URI.normalize_ref(s['$ref'], current_schema.uri) @@ -51,10 +51,10 @@ def self.get_referenced_uri_and_schema(s, current_schema, validator) # We have the schema finally, build it and validate! uri = temp_uri - schema = JSON::Schema.new(target_schema,temp_uri,validator) + schema = JSON::Schema.new(target_schema, temp_uri, validator) end - [uri,schema] + [uri, schema] end end end diff --git a/lib/json-schema/attributes/type.rb b/lib/json-schema/attributes/type.rb index 1073c35c..4a7e38ae 100644 --- a/lib/json-schema/attributes/type.rb +++ b/lib/json-schema/attributes/type.rb @@ -25,14 +25,14 @@ def self.validate(current_schema, data, fragments, processor, validator, options valid = data_valid_for_type?(data, type) elsif type.is_a?(Hash) && union # Validate as a schema - schema = JSON::Schema.new(type,current_schema.uri,validator) + schema = JSON::Schema.new(type, current_schema.uri, validator) # We're going to add a little cruft here to try and maintain any validation errors that occur in this union type # We'll handle this by keeping an error count before and after validation, extracting those errors and pushing them onto a union error pre_validation_error_count = validation_errors(processor).count begin - schema.validate(data,fragments,processor,options.merge(:disallow => false)) + schema.validate(data, fragments, processor, options.merge(:disallow => false)) valid = true rescue ValidationError # We don't care that these schemas don't validate - we only care that one validated diff --git a/lib/json-schema/schema.rb b/lib/json-schema/schema.rb index 32e17940..6f09f377 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/schema/validator.rb b/lib/json-schema/schema/validator.rb index 05913c38..7d2911a9 100644 --- a/lib/json-schema/schema/validator.rb +++ b/lib/json-schema/schema/validator.rb @@ -20,7 +20,7 @@ def extend_schema_definition(schema_uri) end def validate(current_schema, data, fragments, processor, options = {}) - current_schema.schema.each do |attr_name,attribute| + current_schema.schema.each do |attr_name, attribute| if @attributes.has_key?(attr_name.to_s) @attributes[attr_name.to_s].validate(current_schema, data, fragments, processor, self, options) end diff --git a/lib/json-schema/util/uri.rb b/lib/json-schema/util/uri.rb index 9f7a3104..6aa4c69e 100644 --- a/lib/json-schema/util/uri.rb +++ b/lib/json-schema/util/uri.rb @@ -14,7 +14,7 @@ def self.normalized_uri(uri, base_path = Dir.pwd) # Check for absolute path if normalized_uri.relative? data = normalized_uri - data = File.join(base_path, data) if data.path[0,1] != "/" + data = File.join(base_path, data) if data.path[0, 1] != "/" normalized_uri = file_uri(data) end @normalize_cache[uri] = normalized_uri.freeze @@ -45,7 +45,7 @@ def self.normalize_ref(ref, base) path, fragment = ref.to_s.split("#") if path.nil? || path == '' ref_uri.path = base_uri.path - elsif path[0,1] == "/" + elsif path[0, 1] == "/" ref_uri.path = Pathname.new(path).cleanpath.to_s else ref_uri.join!(path) diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index 8377223c..b7d0d555 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -102,7 +102,7 @@ def schema_from_fragment(base_schema, fragment) def validate(data) original_data = data data = initialize_data(data) - @base_schema.validate(data,[],self,@validation_options) + @base_schema.validate(data, [], self, @validation_options) if @options[:record_errors] if @options[:errors_as_objects] @@ -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 @@ -244,7 +244,7 @@ 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 @@ -498,7 +498,7 @@ def merge_missing_values(source, destination) @@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 diff --git a/test/bad_schema_ref_test.rb b/test/bad_schema_ref_test.rb index e8c93a04..9c60673d 100644 --- a/test/bad_schema_ref_test.rb +++ b/test/bad_schema_ref_test.rb @@ -17,9 +17,9 @@ def test_bad_uri_ref "items" => { "$ref" => "../google.json"}, } - data = [1,2,3] + data = [1, 2, 3] error = assert_raises(JSON::Schema::ReadFailed) do - JSON::Validator.validate(schema,data) + JSON::Validator.validate(schema, data) end expanded_path = File.expand_path("../../google.json", __FILE__) @@ -36,9 +36,9 @@ def test_bad_host_ref "items" => { "$ref" => "http://ppcheesecheseunicornnuuuurrrrr.example.invalid/json.schema"}, } - data = [1,2,3] + data = [1, 2, 3] error = assert_raises(JSON::Schema::ReadFailed) do - JSON::Validator.validate(schema,data) + JSON::Validator.validate(schema, data) end assert_equal(:uri, error.type) diff --git a/test/draft1_test.rb b/test/draft1_test.rb index 1308ffe0..5cf87f67 100644 --- a/test/draft1_test.rb +++ b/test/draft1_test.rb @@ -103,7 +103,7 @@ def test_disallow data["a"] = 5 refute_valid schema, data - schema["properties"]["a"]["disallow"] = ["integer","string"] + schema["properties"]["a"]["disallow"] = ["integer", "string"] data["a"] = 'string' refute_valid schema, data diff --git a/test/draft2_test.rb b/test/draft2_test.rb index 6c4cc431..c418c59f 100644 --- a/test/draft2_test.rb +++ b/test/draft2_test.rb @@ -79,7 +79,7 @@ def test_disallow data["a"] = 5 refute_valid schema, data - schema["properties"]["a"]["disallow"] = ["integer","string"] + schema["properties"]["a"]["disallow"] = ["integer", "string"] data["a"] = 'string' refute_valid schema, data diff --git a/test/draft3_test.rb b/test/draft3_test.rb index f5b0cca6..bc333ae6 100644 --- a/test/draft3_test.rb +++ b/test/draft3_test.rb @@ -110,13 +110,13 @@ def test_strict_properties_required_props } data = {"a" => "a"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) end def test_strict_properties_additional_props @@ -130,19 +130,19 @@ def test_strict_properties_additional_props } data = {"a" => "a"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => "c"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => 3} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) end def test_strict_properties_pattern_props @@ -156,25 +156,25 @@ def test_strict_properties_pattern_props } data = {"a" => "a"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => "c"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => 3} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "23 taco" => 3} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "23 taco" => "cheese"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) end def test_disallow @@ -196,7 +196,7 @@ def test_disallow data["a"] = 5 refute_valid schema, data - schema["properties"]["a"]["disallow"] = ["integer","string"] + schema["properties"]["a"]["disallow"] = ["integer", "string"] data["a"] = 'string' refute_valid schema, data @@ -227,7 +227,7 @@ def test_extends } assert_valid schema, data - assert(!JSON::Validator.validate(schema2,data)) + assert(!JSON::Validator.validate(schema2, data)) schema["extends"] = schema2 @@ -241,15 +241,15 @@ def test_list_option "properties" => { "a" => {"type" => "integer", "required" => true} }, } - data = [{"a" => 1},{"a" => 2},{"a" => 3}] - assert(JSON::Validator.validate(schema,data,:list => true)) + data = [{"a" => 1}, {"a" => 2}, {"a" => 3}] + assert(JSON::Validator.validate(schema, data, :list => true)) refute_valid schema, data data = {"a" => 1} - assert(!JSON::Validator.validate(schema,data,:list => true)) + assert(!JSON::Validator.validate(schema, data, :list => true)) - data = [{"a" => 1},{"b" => 2},{"a" => 3}] - assert(!JSON::Validator.validate(schema,data,:list => true)) + data = [{"a" => 1}, {"b" => 2}, {"a" => 3}] + assert(!JSON::Validator.validate(schema, data, :list => true)) end def test_self_reference @@ -313,9 +313,9 @@ def test_format_uri "properties" => { "a" => {"type" => "string", "format" => "uri"}}, } - assert(JSON::Validator.validate(schema,data1)) - assert(!JSON::Validator.validate(schema,data2)) - assert(JSON::Validator.validate(schema,data3)) + assert(JSON::Validator.validate(schema, data1)) + assert(!JSON::Validator.validate(schema, data2)) + assert(JSON::Validator.validate(schema, data3)) end def test_schema @@ -361,7 +361,7 @@ def test_dependency "c" => {"type" => "integer"}, }, "dependencies" => { - "a" => ["b","c"], + "a" => ["b", "c"], }, } @@ -384,7 +384,7 @@ def test_default data = {:b => 2} assert_valid schema, data assert_nil(data["a"]) - assert(JSON::Validator.validate(schema,data, :insert_defaults => true)) + assert(JSON::Validator.validate(schema, data, :insert_defaults => true)) assert_equal(42, data["a"]) assert_equal(2, data[:b]) @@ -400,7 +400,7 @@ def test_default data = {:b => 2} refute_valid schema, data assert_nil(data["a"]) - assert(JSON::Validator.validate(schema,data, :insert_defaults => true)) + assert(JSON::Validator.validate(schema, data, :insert_defaults => true)) assert_equal(42, data["a"]) assert_equal(2, data[:b]) @@ -416,7 +416,7 @@ def test_default data = {:b => 2} refute_valid schema, data assert_nil(data["a"]) - assert(!JSON::Validator.validate(schema,data, :insert_defaults => true)) + assert(!JSON::Validator.validate(schema, data, :insert_defaults => true)) assert_nil(data["a"]) assert_equal(2, data[:b]) @@ -432,8 +432,8 @@ def test_default data = {:b => 2} assert_valid schema, data assert_nil(data["a"]) - assert(!JSON::Validator.validate(schema,data, :insert_defaults => true)) - assert_equal("42",data["a"]) + assert(!JSON::Validator.validate(schema, data, :insert_defaults => true)) + assert_equal("42", data["a"]) assert_equal(2, data[:b]) end end diff --git a/test/draft4_test.rb b/test/draft4_test.rb index 5fd03826..e72002db 100644 --- a/test/draft4_test.rb +++ b/test/draft4_test.rb @@ -95,16 +95,16 @@ def test_strict_properties } data = {"a" => "a"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => "c"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) end def test_strict_properties_additional_props @@ -118,19 +118,19 @@ def test_strict_properties_additional_props } data = {"a" => "a"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => "c"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => 3} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) end def test_strict_properties_pattern_props @@ -144,25 +144,25 @@ def test_strict_properties_pattern_props } data = {"a" => "a"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => "c"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => 3} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "23 taco" => 3} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "23 taco" => "cheese"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) end def test_list_option @@ -173,15 +173,15 @@ def test_list_option "properties" => { "a" => {"type" => "integer"} }, } - data = [{"a" => 1},{"a" => 2},{"a" => 3}] - assert(JSON::Validator.validate(schema,data,:list => true)) + data = [{"a" => 1}, {"a" => 2}, {"a" => 3}] + assert(JSON::Validator.validate(schema, data, :list => true)) refute_valid schema, data data = {"a" => 1} - assert(!JSON::Validator.validate(schema,data,:list => true)) + assert(!JSON::Validator.validate(schema, data, :list => true)) - data = [{"a" => 1},{"b" => 2},{"a" => 3}] - assert(!JSON::Validator.validate(schema,data,:list => true)) + data = [{"a" => 1}, {"b" => 2}, {"a" => 3}] + assert(!JSON::Validator.validate(schema, data, :list => true)) end def test_default_with_strict_and_anyof @@ -331,9 +331,9 @@ def test_format_uri "properties" => { "a" => {"type" => "string", "format" => "uri"}}, } - assert(JSON::Validator.validate(schema,data1)) - assert(!JSON::Validator.validate(schema,data2)) - assert(JSON::Validator.validate(schema,data3)) + assert(JSON::Validator.validate(schema, data1)) + assert(!JSON::Validator.validate(schema, data2)) + assert(JSON::Validator.validate(schema, data3)) end def test_schema @@ -343,7 +343,7 @@ def test_schema } data = {"a" => "taco"} - assert(!JSON::Validator.validate(schema,data)) + assert(!JSON::Validator.validate(schema, data)) schema = { "$schema" => "http://json-schema.org/draft-04/schema#", @@ -379,7 +379,7 @@ def test_dependency "c" => {"type" => "integer"}, }, "dependencies" => { - "a" => ["b","c"], + "a" => ["b", "c"], }, } @@ -410,9 +410,9 @@ def test_schema_dependency "name" => "John Doe", "credit_card" => 5555555555555555, } - assert(!JSON::Validator.validate(schema,data), 'test schema dependency with invalid data') + assert(!JSON::Validator.validate(schema, data), 'test schema dependency with invalid data') data['billing_address'] = "Somewhere over the rainbow" - assert(JSON::Validator.validate(schema,data), 'test schema dependency with valid data') + assert(JSON::Validator.validate(schema, data), 'test schema dependency with valid data') end def test_default @@ -428,7 +428,7 @@ def test_default data = {:b => 2} assert_valid schema, data assert_nil(data["a"]) - assert(JSON::Validator.validate(schema,data, :insert_defaults => true)) + assert(JSON::Validator.validate(schema, data, :insert_defaults => true)) assert_equal(42, data["a"]) assert_equal(2, data[:b]) @@ -445,7 +445,7 @@ def test_default data = {:b => 2} refute_valid schema, data assert_nil(data["a"]) - assert(JSON::Validator.validate(schema,data, :insert_defaults => true)) + assert(JSON::Validator.validate(schema, data, :insert_defaults => true)) assert_equal(42, data["a"]) assert_equal(2, data[:b]) @@ -462,7 +462,7 @@ def test_default data = {:b => 2} refute_valid schema, data assert_nil(data["a"]) - assert(!JSON::Validator.validate(schema,data, :insert_defaults => true)) + assert(!JSON::Validator.validate(schema, data, :insert_defaults => true)) assert_nil(data["a"]) assert_equal(2, data[:b]) @@ -478,8 +478,8 @@ def test_default data = {:b => 2} assert_valid schema, data assert_nil(data["a"]) - assert(!JSON::Validator.validate(schema,data, :insert_defaults => true)) - assert_equal("42",data["a"]) + assert(!JSON::Validator.validate(schema, data, :insert_defaults => true)) + assert_equal("42", data["a"]) assert_equal(2, data[:b]) end @@ -614,7 +614,7 @@ def test_not "properties" => { "a" => {"not" => {"anyOf" => [ { - "type" => ["string","boolean"], + "type" => ["string", "boolean"], }, { "type" => "object", @@ -653,11 +653,11 @@ def test_not_fully_validate } data = {"a" => 1} - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert_equal(0, errors.length) data = {"a" => "taco"} - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert_equal(1, errors.length) end @@ -675,10 +675,10 @@ def test_definitions }, } - data = [1,2,3] + data = [1, 2, 3] assert_valid schema, data - data = [-1,2,3] + data = [-1, 2, 3] refute_valid schema, data end end diff --git a/test/files_test.rb b/test/files_test.rb index ad144f15..33539c9f 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 2038fb00..f3bc8235 100644 --- a/test/fragment_resolution_test.rb +++ b/test/fragment_resolution_test.rb @@ -20,11 +20,11 @@ def test_fragment_resolution assert_valid schema, data, :fragment => "#/properties/a" assert_raises JSON::Schema::SchemaError do - JSON::Validator.validate!(schema,data,:fragment => "/properties/a") + JSON::Validator.validate!(schema, data, :fragment => "/properties/a") end assert_raises JSON::Schema::SchemaError do - JSON::Validator.validate!(schema,data,:fragment => "#/properties/b") + JSON::Validator.validate!(schema, data, :fragment => "#/properties/b") end end diff --git a/test/full_validation_test.rb b/test/full_validation_test.rb index 292bbd6f..a1c1b369 100644 --- a/test/full_validation_test.rb +++ b/test/full_validation_test.rb @@ -12,7 +12,7 @@ def test_full_validation }, } - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) data = {"c" => 5} @@ -28,7 +28,7 @@ def test_full_validation }, } - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert(errors.length == 2) end @@ -73,29 +73,29 @@ def test_full_validation_with_union_types "type" => "object", "properties" => { "b" => { - "type" => ["null","integer"], + "type" => ["null", "integer"], }, }, } - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) schema = { "type" => "object", "properties" => { "b" => { - "type" => ["integer","null"], + "type" => ["integer", "null"], }, }, } - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) data = {"b" => "a string"} - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert(errors.length == 1) schema = { @@ -123,17 +123,17 @@ def test_full_validation_with_union_types data = {"b" => {"c" => "taco"}} - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) data = {"b" => {"d" => 6}} - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert(errors.empty?) data = {"b" => {"c" => 6, "d" => "OH GOD"}} - errors = JSON::Validator.fully_validate(schema,data) + errors = JSON::Validator.fully_validate(schema, data) assert(errors.length == 1) end @@ -148,7 +148,7 @@ def test_full_validation_with_object_errors }, } - errors = JSON::Validator.fully_validate(schema,data,:errors_as_objects => true) + errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true) assert(errors.empty?) data = {"c" => 5} @@ -164,7 +164,7 @@ def test_full_validation_with_object_errors }, } - errors = JSON::Validator.fully_validate(schema,data,:errors_as_objects => true) + errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true) assert(errors.length == 2) assert(errors[0][:failed_attribute] == "Required") @@ -193,7 +193,7 @@ def test_full_validation_with_nested_required_properties } data = {"x" => {"a"=>5, "d"=>5, "e"=>"what?"}} - errors = JSON::Validator.fully_validate(schema,data,:errors_as_objects => true) + errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true) assert_equal 2, errors.length assert_equal '#/x', errors[0][:fragment] assert_equal 'Required', errors[0][:failed_attribute] @@ -223,10 +223,10 @@ def test_full_validation_with_nested_required_propertiesin_array }, } missing_b= {"a"=>5} - e_is_wrong_type= {"a"=>5,"b"=>5,"e"=>"what?"} + 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) + errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true) assert_equal 2, errors.length assert_equal '#/x/0', errors[0][:fragment] assert_equal 'Required', errors[0][:failed_attribute] diff --git a/test/one_of_test.rb b/test/one_of_test.rb index 4ddb8f64..88a22ccd 100644 --- a/test/one_of_test.rb +++ b/test/one_of_test.rb @@ -47,7 +47,7 @@ def test_one_of_sub_errors errors = JSON::Validator.fully_validate(schema, { "a" => 5 }, :errors_as_objects => true) nested_errors = errors[0][:errors] - assert_equal([:oneof_0,:oneof_1,:oneof_2], nested_errors.keys, 'should have nested errors for each allOf subschema') + assert_equal([:oneof_0, :oneof_1, :oneof_2], nested_errors.keys, 'should have nested errors for each allOf subschema') assert_match(/the property '#\/a' of type Integer did not match the following type: string/i, nested_errors[:oneof_0][0][:message]) assert_match(/the property '#\/a' did not have a minimum value of 10, inclusively/i, nested_errors[:oneof_2][0][:message]) end diff --git a/test/schema_validation_test.rb b/test/schema_validation_test.rb index dabeb446..8419f0eb 100644 --- a/test/schema_validation_test.rb +++ b/test/schema_validation_test.rb @@ -124,8 +124,8 @@ def symbolized_schema def test_draft03_validation 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)) + 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 def test_validate_just_schema_draft03 @@ -139,8 +139,8 @@ def test_validate_just_schema_draft03 def test_draft04_validation 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)) + 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 def test_validate_just_schema_draft04 @@ -154,16 +154,16 @@ def test_validate_just_schema_draft04 def test_validate_schema_3_without_version_option 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)) + assert(JSON::Validator.validate(valid_schema_v3, data, :validate_schema => true)) + assert(!JSON::Validator.validate(invalid_schema_v3, data, :validate_schema => true)) end def test_schema_validation_from_different_directory Dir.mktmpdir do |tmpdir| Dir.chdir(tmpdir) do 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)) + 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 end end diff --git a/test/support/enum_validation.rb b/test/support/enum_validation.rb index bf93112a..3bf60f40 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"}]}, }, } @@ -39,7 +39,7 @@ def test_enum_general data["a"] = 'boo' assert_valid schema, data - data["a"] = [1,2,3] + data["a"] = [1, 2, 3] assert_valid schema, data data["a"] = {"a" => "b"} @@ -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/strict_validation.rb b/test/support/strict_validation.rb index 3a237142..ff281323 100644 --- a/test/support/strict_validation.rb +++ b/test/support/strict_validation.rb @@ -9,22 +9,22 @@ def test_strict_properties } data = {"a" => "a"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => "c"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) end def test_strict_error_message schema = { :type => 'object', :properties => { :a => { :type => 'string' } } } data = { :a => 'abc', :b => 'abc' } - errors = JSON::Validator.fully_validate(schema,data,:strict => true) + errors = JSON::Validator.fully_validate(schema, data, :strict => true) assert_match("The property '#/' contained undefined properties: 'b' in schema", errors[0]) end @@ -39,19 +39,19 @@ def test_strict_properties_additional_props } data = {"a" => "a"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => "c"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => 3} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) end def test_strict_properties_pattern_props @@ -64,24 +64,24 @@ def test_strict_properties_pattern_props } data = {"a" => "a"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"b" => "b"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b"} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => "c"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "c" => 3} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "23 taco" => 3} - assert(JSON::Validator.validate(schema,data,:strict => true)) + assert(JSON::Validator.validate(schema, data, :strict => true)) data = {"a" => "a", "b" => "b", "23 taco" => "cheese"} - assert(!JSON::Validator.validate(schema,data,:strict => true)) + assert(!JSON::Validator.validate(schema, data, :strict => true)) end end