When using schema composition or in a schema along with config.validate_keys = true, the errors for the keys are set considering all the composed schemas.
To Reproduce
require 'dry-schema'
strategy_foo_schema = Dry::Schema.define do
required(:type).filled(:string, eql?: 'foo')
required(:options).hash do
required(:foo).filled(:string)
end
end
strategy_bar_schema = Dry::Schema.define do
required(:type).filled(:string, eql?: 'bar')
required(:options).hash do
required(:bar).filled(:string)
end
end
configuration_schema = Dry::Schema.define do
config.validate_keys = true
required(:strategy).schema(strategy_foo_schema | strategy_bar_schema)
end
input = {
strategy: {
type: 'foo',
options: {
foo: 'foo'
}
}
}
puts configuration_schema.call(input)&.errors&.to_h
# => {:strategy=>{:options=>{:foo=>["is not allowed"]}}}
Expected behavior
I would expect the key validation to only apply to the matching schema of the composed schema.
Describe the bug
When using schema composition
or
in a schema along withconfig.validate_keys = true
, the errors for the keys are set considering all the composed schemas.To Reproduce
Expected behavior
I would expect the key validation to only apply to the matching schema of the composed schema.
My environment