# How to disable key validation for a hash prop

**URL:** https://discourse.dry-rb.org/t/how-to-disable-key-validation-for-a-hash-prop/1860
**Category:** Support
**Created:** [November 16, 2024, 5:50pm UTC](https://discourse.dry-rb.org/t/how-to-disable-key-validation-for-a-hash-prop/1860 "2024-11-16T17:50:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![diegocolombo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/diegocolombo/32/1000_2.png) [@diegocolombo](https://discourse.dry-rb.org/u/diegocolombo)
#### Post date: [November 16, 2024, 5:50pm UTC](https://discourse.dry-rb.org/t/how-to-disable-key-validation-for-a-hash-prop/1860/1 "2024-11-16T17:50:09Z")

</div>

In my RoR app, I’ve declared a initializer to define validate\_key

```auto
Dry::Schema.config.validate_keys = true

```

Let’s say I’ve got the following schema

```auto
schema = Dry::Schema.Json do
  optional(:foo).maybe(:hash)
end

```

I wan’t to be able to send any hash to the prop `foo`, but when I do it I’ve got an error

```auto
schema.call({ foo: { bar: 'baz' } })
#<Dry::Schema::Result{:foo=>{:bar=>"baz"}} errors={:foo=>{:bar=>["is not allowed"]}} path=[]>

```

---

<div class="post-metadata">

### Author: ![alassek](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/alassek/32/314_2.png) [@alassek](https://discourse.dry-rb.org/u/alassek)
#### Post date: [November 18, 2024, 7:49pm UTC](https://discourse.dry-rb.org/t/how-to-disable-key-validation-for-a-hash-prop/1860/2 "2024-11-18T19:49:55Z")

</div>

I’m not able to reproduce this behavior with the code sample you’ve provided. Can you give me exact reproduction steps?

```ruby
Dry::Schema.config.validate_keys = false

schema = Dry::Schema.JSON do
  optional(:foo).maybe(:hash)
end

```

```ruby
[1] pry(main)> schema.call({ foo: { bar: 'baz' } })
=> #<Dry::Schema::Result{:foo=>{:bar=>"baz"}} errors={} path=[]>

```

---

<div class="post-metadata">

### Author: ![diegocolombo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/diegocolombo/32/1000_2.png) [@diegocolombo](https://discourse.dry-rb.org/u/diegocolombo)
#### Post date: [November 19, 2024, 1:48pm UTC](https://discourse.dry-rb.org/t/how-to-disable-key-validation-for-a-hash-prop/1860/3 "2024-11-19T13:48:34Z")

</div>

@alassek When `validate_keys` is false, the problem won’t happening.  
I want to be able to validate keys, but not on my hash prop.

```auto
Dry::Schema.config.validate_keys = true

schema = Dry::Schema.JSON do
  optional(:foo).maybe(:hash)
end

r = schema.call({ bar: 1, foo: { bar: 2 } })
r.errors.to_h
# {:bar=>["is not allowed"], :foo=>{:bar=>["is not allowed"]}}

```

In the example above, `bar` shouldn’t be allowed on root, but it should be inside the hash `foo` prop

---

<div class="post-metadata">

### Author: ![alassek](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/alassek/32/314_2.png) [@alassek](https://discourse.dry-rb.org/u/alassek)
#### Post date: [November 19, 2024, 6:37pm UTC](https://discourse.dry-rb.org/t/how-to-disable-key-validation-for-a-hash-prop/1860/4 "2024-11-19T18:37:09Z")

</div>

Okay I understand. This appears to be a [bug in the key validator](https://github.com/dry-rb/dry-schema/issues/452).
