# Validate array items against multiple possible schemas

**URL:** <https://discourse.dry-rb.org/t/validate-array-items-against-multiple-possible-schemas/165>\
**Category:** dry-validation\
**Created:** [November 25, 2016, 11:13am UTC](https://discourse.dry-rb.org/t/validate-array-items-against-multiple-possible-schemas/165 "2016-11-25T11:13:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagse](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/jagse/32/67_2.png) [@jagse](https://discourse.dry-rb.org/u/jagse)\
**Post date:** [November 25, 2016, 11:13am UTC](https://discourse.dry-rb.org/t/validate-array-items-against-multiple-possible-schemas/165/1 "2016-11-25T11:13:12Z")

</div>

Hey guys, should the following not be possible? What do I do wrong?

```
type_a = Dry::Validation.JSON do
  required(:type).filled(format?: /\AA\z/)
end

type_b = Dry::Validation.JSON do
  required(:type).filled(format?: /\AB\z/) 
end

schema = Dry::Validation.JSON do
  required(:data).each { schema(type_a) | schema(type_b) }
end

input = {
  data: [
    { type: 'A' },
    { type: 'B' },
    { type: 'C' }
  ]
}

schema.call(input).errors
NoMethodError: undefined method `path' for #<Array:0x00000001eecd60>

```

Seems like an array is being passed to the message class

```
dry-validation-0.10.3/lib/dry/validation/message.rb:24:in `initialize'

```

And it tries to call path on the array. Of course this only happens in the case when the input is invalid.

---

<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:** [November 26, 2016, 11:01am UTC](https://discourse.dry-rb.org/t/validate-array-items-against-multiple-possible-schemas/165/2 "2016-11-26T11:01:35Z")

</div>

Please report an issue. This is not yet supported but I plan to make it work before 1.0.0.

---

<div class="post-metadata">

**Author:** ![tomasc](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/tomasc/32/622_2.png) [@tomasc](https://discourse.dry-rb.org/u/tomasc)\
**Post date:** [March 15, 2021, 3:58pm UTC](https://discourse.dry-rb.org/t/validate-array-items-against-multiple-possible-schemas/165/3 "2021-03-15T15:58:45Z")

</div>

I am trying to validate on members of array with different types, and upon searching this forum I found this answer.

Implementing similar solution, I am getting:

undefined method `to\_or’ for #Array:…

Is there already a working convention how to validate array with multiple possible schemas?

Thank you,  
Tomas
