Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate_keys=true ignored when the value is array #355

Open
dgutov opened this issue May 20, 2021 · 0 comments
Open

validate_keys=true ignored when the value is array #355

dgutov opened this issue May 20, 2021 · 0 comments

Comments

@dgutov
Copy link

dgutov commented May 20, 2021

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

$ 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
=> #<Dry::Schema::Processor keys=[{:address=>[]}] rules={:address=>"key?(:address) THEN key[addr...
irb(main):010:0> schema.call(address: {a: 1})
=> #<Dry::Schema::Result{:address=>{}} errors={:address=>{:a=>["is not allowed"]}}>
irb(main):011:0> schema.call(address: {a: [1, 2, 3]})
=> #<Dry::Schema::Result{:address=>{}} errors={}>
irb(main):012:0> schema.call(address: {a: {b: 1}})
=> #<Dry::Schema::Result{:address=>{}} errors={:address=>{:a=>{:b=>["is not allowed"]}}}>
irb(main):013:0> schema.call(address: {a: 'zz'})
=> #<Dry::Schema::Result{:address=>{}} errors={:address=>{:a=>["is not allowed"]}}>

Expected behavior

It should return #<Dry::Schema::Result{:address=>{}} 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant