I have to validate two attributes which are in parameter list and raise error with custom error key and I am currently doing something like this:
class Create < Dry::Validation::Contract params do optional(:fee_account).value(:str?) optional(:fee_recipient_name).value(:str?) end rule(:fee_params) do account, name = values[:fee_account], values[:fee_recipient_name] key.failure("internal fee params must all be filled or left blank") unless account || name ? [account, name].all? : false end end
But it says,
Dry::Validation::DuplicateSchemaError with message:
Schema has already been defined,
What will be the best way to do validations where I can generate the error with custom error key and do validation using two or more than two attributes already processed in contract’s schema?