bouncer
bouncer copied to clipboard
:pre functions do not get nested values
When nesting validation sets, functions supplied as :pre get the entire data structure passed to b/validate, not just the nested structure that they would normally get. This basically breaks their functionality.
Here's a more descriptive example:
(def billing-data
{:country v/required
:eu-vat-number [[v/required
:pre (comp countries/eu-country-codes :country)
:message "is required for EU countries"]]})
(def signup-data
{:currency v/required
:billing-data billing-data
:account-data account-data
;; [...]
})
In this example, :eu-vat-number validation will work if a billing-data map is being validated, but will not work as expected if signup-data is validated. The :pre function will get the entire signup-data map, which does not contain a :country key, therefore the :eu-vat-number validation will never run.