diff --git a/modules/reitit-core/src/reitit/impl.cljc b/modules/reitit-core/src/reitit/impl.cljc index 34bd12b4..7d3729bb 100644 --- a/modules/reitit-core/src/reitit/impl.cljc +++ b/modules/reitit-core/src/reitit/impl.cljc @@ -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)) diff --git a/test/cljc/reitit/impl_test.cljc b/test/cljc/reitit/impl_test.cljc index 1b2165c5..8a1fb948 100644 --- a/test/cljc/reitit/impl_test.cljc +++ b/test/cljc/reitit/impl_test.cljc @@ -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 + )