Open mfly opened 4 years ago
Closed because it's related to dry-validation
- https://github.com/dry-rb/dry-validation/issues/643
Reopening, because it can be reproduced with Dry::Schema
schema = Dry::Schema.Params do
required(:data) do
hash { required(:type).filled(:string) } |
array(:hash) { required(:type).filled(:string) }
end
end
actual:
schema.call(data: { type: 'tests', undefined: 1 })
# <Dry::Schema::Result{:data=>{:type=>"tests", :undefined=>1}} errors={}>
expected:
schema.call(data: { type: 'tests', undefined: 1 })
# <Dry::Schema::Result{:data=>{:type=>"tests"}} errors={}>
Thanks for reporting this. I'm scheduling the fix for 2.0.0 because it's going to be simpler to do once a couple other improvements are done.
Describe the bug I need a Contract that is valid for hashes where the
:data
key is either aHash
with defined structure or anArray
of suchHash
es:OR
Following contracts work as expected:
To Reproduce
Unfortunately a Contract that combines those two rules leaks unexpected properties when
:data
contains aHash
:It works in the second scenario:
Validation also seems to work:
Expected behavior Result does not include unexpected keys:
Your environment