Created
December 3, 2019 16:48
-
-
Save hvitorino/834def3eb9cfae10cd1df82e5e32ebed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns transaction-router.routing.interceptors.schema-validation | |
(:require | |
[io.pedestal.interceptor :refer [interceptor]] | |
[route-swagger.doc :as doc] | |
[schema.core :as skm] | |
[humanize.schema :as human])) | |
(defn- explain [schema data] | |
(human/explain (skm/check schema data))) | |
(def validate-schema | |
(interceptor | |
{:name ::validate-schema | |
:enter (fn [ctx] | |
(let [schema (-> ctx :route doc/annotation :parameters :body-params) | |
data (-> ctx :request :body-params) | |
explanation (explain schema data)] | |
(if (nil? explanation) | |
ctx | |
(throw (ex-info "Formato inválido. Verifique as mensagens de erro." {:errors explanation})))))})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment