Dynamic schema depending on values

I am currently building payment system and I wonder if there is a way of defining dynamic schema depending on values of other params.

Ideally I’d be looking for sth like:

schema do
  required(:adapter).filled(:string).filled? do |value|
    required(:params).schema(adapter_schemas[value])
  end
end

Just starting with dry-validate, so sorry if I miss anything obvious.

1 Like

I have a similar issue where my required param can have different types arbitrarily.

eg.
value => hash
value => array
value => scalars

Any suggestions I feel it might be something simple I just cant see it.

I ended up using sum (union) types but it doesnt really do the same thing.

I’d probably define multiple contracts and have something decide which one should be used. I’d also use an external schema first to check if the basic requirements of the input are met.

This is basically how I ended up doing this. My transaction first validates base contract, fetches another contract depending on the base contract values, validates again and merges errors. It is not the prettiest code to write - unless there is a way to easily merge two or more validation results into one result?

Why do you need to merge errors?