mirror of
https://github.com/metosin/reitit.git
synced 2025-12-21 18:11:12 +00:00
parent
ad90a2788e
commit
1790f68b24
2 changed files with 39 additions and 2 deletions
|
|
@ -4,7 +4,9 @@
|
|||
[clojure.set :as set]
|
||||
[meta-merge.core :as mm]
|
||||
[reitit.trie :as trie]
|
||||
[reitit.exception :as ex])
|
||||
[reitit.exception :as ex]
|
||||
;; FIXME: Can't be used directly, should be option enabled by malli coercion
|
||||
malli.util)
|
||||
#?(:clj
|
||||
(:import (java.util HashMap Map)
|
||||
(java.net URLEncoder URLDecoder))))
|
||||
|
|
@ -64,7 +66,11 @@
|
|||
(reduce
|
||||
(fn [acc [k v]]
|
||||
(try
|
||||
(mm/meta-merge acc {k v})
|
||||
(case k
|
||||
;; TODO: Make this enabled from malli coercion
|
||||
;; TODO: Schema & spec
|
||||
:parameters (assoc acc :parameters (merge-with malli.util/merge (:parameters acc) v))
|
||||
(mm/meta-merge acc {k v}))
|
||||
(catch #?(:clj Exception, :cljs js/Error) e
|
||||
(ex/fail! ::merge-data {:path p, :left acc, :right {k v}, :exception e}))))
|
||||
{} x))
|
||||
|
|
|
|||
|
|
@ -169,3 +169,34 @@
|
|||
:path-parts ["https://google.com"]
|
||||
:path-params #{}}
|
||||
(impl/parse "https://google.com" nil))))
|
||||
|
||||
(deftest merge-data-test
|
||||
(is (= {:view 'b
|
||||
:controllers [1 2]}
|
||||
(impl/merge-data "/"
|
||||
[[:view 'a]
|
||||
[:controllers [1]]
|
||||
[:view 'b]
|
||||
[:controllers [2]]])))
|
||||
|
||||
(is (= {:view 'b
|
||||
:controllers [2]}
|
||||
(impl/merge-data "/"
|
||||
[[:view 'a]
|
||||
[:controllers [1]]
|
||||
[:view 'b]
|
||||
[:controllers ^:replace [2]]])))
|
||||
|
||||
(is (= [:map
|
||||
[:a 'string?]
|
||||
[:b 'int?]]
|
||||
(-> (impl/merge-data "/"
|
||||
[[:parameters {:path [:map [:a 'string?]]}]
|
||||
[:parameters {:path [:map [:b 'int?]]}]])
|
||||
:parameters
|
||||
:path
|
||||
;; Merge returns schmea object, convert back to form for comparison
|
||||
malli.core/form)))
|
||||
|
||||
;; TODO: Also test and support Schema and spec merging
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue