mirror of
https://github.com/metosin/reitit.git
synced 2025-12-21 01:51:11 +00:00
Merge pull request #13 from metosin/RouteCoercion
Route coercion, fixes #4
This commit is contained in:
commit
defa0eac73
2 changed files with 25 additions and 2 deletions
|
|
@ -55,8 +55,11 @@
|
|||
(meta-merge acc {k v}))
|
||||
{} x))
|
||||
|
||||
(defn resolve-routes [data opts]
|
||||
(->> (walk data opts) (map-meta merge-meta)))
|
||||
(defn resolve-routes [data {:keys [coerce] :or {coerce identity} :as opts}]
|
||||
(->> (walk data opts)
|
||||
(map-meta merge-meta)
|
||||
(mapv (partial coerce))
|
||||
(filterv identity)))
|
||||
|
||||
(defprotocol Routing
|
||||
(routes [this])
|
||||
|
|
|
|||
|
|
@ -55,6 +55,26 @@
|
|||
(reitit/resolve-routes
|
||||
["/api/:version/ping"] {})))))))
|
||||
|
||||
(testing "route coercion"
|
||||
(let [coerce (fn [[path meta]]
|
||||
(if-not (:invalid? meta)
|
||||
[path (assoc meta :path path)]))
|
||||
router (reitit/router
|
||||
["/api" {:roles #{:admin}}
|
||||
["/ping" ::ping]
|
||||
["/pong" ::pong]
|
||||
["/hidden" {:invalid? true}
|
||||
["/utter"]
|
||||
["/crap"]]]
|
||||
{:coerce coerce})]
|
||||
(is (= [["/api/ping" {:name ::ping
|
||||
:path "/api/ping",
|
||||
:roles #{:admin}}]
|
||||
["/api/pong" {:name ::pong
|
||||
:path "/api/pong",
|
||||
:roles #{:admin}}]]
|
||||
(reitit/routes router)))))
|
||||
|
||||
(testing "bide sample"
|
||||
(let [routes [["/auth/login" :auth/login]
|
||||
["/auth/recovery/token/:token" :auth/recovery]
|
||||
|
|
|
|||
Loading…
Reference in a new issue