:meta-merge-fn -> :meta-merge

This commit is contained in:
Tommi Reiman 2023-01-09 16:57:14 +02:00
parent 3ec5acc7a1
commit 98a4d9b447
7 changed files with 34 additions and 34 deletions

View file

@ -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

View file

@ -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))

View file

@ -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]

View file

@ -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]

View file

@ -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))))

View file

@ -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))))

View file

@ -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)))))))