mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
Support for sequential child routes
This commit is contained in:
parent
ef7a91697f
commit
bf3007bfe1
4 changed files with 34 additions and 2 deletions
13
CHANGELOG.md
13
CHANGELOG.md
|
|
@ -6,6 +6,19 @@
|
||||||
* should only concern you if you are not using [Muuntaja](https://github.com/metosin/muuntaja).
|
* should only concern you if you are not using [Muuntaja](https://github.com/metosin/muuntaja).
|
||||||
* the `r/routes` returns just the path + data tuples as documented, not the compiled route results. To get the compiled results, use `r/compiled-routes` instead.
|
* the `r/routes` returns just the path + data tuples as documented, not the compiled route results. To get the compiled results, use `r/compiled-routes` instead.
|
||||||
* welcome route name conflict resolution! If router has routes with same names, router can't be created. fix 'em.
|
* welcome route name conflict resolution! If router has routes with same names, router can't be created. fix 'em.
|
||||||
|
* sequential child routes are allowed, enabling this:
|
||||||
|
|
||||||
|
```clj
|
||||||
|
(-> ["/api"
|
||||||
|
(for [i (range 4)]
|
||||||
|
[(str "/" i)])]
|
||||||
|
(r/router)
|
||||||
|
(r/routes))
|
||||||
|
;[["/api/0" {}]
|
||||||
|
; ["/api/1" {}]
|
||||||
|
; ["/api/2" {}]
|
||||||
|
; ["/api/3" {}]]
|
||||||
|
```
|
||||||
|
|
||||||
## `reitit-swagger`
|
## `reitit-swagger`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,10 @@
|
||||||
(walk-many pacc macc routes)
|
(walk-many pacc macc routes)
|
||||||
(when (string? (first routes))
|
(when (string? (first routes))
|
||||||
(let [[path & [maybe-arg :as args]] routes
|
(let [[path & [maybe-arg :as args]] routes
|
||||||
[data childs] (if (or (vector? maybe-arg) (nil? maybe-arg))
|
[data childs] (if (or (vector? maybe-arg)
|
||||||
|
(and (sequential? maybe-arg)
|
||||||
|
(sequential? (first maybe-arg)))
|
||||||
|
(nil? maybe-arg))
|
||||||
[{} args]
|
[{} args]
|
||||||
[maybe-arg (rest args)])
|
[maybe-arg (rest args)])
|
||||||
macc (into macc (expand data opts))
|
macc (into macc (expand data opts))
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
(s/def ::path (s/with-gen string? #(gen/fmap (fn [s] (str "/" s)) (s/gen string?))))
|
(s/def ::path (s/with-gen string? #(gen/fmap (fn [s] (str "/" s)) (s/gen string?))))
|
||||||
|
|
||||||
(s/def ::arg (s/and some? (complement vector?)))
|
(s/def ::arg (s/and some? (complement sequential?)))
|
||||||
(s/def ::data (s/map-of keyword? any?))
|
(s/def ::data (s/map-of keyword? any?))
|
||||||
(s/def ::result any?)
|
(s/def ::result any?)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -268,3 +268,19 @@
|
||||||
(-> router
|
(-> router
|
||||||
(r/match-by-name! ::route {:a "olipa", :b "kerran"})
|
(r/match-by-name! ::route {:a "olipa", :b "kerran"})
|
||||||
(r/match->path {:iso "pöriläinen"}))))))
|
(r/match->path {:iso "pöriläinen"}))))))
|
||||||
|
|
||||||
|
(deftest sequential-routes
|
||||||
|
(testing "sequential child routes work"
|
||||||
|
(is (= [["/api/0" {}]
|
||||||
|
["/api/1" {}]]
|
||||||
|
(-> ["/api"
|
||||||
|
(for [i (range 2)]
|
||||||
|
[(str "/" i)])]
|
||||||
|
(r/router)
|
||||||
|
(r/routes)))))
|
||||||
|
(testing "sequential route definition fails"
|
||||||
|
(is (thrown?
|
||||||
|
#?(:clj Exception, :cljs js/Error)
|
||||||
|
(-> ["/api"
|
||||||
|
(list "/ipa")]
|
||||||
|
(r/router))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue