Custom key in rules dry-1.3.1

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
  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

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?

This error means that you’re trying to define a schema for a contract more than once. Probably caused by loading the same file more than once.

1 Like

Thanks @solnic, apparently the error was because of key fee_params which is not available in parameter list.