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

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?

This should work:

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

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

@somenugget please report an issue