-
-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent behavior in nested schemas via passed in blocks #703
Comments
Does it work when you do |
No 😞 -- replacing all |
OK thanks, clearly a bug. Thanks for reporting. |
👍 |
Same issue, I tried some iterations over the same error: https://github.com/marcocarvalho/dry-validation-playground |
Schema = Dry::Schema.JSON do
optional(:external_id).value(:string, max_size?: 64)
optional(:first_name).value(:string, max_size?: 255)
optional(:last_name).value(:string, max_size?: 255)
optional(:type).value(:string, max_size?: 32)
optional(:birthdate).value(:string, format?: /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])\Z/)
end
OnlyCommonFieldsSchema = Dry::Schema.JSON do
optional(:last_name).value(:string, max_size?: 255)
optional(:type).value(:string, max_size?: 32)
optional(:birthdate).value(:string, format?: /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])\Z/)
end
class Contract < Dry::Validation::Contract
json do
required(:person).hash do
required(:external_id).value(:string, max_size?: 64)
required(:first_name).value(:string, max_size?: 255)
optional(:last_name).value(:string, max_size?: 255)
optional(:type).value(:string, max_size?: 32)
optional(:birthdate).value(:string, format?: /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])\Z/)
end
end
end
class CommonFieldsContract < Dry::Validation::Contract
json do
required(:person).hash(OnlyCommonFieldsSchema) do
required(:external_id).value(:string, max_size?: 64)
required(:first_name).value(:string, max_size?: 255)
end
end
end
class InheritSchemaContract < Dry::Validation::Contract
json do
required(:person).hash(Schema) do
required(:external_id).value(:string, max_size?: 64)
required(:first_name).value(:string, max_size?: 255)
end
end
end
params = {
person: {
last_name: "x"*256,
type: "u"*33,
birthdate: "invalid"
}
}
puts InheritSchemaContract.new.call(params).errors.inspect
puts CommonFieldsContract.new.call(params).errors.inspect
puts Contract.new.call(params).inspect
|
@solnic, this breaks the reusability of schemas. Any chance this could be worked on? |
Describe the bug
When schemas are passed blocks,
required
field behavior does not always work, and there is inconsistent behavior for reaching validation rules -- although it seems to correlate with whether therequired
is evaluated.To Reproduce
Expected behavior
I would expect every one of the above results to contain
{:recommended_tire=>{:size=>["is missing"]}
, and I would either expect all of them to make it to the rule or none of them to make it to the rule.My environment
The text was updated successfully, but these errors were encountered: