mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
feat: fold malli :humanize-opts into :options
This commit is contained in:
parent
af7313bd9b
commit
eb06404f1e
2 changed files with 4 additions and 4 deletions
|
|
@ -128,7 +128,7 @@
|
||||||
([]
|
([]
|
||||||
(create nil))
|
(create nil))
|
||||||
([opts]
|
([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))
|
show? (fn [key] (contains? error-keys key))
|
||||||
;; Query-string-coercer needs to construct transfomer without strip-extra-keys so it will
|
;; Query-string-coercer needs to construct transfomer without strip-extra-keys so it will
|
||||||
;; use the transformer-provider directly.
|
;; use the transformer-provider directly.
|
||||||
|
|
@ -189,7 +189,7 @@
|
||||||
(-encode-error [_ error]
|
(-encode-error [_ error]
|
||||||
(cond-> error
|
(cond-> error
|
||||||
(show? :humanized) (assoc :humanized (me/humanize error (cond-> {:wrap :message}
|
(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? :schema) (update :schema edn/write-string opts)
|
||||||
(show? :errors) (-> (me/with-error-messages opts)
|
(show? :errors) (-> (me/with-error-messages opts)
|
||||||
(update :errors (partial map #(update % :schema edn/write-string opts))))
|
(update :errors (partial map #(update % :schema edn/write-string opts))))
|
||||||
|
|
|
||||||
|
|
@ -607,8 +607,8 @@
|
||||||
:body
|
:body
|
||||||
:humanized)))
|
:humanized)))
|
||||||
(is (= {:i ["SHOULD INT"] :x ["MISSING"]}
|
(is (= {:i ["SHOULD INT"] :x ["MISSING"]}
|
||||||
(-> ((->app {:humanize-opts {:errors {:int {:error/message {:en "SHOULD INT"}}
|
(-> ((->app {:options {:errors {:int {:error/message {:en "SHOULD INT"}}
|
||||||
:malli.core/missing-key {:error/message {:en "MISSING"}}}}})
|
:malli.core/missing-key {:error/message {:en "MISSING"}}}}})
|
||||||
(assoc request :body-params {:i "x"}))
|
(assoc request :body-params {:i "x"}))
|
||||||
:body
|
:body
|
||||||
:humanized))))
|
:humanized))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue