diff --git a/doc/advanced/configuring_routers.md b/doc/advanced/configuring_routers.md index 35601c94..3bd4a982 100644 --- a/doc/advanced/configuring_routers.md +++ b/doc/advanced/configuring_routers.md @@ -2,18 +2,18 @@ Routers can be configured via options. The following options are available for the `reitit.core/router`: -| key | description -|--------------|------------- -| `:path` | Base-path for routes -| `:routes` | Initial resolved routes (default `[]`) -| `:data` | Initial route data (default `{}`) -| `:spec` | clojure.spec definition for a route data, see `reitit.spec` on how to use this -| `:syntax` | Path-parameter syntax as keyword or set of keywords (default #{:bracket :colon}) -| `:expand` | Function of `arg opts => data` to expand route arg to route data (default `reitit.core/expand`) -| `:coerce` | Function of `route opts => route` to coerce resolved route, can throw or return `nil` -| `:meta-merge-fn` | Function which follows the signature of `meta-merge.core/meta-merge`, useful for when you want to have more control over the meta merging -| `:compile` | Function of `route opts => result` to compile a route handler -| `:validate` | Function of `routes opts => ()` to validate route (data) via side-effects -| `:conflicts` | Function of `{route #{route}} => ()` to handle conflicting routes -| `:exception` | Function of `Exception => Exception ` to handle creation time exceptions (default `reitit.exception/exception`) -| `:router` | Function of `routes opts => router` to override the actual router implementation +| key | description +|---------------|------------- +| `:path` | Base-path for routes +| `:routes` | Initial resolved routes (default `[]`) +| `:data` | Initial route data (default `{}`) +| `:spec` | clojure.spec definition for a route data, see `reitit.spec` on how to use this +| `:syntax` | Path-parameter syntax as keyword or set of keywords (default #{:bracket :colon}) +| `:expand` | Function of `arg opts => data` to expand route arg to route data (default `reitit.core/expand`) +| `:coerce` | Function of `route opts => route` to coerce resolved route, can throw or return `nil` +| `:meta-merge` | Function which follows the signature of `meta-merge.core/meta-merge`, useful for when you want to have more control over the meta merging +| `:compile` | Function of `route opts => result` to compile a route handler +| `:validate` | Function of `routes opts => ()` to validate route (data) via side-effects +| `:conflicts` | Function of `{route #{route}} => ()` to handle conflicting routes +| `:exception` | Function of `Exception => Exception ` to handle creation time exceptions (default `reitit.exception/exception`) +| `:router` | Function of `routes opts => router` to override the actual router implementation diff --git a/modules/reitit-core/src/reitit/impl.cljc b/modules/reitit-core/src/reitit/impl.cljc index 40d02bf9..9b3780f5 100644 --- a/modules/reitit-core/src/reitit/impl.cljc +++ b/modules/reitit-core/src/reitit/impl.cljc @@ -60,11 +60,11 @@ (defn map-data [f routes] (mapv (fn [[p ds]] [p (f p ds)]) routes)) -(defn merge-data [{:keys [meta-merge-fn] :as g} p x] +(defn merge-data [{:keys [meta-merge]} p x] (reduce (fn [acc [k v]] (try - ((or meta-merge-fn mm/meta-merge) acc {k v}) + ((or meta-merge 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/modules/reitit-core/src/reitit/interceptor.cljc b/modules/reitit-core/src/reitit/interceptor.cljc index 9b544638..7f3dc593 100644 --- a/modules/reitit-core/src/reitit/interceptor.cljc +++ b/modules/reitit-core/src/reitit/interceptor.cljc @@ -1,6 +1,6 @@ (ns reitit.interceptor (:require [clojure.pprint :as pprint] - [meta-merge.core :refer [meta-merge]] + [meta-merge.core :as mm] [reitit.core :as r] [reitit.exception :as exception] [reitit.impl :as impl])) @@ -155,8 +155,8 @@ :handler get-user}]])" ([data] (router data nil)) - ([data {:keys [meta-merge-fn] :as opts}] - (let [opts ((or meta-merge-fn meta-merge) {:compile compile-result} opts)] + ([data {:keys [meta-merge] :as opts}] + (let [opts ((or meta-merge mm/meta-merge) {:compile compile-result} opts)] (r/router data opts)))) (defn interceptor-handler [router] diff --git a/modules/reitit-core/src/reitit/middleware.cljc b/modules/reitit-core/src/reitit/middleware.cljc index 58c13f67..3329d84a 100644 --- a/modules/reitit-core/src/reitit/middleware.cljc +++ b/modules/reitit-core/src/reitit/middleware.cljc @@ -1,6 +1,6 @@ (ns reitit.middleware (:require [clojure.pprint :as pprint] - [meta-merge.core :refer [meta-merge]] + [meta-merge.core :as mm] [reitit.core :as r] [reitit.exception :as exception] [reitit.impl :as impl])) @@ -138,8 +138,8 @@ :handler get-user}]])" ([data] (router data nil)) - ([data {:keys [meta-merge-fn] :as opts}] - (let [opts ((or meta-merge-fn meta-merge) {:compile compile-result} opts)] + ([data {:keys [meta-merge] :as opts}] + (let [opts ((or meta-merge mm/meta-merge) {:compile compile-result} opts)] (r/router data opts)))) (defn middleware-handler [router] diff --git a/modules/reitit-http/src/reitit/http.cljc b/modules/reitit-http/src/reitit/http.cljc index 36e96504..51c8b896 100644 --- a/modules/reitit-http/src/reitit/http.cljc +++ b/modules/reitit-http/src/reitit/http.cljc @@ -1,5 +1,5 @@ (ns reitit.http - (:require [meta-merge.core :refer [meta-merge]] + (:require [meta-merge.core :as mm] [reitit.core :as r] [reitit.exception :as ex] [reitit.interceptor :as interceptor] @@ -14,7 +14,7 @@ (update acc method expand opts) acc)) data ring/http-methods)]) -(defn compile-result [[path data] {:keys [::default-options-endpoint expand meta-merge-fn] :as opts}] +(defn compile-result [[path data] {:keys [::default-options-endpoint expand meta-merge] :as opts}] (let [[top childs] (ring/group-keys data) childs (cond-> childs (and (not (:options childs)) (not (:handler top)) default-options-endpoint) @@ -38,7 +38,7 @@ (->methods true top) (reduce-kv (fn [acc method data] - (let [data ((or meta-merge-fn meta-merge) top data)] + (let [data ((or meta-merge mm/meta-merge) top data)] (assoc acc method (->endpoint path data method method)))) (->methods (:handler top) data) childs)))) diff --git a/modules/reitit-ring/src/reitit/ring.cljc b/modules/reitit-ring/src/reitit/ring.cljc index 97fdc9d2..7dd2093d 100644 --- a/modules/reitit-ring/src/reitit/ring.cljc +++ b/modules/reitit-ring/src/reitit/ring.cljc @@ -1,6 +1,6 @@ (ns reitit.ring (:require [clojure.string :as str] - [meta-merge.core :refer [meta-merge]] + [meta-merge.core :as mm] #?@(:clj [[ring.util.mime-type :as mime-type] [ring.util.response :as response]]) [reitit.core :as r] @@ -29,7 +29,7 @@ (update acc method expand opts) acc)) data http-methods)]) -(defn compile-result [[path data] {:keys [::default-options-endpoint expand meta-merge-fn] :as opts}] +(defn compile-result [[path data] {:keys [::default-options-endpoint expand meta-merge] :as opts}] (let [[top childs] (group-keys data) childs (cond-> childs (and (not (:options childs)) (not (:handler top)) default-options-endpoint) @@ -50,7 +50,7 @@ (->methods true top) (reduce-kv (fn [acc method data] - (let [data ((or meta-merge-fn meta-merge) top data)] + (let [data ((or meta-merge mm/meta-merge) top data)] (assoc acc method (->endpoint path data method method)))) (->methods (:handler top) data) childs)))) diff --git a/test/cljc/reitit/ring_coercion_test.cljc b/test/cljc/reitit/ring_coercion_test.cljc index fb9879bc..64e906e3 100644 --- a/test/cljc/reitit/ring_coercion_test.cljc +++ b/test/cljc/reitit/ring_coercion_test.cljc @@ -562,7 +562,7 @@ (is (= {:status 200, :body {:total +4}} (call "application/edn" [:int {:encode/json -}])))))) (testing "using custom meta-merge function" - (let [->app (fn [schema-fn meta-merge-fn] + (let [->app (fn [schema-fn meta-merge] (ring/ring-handler (ring/router ["/merging-params/:foo" {:parameters {:path (schema-fn [:map [:foo :string]])}} @@ -574,10 +574,10 @@ {:data {:middleware [rrc/coerce-request-middleware rrc/coerce-response-middleware] :coercion malli/coercion} - :meta-merge-fn meta-merge-fn}))) - call (fn [schema-fn meta-merge-fn] - ((->app schema-fn meta-merge-fn) {:uri "/merging-params/this/that" - :request-method :get}))] + :meta-merge meta-merge}))) + call (fn [schema-fn meta-merge] + ((->app schema-fn meta-merge) {:uri "/merging-params/this/that" + :request-method :get}))] (is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call m/schema custom-meta-merge-checking-schema))) (is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call identity custom-meta-merge-checking-parameters)))))))