diff --git a/modules/reitit-ring/src/reitit/ring/coercion.cljc b/modules/reitit-ring/src/reitit/ring/coercion.cljc index 295ba4de..40820699 100644 --- a/modules/reitit-ring/src/reitit/ring/coercion.cljc +++ b/modules/reitit-ring/src/reitit/ring/coercion.cljc @@ -160,7 +160,7 @@ (handler request #(respond (coerce-response coercers request %)) raise)))))))})) (def gen-wrap-coerce-exceptions - "Middleare for coercion exception handling. + "Middleware for handling coercion exceptions. Expects a :coercion of type `reitit.coercion.protocol/Coercion` and :parameters or :responses from route data, otherwise does not mount." (middleware/create @@ -176,6 +176,6 @@ (handle-coercion-exception e identity #(throw %))))) ([request respond raise] (try - (handler request respond (fn [e] (handle-coercion-exception e respond raise))) + (handler request respond #(handle-coercion-exception % respond raise)) (catch #?(:clj Exception :cljs js/Error) e (handle-coercion-exception e respond raise))))))))})) diff --git a/modules/reitit-schema/src/reitit/ring/coercion/schema.cljc b/modules/reitit-schema/src/reitit/ring/coercion/schema.cljc index 7733d574..5029f6ba 100644 --- a/modules/reitit-schema/src/reitit/ring/coercion/schema.cljc +++ b/modules/reitit-schema/src/reitit/ring/coercion/schema.cljc @@ -6,9 +6,7 @@ [schema-tools.coerce :as stc] [spec-tools.swagger.core :as swagger] [clojure.walk :as walk] - [reitit.ring.coercion.protocol :as protocol]) - (:import (schema.core OptionalKey RequiredKey) - (schema.utils ValidationError NamedError))) + [reitit.ring.coercion.protocol :as protocol])) (def string-coercion-matcher stc/string-coercion-matcher) @@ -26,12 +24,12 @@ (walk/prewalk (fn [x] (cond - (class? x) (.getName ^Class x) - (instance? OptionalKey x) (pr-str (list 'opt (:k x))) - (instance? RequiredKey x) (pr-str (list 'req (:k x))) - (and (satisfies? s/Schema x) (record? x)) (try (pr-str (s/explain x)) (catch Exception _ x)) - (instance? ValidationError x) (str (su/validation-error-explain x)) - (instance? NamedError x) (str (su/named-error-explain x)) + #?@(:clj [(class? x) (.getName ^Class x)]) + (instance? schema.core.OptionalKey x) (pr-str (list 'opt (:k x))) + (instance? schema.core.RequiredKey x) (pr-str (list 'req (:k x))) + (and (satisfies? s/Schema x) (record? x)) (try (pr-str (s/explain x)) (catch #?(:clj Exception :cljs js/Error) _ x)) + (instance? schema.utils.ValidationError x) (str (su/validation-error-explain x)) + (instance? schema.utils.NamedError x) (str (su/named-error-explain x)) :else x)) schema)) @@ -45,12 +43,8 @@ (get-apidocs [_ _ {:keys [parameters responses] :as info}] (cond-> (dissoc info :parameters :responses) - parameters (assoc - ::swagger/parameters - parameters) - responses (assoc - ::swagger/responses - responses))) + parameters (assoc ::swagger/parameters parameters) + responses (assoc ::swagger/responses responses))) (make-open [_ schema] (st/open-schema schema)) diff --git a/modules/reitit-spec/src/reitit/ring/coercion/spec.cljc b/modules/reitit-spec/src/reitit/ring/coercion/spec.cljc index edf96ce2..cd2aba4f 100644 --- a/modules/reitit-spec/src/reitit/ring/coercion/spec.cljc +++ b/modules/reitit-spec/src/reitit/ring/coercion/spec.cljc @@ -51,9 +51,7 @@ (memoize #(into-spec %1 (gensym "spec")))) (defn stringify-pred [pred] - (str (if (instance? clojure.lang.LazySeq pred) - (seq pred) - pred))) + (str (if (seq? pred) (seq pred) pred))) (defmulti coerce-response? identity :default ::default) (defmethod coerce-response? ::default [_] true) diff --git a/test/cljc/reitit/coercion_test.cljc b/test/cljc/reitit/coercion_test.cljc index a9b8a62f..c9d5ec71 100644 --- a/test/cljc/reitit/coercion_test.cljc +++ b/test/cljc/reitit/coercion_test.cljc @@ -1,9 +1,9 @@ (ns reitit.coercion-test (:require [clojure.test :refer [deftest testing is]] + [schema.core :as s] [reitit.ring :as ring] [reitit.ring.coercion :as coercion] [reitit.ring.coercion.spec :as spec] - [schema.core :as s] [reitit.ring.coercion.schema :as schema]) #?(:clj (:import (clojure.lang ExceptionInfo))))