README_V3.md in schemacop-3.0.17 vs README_V3.md in schemacop-3.0.18

- old
+ new

@@ -862,10 +862,17 @@ Specifies the (inclusive) minimum number of properties a hash must contain. * `max_properties` Specifies the (inclusive) maximum number of properties a hash must contain. +* `ignore_obsolete_properties` + Similar to `additional_properties`. If this is set to `true`, all additional + properties are allowed (i.e. they pass the validation), but they are removed + from the result hash. This is useful e.g. to validate params coming from the + controller, as this only allows white-listed params and removes any params + which are not whitelisted (i.e. similar to strong params from Rails). + #### Specifying properties Hash nodes support a block in which you can specify the required hash contents. ##### Standard properties @@ -1067,9 +1074,25 @@ schema.validate!({}) # => {} schema.validate!({foo: [1, 2, 3]}) # => {"foo"=>[1, 2, 3]} schema.validate!({foo: :bar}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "Symbol", expected "array". schema.validate!({Foo: :bar}) # => Schemacop::Exceptions::ValidationError: /: Property name :Foo does not match "^[a-z]+$". /Foo: Invalid type, got type "Symbol", expected "array". +``` + +##### Ignoring obsolete properties + +By enabling `ignore_obsolete_properties`, you can filter out any unspecified params, +while still passing validation: + +```ruby +# This schema will accept any additional properties, but remove them from the result +schema = Schemacop::Schema3.new :hash, ignore_obsolete_properties: true do + int? :foo +end + +schema.validate!({}) # => {} +schema.validate!({foo: :bar}) # => {"foo"=>:bar} +schema.validate!({foo: :bar, baz: 42}) # => {"foo"=>:bar} ``` ##### Dependencies Using the DSL method `dep`, you can specifiy (non-nested) property dependencies: