dry-schema: Generating errors for unexpected keys in Hash
I would love to be able to define a schema which generated errors if it was given unexpected keys:
require 'dry/validation'
schema = Dry::Validation.Schema(strict: true) do
hash? do
required(:foo).filled(:int?)
required(:bar).filled(:str?)
end
end
outcome = schema.call(foo: 1, bar: "two", baz: 3.0)
p outcome.messages # => {:baz=>["is not allowed"]}
This is really important for defining a public JSON API where you want to reject invalid user input.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 16 (5 by maintainers)
This will be supported in 1.0