diff --git a/test/cljc/reitit/coercion_test.cljc b/test/cljc/reitit/coercion_test.cljc index d752de0c..b4c5e5a5 100644 --- a/test/cljc/reitit/coercion_test.cljc +++ b/test/cljc/reitit/coercion_test.cljc @@ -54,3 +54,17 @@ (is (= nil (coercion/coerce! m)))) (let [m (r/match-by-path r "/none/kikka/abba")] (is (= nil (coercion/coerce! m)))))))) + +(defn match-by-path-and-coerce! [router path] + (if-let [match (r/match-by-path router path)] + (assoc match :parameters (coercion/coerce! match)))) + +(deftest data-spec-example-test + (let [router (r/router + ["/:company/users/:user-id" {:name ::user-view + :coercion reitit.coercion.spec/coercion + :parameters {:path {:company string? + :user-id int?}}}] + {:compile coercion/compile-request-coercers})] + (is (= {:path {:user-id 123, :company "metosin"}} + (:parameters (match-by-path-and-coerce! router "/metosin/users/123")))))) diff --git a/test/cljc/reitit/ring_coercion_test.cljc b/test/cljc/reitit/ring_coercion_test.cljc index 82fc5a04..3bc7b4bc 100644 --- a/test/cljc/reitit/ring_coercion_test.cljc +++ b/test/cljc/reitit/ring_coercion_test.cljc @@ -1,6 +1,7 @@ (ns reitit.ring-coercion-test (:require [clojure.test :refer [deftest testing is]] [schema.core :as s] + [spec-tools.data-spec :as ds] [reitit.ring :as ring] [reitit.ring.coercion :as rrc] [reitit.coercion.spec :as spec] @@ -48,7 +49,7 @@ (ring/router ["/api" ["/plus/:e" - {:get {:parameters {:query {:a int?} + {:get {:parameters {:query {(ds/opt :a) int?} :body {:b int?} :form {:c int?} :header {:d int?}