Skip to content

Key validation shouldn't happen when no schema for a hash is set #452

@flash-gordon

Description

@flash-gordon

Describe the bug

There can be a case when no schema for a hash is set. In such a case, there's not need to validate keys. I might be wrong but it's just logical to me.

To Reproduce

DemoSchema = Dry::Schema.define do
  config.validate_keys = true

  required(:addresses).array(:hash)
end

DemoSchema.call({addresses: [{number: "oo"}]}) 
=> #<Dry::Schema::Result{:addresses=>[{:number=>"oo"}]} errors={:addresses=>{0=>{:number=>["is not allowed"]}}} path=[]>

Expected behavior

The validation passes. We didn't specify any key for nested hashes, key validation shouldn't be applied in such cases. I would expect such values to be validated at later stages with rules or custom code.

My environment

  • Affects my production application: NO
  • Ruby version: 3.2.0
  • OS: N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions