mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
Merge pull request #760 from metosin/fix/758-match-by-name-bang-nil
fix: match-by-name! should throw when match-by-name is PartialMatch
This commit is contained in:
commit
abe95bfc17
2 changed files with 11 additions and 6 deletions
|
|
@ -198,9 +198,8 @@
|
|||
(:path route)))
|
||||
|
||||
(defn throw-on-missing-path-params [template required path-params]
|
||||
(when-not (every? #(contains? path-params %) required)
|
||||
(let [defined (-> path-params keys set)
|
||||
missing (set/difference required defined)]
|
||||
(let [missing (set (remove #(get path-params %) required))]
|
||||
(when-not (empty? missing)
|
||||
(ex/fail!
|
||||
(str "missing path-params for route " template " -> " missing)
|
||||
{:path-params path-params, :required required}))))
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@
|
|||
|
||||
(testing "routers handling wildcard paths"
|
||||
(are [r name]
|
||||
(testing "wild"
|
||||
|
||||
(testing (str name)
|
||||
(testing "simple"
|
||||
(let [router (r/router ["/api" ["/ipa" ["/:size" ::beer]]] {:router r})]
|
||||
(is (= name (r/router-name router)))
|
||||
|
|
@ -52,10 +51,17 @@
|
|||
:path-params nil})
|
||||
(r/match-by-name router ::beer)))
|
||||
(is (r/partial-match? (r/match-by-name router ::beer)))
|
||||
(is (r/partial-match? (r/match-by-name router ::beer {:size nil}))
|
||||
"nil counts as missing")
|
||||
(is (thrown-with-msg?
|
||||
ExceptionInfo
|
||||
#"^missing path-params for route /api/ipa/:size -> \#\{:size\}$"
|
||||
(r/match-by-name! router ::beer))))))
|
||||
(r/match-by-name! router ::beer)))
|
||||
(is (thrown-with-msg?
|
||||
ExceptionInfo
|
||||
#"^missing path-params for route /api/ipa/:size -> \#\{:size\}$"
|
||||
(r/match-by-name! router ::beer {:size nil}))
|
||||
"nil counts as missing"))))
|
||||
|
||||
(testing "decode %-encoded path params"
|
||||
(let [router (r/router [["/one-param-path/:param1" ::one]
|
||||
|
|
|
|||
Loading…
Reference in a new issue