validate_keys=true ignored when the value is array
- Dominant language
- Ruby
- Stars
- 492
- Forks
- 123
- PR merge metrics
- No merged PRs in 30d
Description
## Describe the bug
When the unexpected key's value is an array, it is not reported as unexpected. Validation can be marked as successful even.
## To Reproduce
```rb
$ irb
irb(main):001:0> require 'dry-schema'
=> true
irb(main):002:0> require 'dry/schema/version'
=> true
irb(main):003:0> Dry::Schema::VERSION
=> "1.6.2"
irb(main):004:1* schema = Dry::Schema.define do
irb(main):005:1* config.validate_keys = true
irb(main):006:1*
irb(main):007:2* optional(:address).hash do
irb(main):008:1* end
irb(main):009:0> end
=> #[]}] rules={:address=>"key?(:address) THEN key[addr...
irb(main):010:0> schema.call(address: {a: 1})
=> #{}} errors={:address=>{:a=>["is not allowed"]}}>
irb(main):011:0> schema.call(address: {a: [1, 2, 3]})
=> #{}} errors={}>
irb(main):012:0> schema.call(address: {a: {b: 1}})
=> #{}} errors={:address=>{:a=>{:b=>["is not allowed"]}}}>
irb(main):013:0> schema.call(address: {a: 'zz'})
=> #{}} errors={:address=>{:a=>["is not allowed"]}}>
```
## Expected behavior
It should return `#{}} errors={:address=>{:a=>["is not allowed"]}}>` in all cases.
BTW, the nested hash behavior also looks wrong. It should not report that the `:b` key is out of place, it should do that for the parent structure instead. IOW, I expect all of the cases above to return the same value.
## My environment
- Affects my production application: **YES**
- Ruby version: 2.7.2
- OS: Ubuntu 20.04
Contributor guide
Research direction
Reproduce the issue with the Ruby IRB schema shown in the report, comparing array, scalar, and nested-hash values. Trace how validate_keys=true handles those values; done means each case reports the unexpected parent key :a as “is not allowed,” matching the expected Result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100