Next-gen ruby libs! » github.com/dry-rb » website: https://dry-rb.org » forum: https://discourse.dry-rb.org
JSON
or Form
. Consider this:Schema = Dry::Validation.Schema do
configure { config.type_specs = true }
required(:first_name, :string).filled(:str?)
end
OtherSchema = Dry::Validation.Schema(Schema) do
required(:last_name, :string).filled(:str?)
end
input = { first_name: 'John', last_name: 'Smith' }
Schema.(input).success? => true
Schema.(input).output => {:first_name=>"John", :last_name=>"Smith"}
OtherSchema.(input).success? => true
OtherSchema.(input).output => {:first_name=>"John", :last_name=>"Smith"}
Schema = Dry::Validation.JSON do
configure { config.type_specs = true }
required(:first_name, :string).filled(:str?)
end
OtherSchema = Dry::Validation.Schema(Schema) do
required(:last_name, :string).filled(:str?)
end
input = { 'first_name' => 'Joe', 'last_name' => 'Smith' }
Schema.(input).success? => true
Schema.(input).output => {:first_name=>"Joe"}
OtherSchema.(input).success? => false
OtherSchema.(input).errors => {:first_name=>["is missing"]}
OtherSchema
to recognize first_name
. Inheritance works as I would expect with the normal schema. It's not a problem with the JSON
macro either, as this would yield the same issues:Schema = Dry::Validation.Schema do
configure do
config.type_specs = true
config.input_processor = :json
config.hash_type = :symbolized
end
required(:first_name, :string).filled(:str?)
end
OtherSchema = Dry::Validation.Schema(Schema) do
required(:last_name, :string).filled(:str?)
end
OtherSchema = Dry::Validation.Schema(Schema) do
configure do
config.type_specs = true
config.input_processor = :json
config.hash_type = :symbolized
end
required(:last_name, :string).filled(:str?)
end
input_processor
is clearly the culprit when messing around with scenarios.
One more thing to add, it isn't just the input_preprocessor
but rather a combination of that and type_specs
set to true
. Looking at OtherSchema
I see that:
OtherSchema.config[:type_map] => {:last_name=>#<Dry::Types::Definition primitive=String options={} meta={}>}
Not that first_name
is not in the type_map
. I haven't done a deep dive into the code yet, but if anyone familiar with the finer points can give me any pointers (or just flat out tell me if this is a bug and, if so, I'll work to patch it) that would be really handy.
Looks like the bug has actually been patched: https://github.com/dry-rb/dry-validation/pull/359/commits/71872da3985c54b6930ed39c42d004f837e9812f
This fixes the behavior. Is there something wrong with this PR?