rename and make set-validation-error utility function public

This commit is contained in:
Gered 2015-02-14 18:12:03 -05:00
parent bc9e2a8912
commit 4eab47cbdd

View file

@ -116,7 +116,9 @@
(assoc-in request [:safe-params :body] (:body request)) (assoc-in request [:safe-params :body] (:body request))
(update-in request [:safe-params] merge (:body request)))) (update-in request [:safe-params] merge (:body request))))
(defn- assoc-validation-error [request param] (defn set-validation-error
"Adds a parameter to the list of validation errors."
[request param]
(update-in (update-in
request request
[:validation-errors] [:validation-errors]
@ -133,7 +135,7 @@
(let [k (if (sequential? param) (concat [parent] param) [parent param])] (let [k (if (sequential? param) (concat [parent] param) [parent param])]
(if (f (get-in request k)) (if (f (get-in request k))
(safe request parent [param]) (safe request parent [param])
(assoc-validation-error request param))))) (set-validation-error request param)))))
(defn validate-schema (defn validate-schema
"Validates the specified parameter by checking it against the given schema. "Validates the specified parameter by checking it against the given schema.
@ -144,7 +146,7 @@
(let [k (if (sequential? param) (concat [parent] param) [parent param])] (let [k (if (sequential? param) (concat [parent] param) [parent param])]
(if (nil? (s/check schema (get-in request k))) (if (nil? (s/check schema (get-in request k)))
(safe request parent [param]) (safe request parent [param])
(assoc-validation-error request param))))) (set-validation-error request param)))))
(defn validate-body (defn validate-body
"Validates the request body using function f which gets passed the body of "Validates the request body using function f which gets passed the body of
@ -153,7 +155,7 @@
[request f & [copy-into-params?]] [request f & [copy-into-params?]]
(if (f (:body request)) (if (f (:body request))
(safe-body request copy-into-params?) (safe-body request copy-into-params?)
(assoc-validation-error request :body))) (set-validation-error request :body)))
(defn validate-body-schema (defn validate-body-schema
"Validates the request body by checking it against the given schema. If it "Validates the request body by checking it against the given schema. If it
@ -162,7 +164,7 @@
[request schema & [copy-into-params?]] [request schema & [copy-into-params?]]
(if (nil? (s/check schema (:body request))) (if (nil? (s/check schema (:body request)))
(safe-body request copy-into-params?) (safe-body request copy-into-params?)
(assoc-validation-error request :body))) (set-validation-error request :body)))
(defn transform (defn transform
"Transforms the specified parameter using function f which gets passed the value "Transforms the specified parameter using function f which gets passed the value