feat: fold malli :humanize-opts into :options

This commit is contained in:
Joel Kaasinen 2025-11-14 14:06:43 +02:00
parent af7313bd9b
commit eb06404f1e
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View file

@ -128,7 +128,7 @@
([]
(create nil))
([opts]
(let [{:keys [transformers lite compile options error-keys encode-error humanize-opts] :as opts} (merge default-options opts)
(let [{:keys [transformers lite compile options error-keys encode-error] :as opts} (merge default-options opts)
show? (fn [key] (contains? error-keys key))
;; Query-string-coercer needs to construct transfomer without strip-extra-keys so it will
;; use the transformer-provider directly.
@ -189,7 +189,7 @@
(-encode-error [_ error]
(cond-> error
(show? :humanized) (assoc :humanized (me/humanize error (cond-> {:wrap :message}
humanize-opts (merge humanize-opts))))
options (merge options))))
(show? :schema) (update :schema edn/write-string opts)
(show? :errors) (-> (me/with-error-messages opts)
(update :errors (partial map #(update % :schema edn/write-string opts))))

View file

@ -607,8 +607,8 @@
:body
:humanized)))
(is (= {:i ["SHOULD INT"] :x ["MISSING"]}
(-> ((->app {:humanize-opts {:errors {:int {:error/message {:en "SHOULD INT"}}
:malli.core/missing-key {:error/message {:en "MISSING"}}}}})
(-> ((->app {:options {:errors {:int {:error/message {:en "SHOULD INT"}}
:malli.core/missing-key {:error/message {:en "MISSING"}}}}})
(assoc request :body-params {:i "x"}))
:body
:humanized))))