Hi
I am migrating from dry-validation 0.13.0 to 1.6. However I am having problems with validating an email with macro.Here is my code:
AddressSchema = Dry::Schema.Params do
required(:email)
optional(:name)
end
PersonalizationSchema = Dry::Schema.Params do
required(:to).value(:array, min_size?: 1, max_size?: 10).each do
schema(AddressSchema)
end
optional(:me).value(:array, min_size?: 1, max_size?: 10).each do
schema(AddressSchema)
end
optional(:subject)
end
ContentSchema = Dry::Schema.Params do
required(:type).filled(:str?)
required(:value).filled(:str?)
end
And finally my contract:
class MailContract < Prowly::ApplicationContract
PERSONALIZATION_KEYS = %i[to me].freeze
params do
required(:personalizations).value(:array, min_size?: 1, max_size?: 1000).each do
schema(PersonalizationSchema)
end
required(:from).schema(AddressSchema)
required(:content).value(:array, min_size?: 1, max_size?: 2).each do
schema(ContentSchema)
end
end
end
rule(from: :email) do
key([:from, :email]).failure('must be string') unless value.is_a?(String)
key([:from, :email]).failure('must be filled') unless !value.blank?
result = email_validator(value)
key([:from, :email]).failure('is incorrect') unless result
end
end
As you can see I have a heavy-packed rule for personalizations .In fact, the only thing I want is to check email value in each element of to and me which are inside personalizations array. I cannot have:
AddressSchema = Dry::Schema.Params do required(:email).filled(:str?) optional(:name).filled(:str?) end
because If I have an input like this:
{ personalizations: [ ] }