metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 204 forks source link

Custom validation functions: Allow programmatically defining `:error/path` #975

Open mkreis opened 7 months ago

mkreis commented 7 months ago

Open this feature request as discussed here: https://clojurians.slack.com/archives/CLDK6MFMK/p1701249325700779

It would be great if it was possible to programmatically define :error/path depending on the validation function (and the data to be validated).

In below example from the docs :error/path only accept vectors is hard-coded to [:password2]:

(-> [:and [:map
           [:password string?]
           [:password2 string?]]
     [:fn {:error/message "passwords don't match"
           :error/path [:password2]}
       (fn [{:keys [password password2]}]
         (= password password2))]]
    (m/explain {:password "secret"
                :password2 "faarao"})
    (me/humanize))
; {:password2 ["passwords don't match"]}