schemacop 3.0.20 → 3.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e4a4c21714a897d8dc9d04f6ef054890c39571a200390fc727943be5012f4fe
4
- data.tar.gz: 29f3660744d2080d928bc0645fe6da7a110f985272a5a279508f7eb85816905e
3
+ metadata.gz: 2ac247150fb2c8a5e10bff8173787ce94e063b3a24f8fe2f323d78015424bfbb
4
+ data.tar.gz: c3393891a019419b1b0aac9200487bdd547124787507ce67d9be7d9a8ee2ae63
5
5
  SHA512:
6
- metadata.gz: f5a5cfa4ea22c5b9203ecb7d049e15b29cb2c41ea1c4246bcab707a9265bb1769e1c645a1a7b5c7e5a8f0640c796aa154f87497d0a5b65228f512d6a14f893d8
7
- data.tar.gz: ed8dd1f20572424c12dc1bb3b098169482a1ee887721054227d4f6111ad7fb65548e87b3a128f24b3a56ac4fbcd083de39bf25fd6b4404516850f9f2eab46711
6
+ metadata.gz: b51f45a493ce448dcb6413ec9f4eb7c109891bad83ff5bac50ef1fb59af7adac8606c70de744dff598b19784faa4c43a8c88e47ed3fddfa1e7f772eee97cc6e3
7
+ data.tar.gz: 42e69a2f2767bd95ebfaa13306e0e3e3d70b21998e013754b08a5ff6de448ddd680cec4f490b2acf9b94d9b5b2235bf713c63af675d256411feaa352b95912c9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change log
2
2
 
3
+ ## 3.0.22 (2022-10-31)
4
+
5
+ * Fix `v3_default_options` being not applied to nodes
6
+
7
+ ## 3.0.21 (2022-10-31)
8
+
9
+ * Adapt option `ignore_obsolete_properties` of `HashNode` so that it can also
10
+ function as a parameter white-list when set to an enumerable.
11
+
3
12
  ## 3.0.20 (2022-09-29)
4
13
 
5
14
  * Improve error messages for `all_of`, `any_of` and `one_of`
data/README_V3.md CHANGED
@@ -873,6 +873,9 @@ It consists of key-value-pairs that can be validated using arbitrary nodes.
873
873
  controller, as this only allows white-listed params and removes any params
874
874
  which are not whitelisted (i.e. similar to strong params from Rails).
875
875
 
876
+ If it is set to an enumerable (e.g. `Set` or `Array`), it functions as a
877
+ white-list and only the given additional properties are allowed.
878
+
876
879
  #### Specifying properties
877
880
 
878
881
  Hash nodes support a block in which you can specify the required hash contents.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.20
1
+ 3.0.22
@@ -141,7 +141,9 @@ module Schemacop
141
141
  result.in_path(name) do
142
142
  property_patterns[match]._validate(additional_property, result: result)
143
143
  end
144
- elsif !options[:ignore_obsolete_properties]
144
+ elsif (options[:ignore_obsolete_properties].is_a?(Enumerable) &&
145
+ options[:ignore_obsolete_properties].exclude?(name.to_sym)) ||
146
+ !options[:ignore_obsolete_properties]
145
147
  result.error "Obsolete property #{name.to_s.inspect}."
146
148
  end
147
149
  elsif options[:additional_properties].is_a?(Node)
@@ -28,9 +28,8 @@ module Schemacop
28
28
  klass = resolve_class(type)
29
29
  fail "Could not find node for type #{type.inspect}." unless klass
30
30
 
31
- node = klass.new(**options, &block)
32
-
33
31
  options = Schemacop.v3_default_options.slice(*klass.allowed_options).merge(options)
32
+ node = klass.new(**options, &block)
34
33
 
35
34
  if options.delete(:cast_str)
36
35
  format = NodeRegistry.name(klass)
data/schemacop.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: schemacop 3.0.20 ruby lib
2
+ # stub: schemacop 3.0.22 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "3.0.20"
6
+ s.version = "3.0.22"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sitrox".freeze]
11
- s.date = "2022-09-29"
11
+ s.date = "2022-10-31"
12
12
  s.files = [".github/workflows/ruby.yml".freeze, ".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "README_V2.md".freeze, "README_V3.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/schemacop.rb".freeze, "lib/schemacop/base_schema.rb".freeze, "lib/schemacop/exceptions.rb".freeze, "lib/schemacop/railtie.rb".freeze, "lib/schemacop/schema.rb".freeze, "lib/schemacop/schema2.rb".freeze, "lib/schemacop/schema3.rb".freeze, "lib/schemacop/scoped_env.rb".freeze, "lib/schemacop/v2.rb".freeze, "lib/schemacop/v2/caster.rb".freeze, "lib/schemacop/v2/collector.rb".freeze, "lib/schemacop/v2/dupper.rb".freeze, "lib/schemacop/v2/field_node.rb".freeze, "lib/schemacop/v2/node.rb".freeze, "lib/schemacop/v2/node_resolver.rb".freeze, "lib/schemacop/v2/node_supporting_field.rb".freeze, "lib/schemacop/v2/node_supporting_type.rb".freeze, "lib/schemacop/v2/node_with_block.rb".freeze, "lib/schemacop/v2/validator/array_validator.rb".freeze, "lib/schemacop/v2/validator/boolean_validator.rb".freeze, "lib/schemacop/v2/validator/float_validator.rb".freeze, "lib/schemacop/v2/validator/hash_validator.rb".freeze, "lib/schemacop/v2/validator/integer_validator.rb".freeze, "lib/schemacop/v2/validator/nil_validator.rb".freeze, "lib/schemacop/v2/validator/number_validator.rb".freeze, "lib/schemacop/v2/validator/object_validator.rb".freeze, "lib/schemacop/v2/validator/string_validator.rb".freeze, "lib/schemacop/v2/validator/symbol_validator.rb".freeze, "lib/schemacop/v3.rb".freeze, "lib/schemacop/v3/all_of_node.rb".freeze, "lib/schemacop/v3/any_of_node.rb".freeze, "lib/schemacop/v3/array_node.rb".freeze, "lib/schemacop/v3/boolean_node.rb".freeze, "lib/schemacop/v3/combination_node.rb".freeze, "lib/schemacop/v3/context.rb".freeze, "lib/schemacop/v3/dsl_scope.rb".freeze, "lib/schemacop/v3/global_context.rb".freeze, "lib/schemacop/v3/hash_node.rb".freeze, "lib/schemacop/v3/integer_node.rb".freeze, "lib/schemacop/v3/is_not_node.rb".freeze, "lib/schemacop/v3/node.rb".freeze, "lib/schemacop/v3/node_registry.rb".freeze, "lib/schemacop/v3/number_node.rb".freeze, "lib/schemacop/v3/numeric_node.rb".freeze, "lib/schemacop/v3/object_node.rb".freeze, "lib/schemacop/v3/one_of_node.rb".freeze, "lib/schemacop/v3/reference_node.rb".freeze, "lib/schemacop/v3/result.rb".freeze, "lib/schemacop/v3/string_node.rb".freeze, "lib/schemacop/v3/symbol_node.rb".freeze, "schemacop.gemspec".freeze, "test/lib/test_helper.rb".freeze, "test/schemas/nested/group.rb".freeze, "test/schemas/user.rb".freeze, "test/unit/schemacop/v2/casting_test.rb".freeze, "test/unit/schemacop/v2/collector_test.rb".freeze, "test/unit/schemacop/v2/custom_check_test.rb".freeze, "test/unit/schemacop/v2/custom_if_test.rb".freeze, "test/unit/schemacop/v2/defaults_test.rb".freeze, "test/unit/schemacop/v2/empty_test.rb".freeze, "test/unit/schemacop/v2/nil_dis_allow_test.rb".freeze, "test/unit/schemacop/v2/node_resolver_test.rb".freeze, "test/unit/schemacop/v2/short_forms_test.rb".freeze, "test/unit/schemacop/v2/types_test.rb".freeze, "test/unit/schemacop/v2/validator_array_test.rb".freeze, "test/unit/schemacop/v2/validator_boolean_test.rb".freeze, "test/unit/schemacop/v2/validator_float_test.rb".freeze, "test/unit/schemacop/v2/validator_hash_test.rb".freeze, "test/unit/schemacop/v2/validator_integer_test.rb".freeze, "test/unit/schemacop/v2/validator_nil_test.rb".freeze, "test/unit/schemacop/v2/validator_number_test.rb".freeze, "test/unit/schemacop/v2/validator_object_test.rb".freeze, "test/unit/schemacop/v2/validator_string_test.rb".freeze, "test/unit/schemacop/v2/validator_symbol_test.rb".freeze, "test/unit/schemacop/v3/all_of_node_test.rb".freeze, "test/unit/schemacop/v3/any_of_node_test.rb".freeze, "test/unit/schemacop/v3/array_node_test.rb".freeze, "test/unit/schemacop/v3/boolean_node_test.rb".freeze, "test/unit/schemacop/v3/global_context_test.rb".freeze, "test/unit/schemacop/v3/hash_node_test.rb".freeze, "test/unit/schemacop/v3/integer_node_test.rb".freeze, "test/unit/schemacop/v3/is_not_node_test.rb".freeze, "test/unit/schemacop/v3/node_test.rb".freeze, "test/unit/schemacop/v3/number_node_test.rb".freeze, "test/unit/schemacop/v3/object_node_test.rb".freeze, "test/unit/schemacop/v3/one_of_node_test.rb".freeze, "test/unit/schemacop/v3/reference_node_test.rb".freeze, "test/unit/schemacop/v3/string_node_test.rb".freeze, "test/unit/schemacop/v3/symbol_node_test.rb".freeze]
13
13
  s.homepage = "https://github.com/sitrox/schemacop".freeze
14
14
  s.licenses = ["MIT".freeze]
@@ -1074,6 +1074,43 @@ module Schemacop
1074
1074
  assert_cast({ foo: 1, bar: 'baz', obsolete_key: 42 }, { foo: 1, bar: 'baz' }.with_indifferent_access)
1075
1075
  end
1076
1076
 
1077
+ def test_ignore_obsolete_properties_whitelist
1078
+ schema :hash, ignore_obsolete_properties: %i[obsolete_key] do
1079
+ int? :foo
1080
+ str? :bar
1081
+ end
1082
+
1083
+ # Some standard validations first
1084
+ assert_validation({})
1085
+ assert_validation({ foo: 1 })
1086
+ assert_validation({ bar: 'baz' })
1087
+ assert_validation({ foo: 1, bar: 'baz' })
1088
+ assert_validation({ foo: 1, bar: 'baz', baz: 'foo' }) do
1089
+ error '/', 'Obsolete property "baz".'
1090
+ end
1091
+
1092
+ assert_cast({}, {}.with_indifferent_access)
1093
+ assert_cast({ foo: 1 }, { foo: 1 }.with_indifferent_access)
1094
+ assert_cast({ bar: 'baz' }, { bar: 'baz' }.with_indifferent_access)
1095
+ assert_cast({ foo: 1, bar: 'baz' }, { foo: 1, bar: 'baz' }.with_indifferent_access)
1096
+
1097
+ # Should allow obsolete properties and remove them from the result
1098
+ assert_validation({ obsolete_key: 42 })
1099
+ assert_validation({ foo: 1, obsolete_key: 42 })
1100
+ assert_validation({ bar: 'baz', obsolete_key: 42 })
1101
+ assert_validation({ foo: 1, bar: 'baz', obsolete_key: 42 })
1102
+
1103
+ assert_cast({ obsolete_key: 42 }, {}.with_indifferent_access)
1104
+ assert_cast({ foo: 1, obsolete_key: 42 }, { foo: 1 }.with_indifferent_access)
1105
+ assert_cast({ bar: 'baz', obsolete_key: 42 }, { bar: 'baz' }.with_indifferent_access)
1106
+ assert_cast({ foo: 1, bar: 'baz', obsolete_key: 42 }, { foo: 1, bar: 'baz' }.with_indifferent_access)
1107
+
1108
+ assert_cast({ obsolete_key: 42 }, {}.with_indifferent_access)
1109
+ assert_cast({ foo: 1, obsolete_key: 42 }, { foo: 1 }.with_indifferent_access)
1110
+ assert_cast({ bar: 'baz', obsolete_key: 42 }, { bar: 'baz' }.with_indifferent_access)
1111
+ assert_cast({ foo: 1, bar: 'baz', obsolete_key: 42 }, { foo: 1, bar: 'baz' }.with_indifferent_access)
1112
+ end
1113
+
1077
1114
  def test_ignore_obsolete_properties_false
1078
1115
  schema :hash, ignore_obsolete_properties: false do
1079
1116
  int? :foo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemacop
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.20
4
+ version: 3.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-29 00:00:00.000000000 Z
11
+ date: 2022-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport