# \[dry-schema\] Array of hashes with one of schemas

**URL:** <https://discourse.dry-rb.org/t/dry-schema-array-of-hashes-with-one-of-schemas/796>\
**Category:** Support\
**Created:** [May 28, 2019, 4:33pm UTC](https://discourse.dry-rb.org/t/dry-schema-array-of-hashes-with-one-of-schemas/796 "2019-05-28T16:33:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![somenugget](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/somenugget/32/388_2.png) [@somenugget](https://discourse.dry-rb.org/u/somenugget)\
**Post date:** [May 28, 2019, 4:33pm UTC](https://discourse.dry-rb.org/t/dry-schema-array-of-hashes-with-one-of-schemas/796/1 "2019-05-28T16:33:44Z")

</div>

get: dry-schema  
version: 1.0.3

Hello, there.  
I’m trying to validate a schema with an array that can contain hashes with different structures.  
That what I’ve tried but unsuccessful.

```
LocationCustom = Dry::Schema.Params do
  required(:latitude).filled(:float?)
  required(:longitude).filled(:float?)
  required(:radius).filled(:float?)
end
LocationZip = Dry::Schema.Params do
  required(:type).filled(:string)
  required(:value).filled(:string)
end
Dry::Schema.Params do
  required(:locations).filled(:array?) do
    required(:locations).array {
      schema(LocationCustom).or(schema(LocationZip))
    }
  end
end

```

Is it possible to make what I wand using `dry-schema`'s DSL? Or should I try `dry-validation` for this?

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [June 10, 2019, 9:07pm UTC](https://discourse.dry-rb.org/t/dry-schema-array-of-hashes-with-one-of-schemas/796/2 "2019-06-10T21:07:10Z")

</div>

This should work:

```ruby
LocationCustom = Dry::Schema.Params do
  required(:latitude).filled(:float?)
  required(:longitude).filled(:float?)
  required(:radius).filled(:float?)
end

LocationZip = Dry::Schema.Params do
  required(:type).filled(:string)
  required(:value).filled(:string)
end

Dry::Schema.Params do
  required(:locations).value(:array).each { hash(LocationCustom) | hash(LocationZip) }
end

```

---

<div class="post-metadata">

**Author:** ![somenugget](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/somenugget/32/388_2.png) [@somenugget](https://discourse.dry-rb.org/u/somenugget)\
**Post date:** [June 25, 2019, 9:37am UTC](https://discourse.dry-rb.org/t/dry-schema-array-of-hashes-with-one-of-schemas/796/3 "2019-06-25T09:37:27Z")

</div>

Unfortunately, this will return result from the last `hash`. `LocationZip` in this case.

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [June 26, 2019, 8:50pm UTC](https://discourse.dry-rb.org/t/dry-schema-array-of-hashes-with-one-of-schemas/796/4 "2019-06-26T20:50:44Z")

</div>

@somenugget please report an issue
