Compare commits

..

1 commit

Author SHA1 Message Date
Daniel Compton
a429067a69
Merge 7a707f042b into e3306e1876 2026-01-26 13:05:55 -05:00
6 changed files with 19 additions and 83 deletions

View file

@ -12,12 +12,6 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino
[breakver]: https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md
## UNRELEASED
* **FIX** redirect-trailing-slash-handler won't make external redirects. [#776](https://github.com/metosin/reitit/pull/776)
* Allow colons in bracket parameter syntax. [#770](https://github.com/metosin/reitit/pull/770)
* Add `url-encode?` option to `match-by-name`. [#778](https://github.com/metosin/reitit/pull/778)
## 0.10.0 (2026-01-09)
* Improve & document how response schemas get picked in per-content-type coercion. See [docs](./doc/ring/coercion.md#per-content-type-coercion). [#745](https://github.com/metosin/reitit/issues/745).

View file

@ -75,17 +75,6 @@ Path-parameters are automatically coerced into strings, with the help of (curren
; :path-params {:id "1"}}
```
In case you want to do something like generate a template path for documentation, you can disable url-encoding:
```clj
(r/match-by-name router ::user {:id "<id goes here>"} {:url-encode? false})
; #reitit.core.Match{:template "/api/user/:id"
; :data {:name :user/user}
; :path "/api/user/<id goes here>"
; :result nil
; :path-params {:id "<id goes here>"}}
```
There is also an exception throwing version:
```clj
@ -108,5 +97,5 @@ It can take an optional map of query-parameters too:
(-> router
(r/match-by-name ::user {:id 1})
(r/match->path {:iso "möly"}))
; "/api/user/1?iso=m%C3%B6ly"
; "/api/user/1?iso=m%C3%B6ly"
```

View file

@ -46,7 +46,7 @@
(options [this])
(route-names [this])
(match-by-path [this path])
(match-by-name [this name] [this name path-params] [this name path-params opts]))
(match-by-name [this name] [this name path-params]))
(defn router? [x]
(satisfies? Router x))
@ -122,11 +122,9 @@
(match-by-name [_ name]
(if-let [match (impl/fast-get lookup name)]
(match nil)))
(match-by-name [r name path-params]
(match-by-name r name path-params nil))
(match-by-name [_ name path-params opts]
(match-by-name [_ name path-params]
(if-let [match (impl/fast-get lookup name)]
(match (impl/path-params path-params opts))))))))
(match (impl/path-params path-params))))))))
(defn lookup-router
"Creates a lookup-router from resolved routes and optional
@ -163,11 +161,9 @@
(match-by-name [_ name]
(if-let [match (impl/fast-get lookup name)]
(match nil)))
(match-by-name [r name path-params]
(match-by-name r name path-params nil))
(match-by-name [_ name path-params opts]
(match-by-name [_ name path-params]
(if-let [match (impl/fast-get lookup name)]
(match (impl/path-params path-params opts))))))))
(match (impl/path-params path-params))))))))
(defn trie-router
"Creates a special prefix-tree router from resolved routes and optional
@ -212,11 +208,9 @@
(match-by-name [_ name]
(if-let [match (impl/fast-get lookup name)]
(match nil)))
(match-by-name [r name path-params]
(match-by-name r name path-params nil))
(match-by-name [_ name path-params opts]
(match-by-name [_ name path-params]
(if-let [match (impl/fast-get lookup name)]
(match (impl/path-params path-params opts))))))))
(match (impl/path-params path-params))))))))
(defn single-static-path-router
"Creates a fast router of 1 static route(s) and optional
@ -244,10 +238,8 @@
(if (#?(:clj .equals :cljs =) p path) match))
(match-by-name [_ name]
(if (= n name) match))
(match-by-name [r name path-params]
(match-by-name r name path-params nil))
(match-by-name [_ name path-params opts]
(if (= n name) (impl/fast-assoc match :path-params (impl/path-params path-params opts))))))))
(match-by-name [_ name path-params]
(if (= n name) (impl/fast-assoc match :path-params (impl/path-params path-params))))))))
(defn mixed-router
"Creates two routers: [[lookup-router]] or [[single-static-path-router]] for
@ -276,11 +268,9 @@
(match-by-name [_ name]
(or (match-by-name static-router name)
(match-by-name wildcard-router name)))
(match-by-name [r name path-params]
(match-by-name r name path-params nil))
(match-by-name [_ name path-params opts]
(or (match-by-name static-router name path-params opts)
(match-by-name wildcard-router name path-params opts)))))))
(match-by-name [_ name path-params]
(or (match-by-name static-router name path-params)
(match-by-name wildcard-router name path-params)))))))
(defn quarantine-router
"Creates two routers: [[mixed-router]] for non-conflicting routes
@ -309,11 +299,9 @@
(match-by-name [_ name]
(or (match-by-name mixed-router name)
(match-by-name linear-router name)))
(match-by-name [r name path-params]
(match-by-name r name path-params nil))
(match-by-name [_ name path-params opts]
(or (match-by-name mixed-router name path-params opts)
(match-by-name linear-router name path-params opts)))))))
(match-by-name [_ name path-params]
(or (match-by-name mixed-router name path-params)
(match-by-name linear-router name path-params)))))))
;;
;; Creating Routers

View file

@ -297,11 +297,8 @@
(defn path-params
"Convert parameters' values into URL-encoded strings, suitable for URL paths"
([params] (path-params params nil))
([params {:keys [url-encode?] :or {url-encode? true}}]
(if url-encode?
(maybe-map-values #(url-encode (into-string %)) params)
(maybe-map-values #(into-string %) params))))
[params]
(maybe-map-values #(url-encode (into-string %)) params))
(defn- query-parameter [k v]
(str (form-encode (into-string k))

View file

@ -33,12 +33,6 @@
:path "/api/ipa/large"
:path-params {:size "large"}})
(r/match-by-name router ::beer {:size "large"})))
(is (= (r/map->Match
{:template "/api/ipa/:size"
:data {:name ::beer}
:path "/api/ipa/:large"
:path-params {:size ":large"}})
(r/match-by-name router ::beer {:size ":large"} {:url-encode? false})))
(is (= (r/map->Match
{:template "/api/ipa/:size"
:data {:name ::beer}

View file

@ -41,33 +41,7 @@
:u #uuid "c2541900-17a7-4353-9024-db8ac258ba4e"
:k :kikka
:qk ::kikka
:nil nil})))
(is (= {:n "1"
:n1 "-1"
:n2 "1"
:n3 "1"
:n4 "1"
:n5 "1"
:d "2.2"
:b "true"
:s "kikka"
:u "c2541900-17a7-4353-9024-db8ac258ba4e"
:k "kikka"
:qk "reitit.impl-test/kikka"
:nil nil}
(impl/path-params {:n 1
:n1 -1
:n2 (long 1)
:n3 (int 1)
:n4 (short 1)
:n5 (byte 1)
:d 2.2
:b true
:s "kikka"
:u #uuid "c2541900-17a7-4353-9024-db8ac258ba4e"
:k :kikka
:qk ::kikka
:nil nil} {:url-encode? false}))))
:nil nil}))))
(deftest query-params-test
(are [x y]