feat: support humanize options

This commit is contained in:
ertugrulcetin 2021-01-29 23:18:18 +03:00 committed by Joel Kaasinen
parent 9d88d92241
commit a4576cc622
No known key found for this signature in database

View file

@ -128,7 +128,7 @@
([]
(create nil))
([opts]
(let [{:keys [transformers lite compile options error-keys encode-error] :as opts} (merge default-options opts)
(let [{:keys [transformers lite compile options error-keys encode-error humanize-opts] :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.
@ -188,7 +188,8 @@
(-open-model [_ schema] schema)
(-encode-error [_ error]
(cond-> error
(show? :humanized) (assoc :humanized (me/humanize error {:wrap :message}))
(show? :humanized) (assoc :humanized (me/humanize error (cond-> {:wrap :message}
humanize-opts (merge humanize-opts))))
(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))))