mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
:meta-merge-fn -> :meta-merge
This commit is contained in:
parent
3ec5acc7a1
commit
98a4d9b447
7 changed files with 34 additions and 34 deletions
|
|
@ -2,18 +2,18 @@
|
||||||
|
|
||||||
Routers can be configured via options. The following options are available for the `reitit.core/router`:
|
Routers can be configured via options. The following options are available for the `reitit.core/router`:
|
||||||
|
|
||||||
| key | description
|
| key | description
|
||||||
|--------------|-------------
|
|---------------|-------------
|
||||||
| `:path` | Base-path for routes
|
| `:path` | Base-path for routes
|
||||||
| `:routes` | Initial resolved routes (default `[]`)
|
| `:routes` | Initial resolved routes (default `[]`)
|
||||||
| `:data` | Initial route data (default `{}`)
|
| `:data` | Initial route data (default `{}`)
|
||||||
| `:spec` | clojure.spec definition for a route data, see `reitit.spec` on how to use this
|
| `: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})
|
| `: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`)
|
| `: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`
|
| `: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
|
| `: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
|
| `:compile` | Function of `route opts => result` to compile a route handler
|
||||||
| `:validate` | Function of `routes opts => ()` to validate route (data) via side-effects
|
| `:validate` | Function of `routes opts => ()` to validate route (data) via side-effects
|
||||||
| `:conflicts` | Function of `{route #{route}} => ()` to handle conflicting routes
|
| `:conflicts` | Function of `{route #{route}} => ()` to handle conflicting routes
|
||||||
| `:exception` | Function of `Exception => Exception ` to handle creation time exceptions (default `reitit.exception/exception`)
|
| `: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
|
| `:router` | Function of `routes opts => router` to override the actual router implementation
|
||||||
|
|
|
||||||
|
|
@ -60,11 +60,11 @@
|
||||||
(defn map-data [f routes]
|
(defn map-data [f routes]
|
||||||
(mapv (fn [[p ds]] [p (f p ds)]) 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
|
(reduce
|
||||||
(fn [acc [k v]]
|
(fn [acc [k v]]
|
||||||
(try
|
(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
|
(catch #?(:clj Exception, :cljs js/Error) e
|
||||||
(ex/fail! ::merge-data {:path p, :left acc, :right {k v}, :exception e}))))
|
(ex/fail! ::merge-data {:path p, :left acc, :right {k v}, :exception e}))))
|
||||||
{} x))
|
{} x))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(ns reitit.interceptor
|
(ns reitit.interceptor
|
||||||
(:require [clojure.pprint :as pprint]
|
(:require [clojure.pprint :as pprint]
|
||||||
[meta-merge.core :refer [meta-merge]]
|
[meta-merge.core :as mm]
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.exception :as exception]
|
[reitit.exception :as exception]
|
||||||
[reitit.impl :as impl]))
|
[reitit.impl :as impl]))
|
||||||
|
|
@ -155,8 +155,8 @@
|
||||||
:handler get-user}]])"
|
:handler get-user}]])"
|
||||||
([data]
|
([data]
|
||||||
(router data nil))
|
(router data nil))
|
||||||
([data {:keys [meta-merge-fn] :as opts}]
|
([data {:keys [meta-merge] :as opts}]
|
||||||
(let [opts ((or meta-merge-fn meta-merge) {:compile compile-result} opts)]
|
(let [opts ((or meta-merge mm/meta-merge) {:compile compile-result} opts)]
|
||||||
(r/router data opts))))
|
(r/router data opts))))
|
||||||
|
|
||||||
(defn interceptor-handler [router]
|
(defn interceptor-handler [router]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(ns reitit.middleware
|
(ns reitit.middleware
|
||||||
(:require [clojure.pprint :as pprint]
|
(:require [clojure.pprint :as pprint]
|
||||||
[meta-merge.core :refer [meta-merge]]
|
[meta-merge.core :as mm]
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.exception :as exception]
|
[reitit.exception :as exception]
|
||||||
[reitit.impl :as impl]))
|
[reitit.impl :as impl]))
|
||||||
|
|
@ -138,8 +138,8 @@
|
||||||
:handler get-user}]])"
|
:handler get-user}]])"
|
||||||
([data]
|
([data]
|
||||||
(router data nil))
|
(router data nil))
|
||||||
([data {:keys [meta-merge-fn] :as opts}]
|
([data {:keys [meta-merge] :as opts}]
|
||||||
(let [opts ((or meta-merge-fn meta-merge) {:compile compile-result} opts)]
|
(let [opts ((or meta-merge mm/meta-merge) {:compile compile-result} opts)]
|
||||||
(r/router data opts))))
|
(r/router data opts))))
|
||||||
|
|
||||||
(defn middleware-handler [router]
|
(defn middleware-handler [router]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(ns reitit.http
|
(ns reitit.http
|
||||||
(:require [meta-merge.core :refer [meta-merge]]
|
(:require [meta-merge.core :as mm]
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.exception :as ex]
|
[reitit.exception :as ex]
|
||||||
[reitit.interceptor :as interceptor]
|
[reitit.interceptor :as interceptor]
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
(update acc method expand opts)
|
(update acc method expand opts)
|
||||||
acc)) data ring/http-methods)])
|
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)
|
(let [[top childs] (ring/group-keys data)
|
||||||
childs (cond-> childs
|
childs (cond-> childs
|
||||||
(and (not (:options childs)) (not (:handler top)) default-options-endpoint)
|
(and (not (:options childs)) (not (:handler top)) default-options-endpoint)
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
(->methods true top)
|
(->methods true top)
|
||||||
(reduce-kv
|
(reduce-kv
|
||||||
(fn [acc method data]
|
(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))))
|
(assoc acc method (->endpoint path data method method))))
|
||||||
(->methods (:handler top) data)
|
(->methods (:handler top) data)
|
||||||
childs))))
|
childs))))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(ns reitit.ring
|
(ns reitit.ring
|
||||||
(:require [clojure.string :as str]
|
(:require [clojure.string :as str]
|
||||||
[meta-merge.core :refer [meta-merge]]
|
[meta-merge.core :as mm]
|
||||||
#?@(:clj [[ring.util.mime-type :as mime-type]
|
#?@(:clj [[ring.util.mime-type :as mime-type]
|
||||||
[ring.util.response :as response]])
|
[ring.util.response :as response]])
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
(update acc method expand opts)
|
(update acc method expand opts)
|
||||||
acc)) data http-methods)])
|
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)
|
(let [[top childs] (group-keys data)
|
||||||
childs (cond-> childs
|
childs (cond-> childs
|
||||||
(and (not (:options childs)) (not (:handler top)) default-options-endpoint)
|
(and (not (:options childs)) (not (:handler top)) default-options-endpoint)
|
||||||
|
|
@ -50,7 +50,7 @@
|
||||||
(->methods true top)
|
(->methods true top)
|
||||||
(reduce-kv
|
(reduce-kv
|
||||||
(fn [acc method data]
|
(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))))
|
(assoc acc method (->endpoint path data method method))))
|
||||||
(->methods (:handler top) data)
|
(->methods (:handler top) data)
|
||||||
childs))))
|
childs))))
|
||||||
|
|
|
||||||
|
|
@ -562,7 +562,7 @@
|
||||||
(is (= {:status 200, :body {:total +4}} (call "application/edn" [:int {:encode/json -}]))))))
|
(is (= {:status 200, :body {:total +4}} (call "application/edn" [:int {:encode/json -}]))))))
|
||||||
|
|
||||||
(testing "using custom meta-merge function"
|
(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/ring-handler
|
||||||
(ring/router
|
(ring/router
|
||||||
["/merging-params/:foo" {:parameters {:path (schema-fn [:map [:foo :string]])}}
|
["/merging-params/:foo" {:parameters {:path (schema-fn [:map [:foo :string]])}}
|
||||||
|
|
@ -574,10 +574,10 @@
|
||||||
{:data {:middleware [rrc/coerce-request-middleware
|
{:data {:middleware [rrc/coerce-request-middleware
|
||||||
rrc/coerce-response-middleware]
|
rrc/coerce-response-middleware]
|
||||||
:coercion malli/coercion}
|
:coercion malli/coercion}
|
||||||
:meta-merge-fn meta-merge-fn})))
|
:meta-merge meta-merge})))
|
||||||
call (fn [schema-fn meta-merge-fn]
|
call (fn [schema-fn meta-merge]
|
||||||
((->app schema-fn meta-merge-fn) {:uri "/merging-params/this/that"
|
((->app schema-fn meta-merge) {:uri "/merging-params/this/that"
|
||||||
:request-method :get}))]
|
: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 m/schema custom-meta-merge-checking-schema)))
|
||||||
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call identity custom-meta-merge-checking-parameters)))))))
|
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call identity custom-meta-merge-checking-parameters)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue