Schema containing sum hash types allow any hash to pass coercion.
To Reproduce
require 'dry-schema'
module Types
include Dry.Types()
end
FooType = Types::Hash.schema(foo: Types::String)
BarType = Types::Hash.schema(bar: Types::String)
FooBarType = FooType | BarType
FooBarSchema = Dry::Schema.Params do
required(:foobar).filled(FooBarType)
end
data = {foobar: {something_wrong: true}}
FooBarSchema.call(data)
# => #<Dry::Schema::Result{:foobar=>{:something_wrong=>true}} errors={} path=[]>
# Type itself works fine
FooBarType[data[:foobar]]
# => `block in resolve_missing_keys': :bar is missing in Hash input (Dry::Types::MissingKeyError)
# Hash schemas without sums also works fine:
FooSchema = Dry::Schema.Params do
required(:foobar).filled(FooType)
end
FooSchema.call(data)
#=> #<Dry::Schema::Result{:foobar=>{}} errors={:foobar=>["must be filled"]} path=[]>
Describe the bug
Schema containing sum hash types allow any hash to pass coercion.
To Reproduce
Expected behavior
Coercion should happen for sum hash types.
My environment
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]