diff --git a/README.md b/README.md index ff89d226..84cc2dfd 100644 --- a/README.md +++ b/README.md @@ -609,7 +609,96 @@ The `:gen` -version has 50% less code, is easier to reason about and is 2-4x fas *TODO* -## Validating meta-data +## Validating route-trees + +Namespace `reitit.spec` contains [specs](https://clojure.org/about/spec) for routes, router and router options. + +To enable spec-validation of `router` inputs & outputs at development time, one can do the following: + +```clj +; add to dependencies: +; [expound "0.3.0"] + +(require '[clojure.spec.test.alpha :as st]) +(require '[expound.alpha :as expound]) +(require '[clojure.spec.alpha :as s]) +(require '[reitit.spec]) + +(st/instrument `reitit/router) +(set! s/*explain-out* expound/printer) + +(reitit/router + ["/api" + ["/publuc" + ["/ping"] + ["pong"]]]) +; -- Spec failed -------------------- +; +; ["/api" ...] +; ^^^^^^ +; +; should satisfy +; +; (clojure.spec.alpha/cat +; :path +; :reitit.spec/path +; :arg +; (clojure.spec.alpha/? :reitit.spec/arg) +; :childs +; (clojure.spec.alpha/* (clojure.spec.alpha/and :reitit.spec/raw-route))) +; +; -- Relevant specs ------- +; +; :reitit.spec/raw-route: +; (clojure.spec.alpha/cat +; :path +; :reitit.spec/path +; :arg +; (clojure.spec.alpha/? :reitit.spec/arg) +; :childs +; (clojure.spec.alpha/* (clojure.spec.alpha/and :reitit.spec/raw-route))) +; :reitit.spec/raw-routes: +; (clojure.spec.alpha/or +; :route +; :reitit.spec/raw-route +; :routes +; (clojure.spec.alpha/coll-of :reitit.spec/raw-route :into [])) +; +; -- Spec failed -------------------- +; +; [... [... ... ["pong"]]] +; ^^^^^^ +; +; should satisfy +; +; (fn [%] (clojure.string/starts-with? % "/")) +; +; -- Relevant specs ------- +; +; :reitit.spec/path: +; (clojure.spec.alpha/and +; clojure.core/string? +; (clojure.core/fn [%] (clojure.string/starts-with? % "/"))) +; :reitit.spec/raw-route: +; (clojure.spec.alpha/cat +; :path +; :reitit.spec/path +; :arg +; (clojure.spec.alpha/? :reitit.spec/arg) +; :childs +; (clojure.spec.alpha/* (clojure.spec.alpha/and :reitit.spec/raw-route))) +; :reitit.spec/raw-routes: +; (clojure.spec.alpha/or +; :route +; :reitit.spec/raw-route +; :routes +; (clojure.spec.alpha/coll-of :reitit.spec/raw-route :into [])) +; +; ------------------------- +; Detected 2 errors +``` + +### Validating meta-data *TODO* diff --git a/project.clj b/project.clj index f843d35e..378b9e39 100644 --- a/project.clj +++ b/project.clj @@ -26,7 +26,7 @@ [metosin/spec-tools "0.3.3"] [org.clojure/spec.alpha "0.1.123"] - [expound "0.2.1"] + [expound "0.3.0"] [orchestra "2017.08.13"] [criterium "0.4.4"] diff --git a/src/reitit/coercion.cljc b/src/reitit/coercion.cljc index 4879f50a..ea404b27 100644 --- a/src/reitit/coercion.cljc +++ b/src/reitit/coercion.cljc @@ -194,4 +194,3 @@ (coerce-response coercers request (handler request))) ([request respond raise] (handler request #(respond (coerce-response coercers request %)) raise)))))))})) -