use fn? instead of fspec with router options

fspec fails for some reason.
related? http://github.com/walmartlabs/lacinia/pull/112
This commit is contained in:
Tommi Reiman 2017-09-03 14:55:58 +03:00
parent 7d4db18000
commit b4855699b5
3 changed files with 45 additions and 39 deletions

View file

@ -30,7 +30,7 @@
(expand [_ _])) (expand [_ _]))
(defn walk [data {:keys [path meta routes expand] (defn walk [data {:keys [path meta routes expand]
:or {path "", meta [], routes [], expand expand} :or {meta [], routes [], expand expand}
:as opts}] :as opts}]
(letfn (letfn
[(walk-many [p m r] [(walk-many [p m r]
@ -245,7 +245,7 @@
| key | description | | key | description |
| -------------|-------------| | -------------|-------------|
| `:path` | Base-path for routes (default `\"\"`) | `:path` | Base-path for routes
| `:routes` | Initial resolved routes (default `[]`) | `:routes` | Initial resolved routes (default `[]`)
| `:meta` | Initial route meta (default `{}`) | `:meta` | Initial route meta (default `{}`)
| `:expand` | Function of `arg opts => meta` to expand route arg to route meta-data (default `reitit.core/expand`) | `:expand` | Function of `arg opts => meta` to expand route arg to route meta-data (default `reitit.core/expand`)

View file

@ -38,42 +38,41 @@
(s/def ::router reitit/router?) (s/def ::router reitit/router?)
(s/def :reitit.router/path (s/or :empty #{""} :path ::path)) (s/def :reitit.router/path ::path)
(s/def :reitit.router/routes ::routes) (s/def :reitit.router/routes ::routes)
(s/def :reitit.router/meta ::meta) (s/def :reitit.router/meta ::meta)
(s/def :reitit.router/expand (s/def :reitit.router/expand fn?
(s/fspec :args (s/cat :arg ::arg, :opts ::opts) #_(s/fspec :args (s/cat :arg ::arg, :opts ::opts)
:ret ::route)) :ret ::route))
(s/def :reitit.router/coerce (s/def :reitit.router/coerce fn?
(s/fspec :args (s/cat :route (s/spec ::route), :opts ::opts) #_(s/fspec :args (s/cat :route (s/spec ::route), :opts ::opts)
:ret ::route)) :ret ::route))
(s/def :reitit.router/compile (s/def :reitit.router/compile fn?
(s/fspec :args (s/cat :route (s/spec ::route), :opts ::opts) #_(s/fspec :args (s/cat :route (s/spec ::route), :opts ::opts)
:ret ::result)) :ret ::result))
(s/def :reitit.router/conflicts (s/def :reitit.router/conflicts fn?
(s/fspec :args (s/cat :conflicts (s/map-of ::route (s/coll-of ::route :into #{}))))) #_(s/fspec :args (s/cat :conflicts (s/map-of ::route (s/coll-of ::route :into #{})))))
(s/def :reitit.router/router (s/def :reitit.router/router fn?
(s/fspec :args (s/cat :routes ::routes, :opts ::opts) #_(s/fspec :args (s/cat :routes ::routes, :opts ::opts)
:ret ::router)) :ret ::router))
;; TODO: fspecs fail..
(s/def ::opts (s/def ::opts
(s/nilable (s/nilable
(s/keys :opt-un [:reitit.router/path (s/keys :opt-un [:reitit.router/path
:reitit.router/routes :reitit.router/routes
:reitit.router/meta :reitit.router/meta
#_:reitit.router/expand :reitit.router/expand
#_:reitit.router/coerce :reitit.router/coerce
#_:reitit.router/compile :reitit.router/compile
#_:reitit.router/conflicts :reitit.router/conflicts
#_:reitit.router/router]))) :reitit.router/router])))
(s/fdef reitit/router (s/fdef reitit/router
:args (s/or :1arity (s/cat :data (s/spec ::raw-routes)) :args (s/or :1arity (s/cat :data (s/spec ::raw-routes))

View file

@ -50,12 +50,12 @@
(is (= true (reitit/router? (reitit/router ["/api"] opts)))) (is (= true (reitit/router? (reitit/router ["/api"] opts))))
{:path "/"} {:path "/"}
{:meta {}} {:meta {}}
{:expand (fn [_ _] {})}
#_{:coerce (fn [_ _] ["/"])} {:coerce (fn [route _] route)}
) {:compile (fn [_ _])}
{:conflicts (fn [_])}
{:router reitit/linear-router})
(are [opts] (are [opts]
(is (thrown-with-msg? (is (thrown-with-msg?
@ -64,4 +64,11 @@
(reitit/router (reitit/router
["/api"] opts))) ["/api"] opts)))
{:meta 1})))) {:path ""}
{:path nil}
{:meta nil}
{:expand nil}
{:coerce nil}
{:compile nil}
{:conflicts nil}
{:router nil}))))