mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
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:
parent
7d4db18000
commit
b4855699b5
3 changed files with 45 additions and 39 deletions
|
|
@ -30,7 +30,7 @@
|
|||
(expand [_ _]))
|
||||
|
||||
(defn walk [data {:keys [path meta routes expand]
|
||||
:or {path "", meta [], routes [], expand expand}
|
||||
:or {meta [], routes [], expand expand}
|
||||
:as opts}]
|
||||
(letfn
|
||||
[(walk-many [p m r]
|
||||
|
|
@ -245,7 +245,7 @@
|
|||
|
||||
| key | description |
|
||||
| -------------|-------------|
|
||||
| `:path` | Base-path for routes (default `\"\"`)
|
||||
| `:path` | Base-path for routes
|
||||
| `:routes` | Initial resolved routes (default `[]`)
|
||||
| `:meta` | Initial route meta (default `{}`)
|
||||
| `:expand` | Function of `arg opts => meta` to expand route arg to route meta-data (default `reitit.core/expand`)
|
||||
|
|
|
|||
|
|
@ -38,42 +38,41 @@
|
|||
|
||||
(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/meta ::meta)
|
||||
|
||||
(s/def :reitit.router/expand
|
||||
(s/fspec :args (s/cat :arg ::arg, :opts ::opts)
|
||||
(s/def :reitit.router/expand fn?
|
||||
#_(s/fspec :args (s/cat :arg ::arg, :opts ::opts)
|
||||
:ret ::route))
|
||||
|
||||
(s/def :reitit.router/coerce
|
||||
(s/fspec :args (s/cat :route (s/spec ::route), :opts ::opts)
|
||||
(s/def :reitit.router/coerce fn?
|
||||
#_(s/fspec :args (s/cat :route (s/spec ::route), :opts ::opts)
|
||||
:ret ::route))
|
||||
|
||||
(s/def :reitit.router/compile
|
||||
(s/fspec :args (s/cat :route (s/spec ::route), :opts ::opts)
|
||||
(s/def :reitit.router/compile fn?
|
||||
#_(s/fspec :args (s/cat :route (s/spec ::route), :opts ::opts)
|
||||
:ret ::result))
|
||||
|
||||
(s/def :reitit.router/conflicts
|
||||
(s/fspec :args (s/cat :conflicts (s/map-of ::route (s/coll-of ::route :into #{})))))
|
||||
(s/def :reitit.router/conflicts fn?
|
||||
#_(s/fspec :args (s/cat :conflicts (s/map-of ::route (s/coll-of ::route :into #{})))))
|
||||
|
||||
(s/def :reitit.router/router
|
||||
(s/fspec :args (s/cat :routes ::routes, :opts ::opts)
|
||||
(s/def :reitit.router/router fn?
|
||||
#_(s/fspec :args (s/cat :routes ::routes, :opts ::opts)
|
||||
:ret ::router))
|
||||
|
||||
;; TODO: fspecs fail..
|
||||
(s/def ::opts
|
||||
(s/nilable
|
||||
(s/keys :opt-un [:reitit.router/path
|
||||
:reitit.router/routes
|
||||
:reitit.router/meta
|
||||
#_:reitit.router/expand
|
||||
#_:reitit.router/coerce
|
||||
#_:reitit.router/compile
|
||||
#_:reitit.router/conflicts
|
||||
#_:reitit.router/router])))
|
||||
:reitit.router/expand
|
||||
:reitit.router/coerce
|
||||
:reitit.router/compile
|
||||
:reitit.router/conflicts
|
||||
:reitit.router/router])))
|
||||
|
||||
(s/fdef reitit/router
|
||||
:args (s/or :1arity (s/cat :data (s/spec ::raw-routes))
|
||||
|
|
|
|||
|
|
@ -50,12 +50,12 @@
|
|||
(is (= true (reitit/router? (reitit/router ["/api"] opts))))
|
||||
|
||||
{:path "/"}
|
||||
|
||||
{:meta {}}
|
||||
|
||||
#_{:coerce (fn [_ _] ["/"])}
|
||||
)
|
||||
|
||||
{:expand (fn [_ _] {})}
|
||||
{:coerce (fn [route _] route)}
|
||||
{:compile (fn [_ _])}
|
||||
{:conflicts (fn [_])}
|
||||
{:router reitit/linear-router})
|
||||
|
||||
(are [opts]
|
||||
(is (thrown-with-msg?
|
||||
|
|
@ -64,4 +64,11 @@
|
|||
(reitit/router
|
||||
["/api"] opts)))
|
||||
|
||||
{:meta 1}))))
|
||||
{:path ""}
|
||||
{:path nil}
|
||||
{:meta nil}
|
||||
{:expand nil}
|
||||
{:coerce nil}
|
||||
{:compile nil}
|
||||
{:conflicts nil}
|
||||
{:router nil}))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue