diff --git a/CHANGELOG.md b/CHANGELOG.md index d77091f8..69ef1f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,29 @@ We use [Break Versioning][breakver]. The version numbers follow a `. 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..8c6d1cbb 100644 --- a/modules/reitit-core/src/reitit/impl.cljc +++ b/modules/reitit-core/src/reitit/impl.cljc @@ -60,11 +60,14 @@ (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 meta-merge [left right opts] + ((or (:meta-merge opts) mm/meta-merge) left right)) + +(defn merge-data [opts p x] (reduce (fn [acc [k v]] (try - ((or meta-merge-fn mm/meta-merge) acc {k v}) + (meta-merge acc {k v} opts) (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..22d3584b 100644 --- a/modules/reitit-core/src/reitit/interceptor.cljc +++ b/modules/reitit-core/src/reitit/interceptor.cljc @@ -1,6 +1,5 @@ (ns reitit.interceptor (:require [clojure.pprint :as pprint] - [meta-merge.core :refer [meta-merge]] [reitit.core :as r] [reitit.exception :as exception] [reitit.impl :as impl])) @@ -155,14 +154,14 @@ :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 opts] + (let [opts (impl/meta-merge {:compile compile-result} opts opts)] (r/router data opts)))) (defn interceptor-handler [router] (with-meta - (fn [path] - (some->> (r/match-by-path router path) - :result - :interceptors)) - {::router router})) + (fn [path] + (some->> (r/match-by-path router path) + :result + :interceptors)) + {::router router})) diff --git a/modules/reitit-core/src/reitit/middleware.cljc b/modules/reitit-core/src/reitit/middleware.cljc index 58c13f67..3f1be365 100644 --- a/modules/reitit-core/src/reitit/middleware.cljc +++ b/modules/reitit-core/src/reitit/middleware.cljc @@ -1,6 +1,5 @@ (ns reitit.middleware (:require [clojure.pprint :as pprint] - [meta-merge.core :refer [meta-merge]] [reitit.core :as r] [reitit.exception :as exception] [reitit.impl :as impl])) @@ -138,15 +137,15 @@ :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 opts] + (let [opts (impl/meta-merge {:compile compile-result} opts opts)] (r/router data opts)))) (defn middleware-handler [router] (with-meta - (fn [path] - (some->> path - (r/match-by-path router) - :result - :handler)) - {::router router})) + (fn [path] + (some->> path + (r/match-by-path router) + :result + :handler)) + {::router router})) diff --git a/modules/reitit-core/src/reitit/trie.cljc b/modules/reitit-core/src/reitit/trie.cljc index 22c6356b..061dbeab 100644 --- a/modules/reitit-core/src/reitit/trie.cljc +++ b/modules/reitit-core/src/reitit/trie.cljc @@ -176,10 +176,10 @@ (fn [_ [p n]] (if-let [cp (common-prefix p path)] (if (= cp p) - ;; insert into child node + ;; insert into child node (let [n' (-insert n (conj ps (subs path (count p))) fp params data)] (reduced (assoc-in node [:children p] n'))) - ;; split child node + ;; split child node (let [rp (subs p (count cp)) rp' (subs path (count cp)) n' (-insert (-node {}) ps fp params data) @@ -189,7 +189,7 @@ (dissoc p) (assoc cp n''))))))))) nil (:children node)) - ;; new child node + ;; new child node (assoc-in node [:children path] (-insert (-node {}) ps fp params data))))] (if-let [child (get-in node' [:children ""])] ;; optimize by removing empty paths @@ -385,62 +385,62 @@ ;; (comment - (-> - [["/v2/whoami" 1] - ["/v2/users/:user-id/datasets" 2] - ["/v2/public/projects/:project-id/datasets" 3] - ["/v1/public/topics/:topic" 4] - ["/v1/users/:user-id/orgs/:org-id" 5] - ["/v1/search/topics/:term" 6] - ["/v1/users/:user-id/invitations" 7] - ["/v1/users/:user-id/topics" 9] - ["/v1/users/:user-id/bookmarks/followers" 10] - ["/v2/datasets/:dataset-id" 11] - ["/v1/orgs/:org-id/usage-stats" 12] - ["/v1/orgs/:org-id/devices/:client-id" 13] - ["/v1/messages/user/:user-id" 14] - ["/v1/users/:user-id/devices" 15] - ["/v1/public/users/:user-id" 16] - ["/v1/orgs/:org-id/errors" 17] - ["/v1/public/orgs/:org-id" 18] - ["/v1/orgs/:org-id/invitations" 19] - ["/v1/users/:user-id/device-errors" 22] - ["/v2/login" 23] - ["/v1/users/:user-id/usage-stats" 24] - ["/v2/users/:user-id/devices" 25] - ["/v1/users/:user-id/claim-device/:client-id" 26] - ["/v2/public/projects/:project-id" 27] - ["/v2/public/datasets/:dataset-id" 28] - ["/v2/users/:user-id/topics/bulk" 29] - ["/v1/messages/device/:client-id" 30] - ["/v1/users/:user-id/owned-orgs" 31] - ["/v1/topics/:topic" 32] - ["/v1/users/:user-id/bookmark/:topic" 33] - ["/v1/orgs/:org-id/members/:user-id" 34] - ["/v1/users/:user-id/devices/:client-id" 35] - ["/v1/users/:user-id" 36] - ["/v1/orgs/:org-id/devices" 37] - ["/v1/orgs/:org-id/members" 38] - ["/v2/orgs/:org-id/topics" 40] - ["/v1/whoami" 41] - ["/v1/orgs/:org-id" 42] - ["/v1/users/:user-id/api-key" 43] - ["/v2/schemas" 44] - ["/v2/users/:user-id/topics" 45] - ["/v1/orgs/:org-id/confirm-membership/:token" 46] - ["/v2/topics/:topic" 47] - ["/v1/messages/topic/:topic" 48] - ["/v1/users/:user-id/devices/:client-id/reset-password" 49] - ["/v2/topics" 50] - ["/v1/login" 51] - ["/v1/users/:user-id/orgs" 52] - ["/v2/public/messages/dataset/:dataset-id" 53] - ["/v1/topics" 54] - ["/v1/orgs" 55] - ["/v1/users/:user-id/bookmarks" 56] - ["/v1/orgs/:org-id/topics" 57] - ["/command1 {arg1} {arg2}" ::cmd1] - ["/command2 {arg1} {arg2} {arg3}" ::cmd2]] - (insert) - (compile) - (pretty))) + (-> + [["/v2/whoami" 1] + ["/v2/users/:user-id/datasets" 2] + ["/v2/public/projects/:project-id/datasets" 3] + ["/v1/public/topics/:topic" 4] + ["/v1/users/:user-id/orgs/:org-id" 5] + ["/v1/search/topics/:term" 6] + ["/v1/users/:user-id/invitations" 7] + ["/v1/users/:user-id/topics" 9] + ["/v1/users/:user-id/bookmarks/followers" 10] + ["/v2/datasets/:dataset-id" 11] + ["/v1/orgs/:org-id/usage-stats" 12] + ["/v1/orgs/:org-id/devices/:client-id" 13] + ["/v1/messages/user/:user-id" 14] + ["/v1/users/:user-id/devices" 15] + ["/v1/public/users/:user-id" 16] + ["/v1/orgs/:org-id/errors" 17] + ["/v1/public/orgs/:org-id" 18] + ["/v1/orgs/:org-id/invitations" 19] + ["/v1/users/:user-id/device-errors" 22] + ["/v2/login" 23] + ["/v1/users/:user-id/usage-stats" 24] + ["/v2/users/:user-id/devices" 25] + ["/v1/users/:user-id/claim-device/:client-id" 26] + ["/v2/public/projects/:project-id" 27] + ["/v2/public/datasets/:dataset-id" 28] + ["/v2/users/:user-id/topics/bulk" 29] + ["/v1/messages/device/:client-id" 30] + ["/v1/users/:user-id/owned-orgs" 31] + ["/v1/topics/:topic" 32] + ["/v1/users/:user-id/bookmark/:topic" 33] + ["/v1/orgs/:org-id/members/:user-id" 34] + ["/v1/users/:user-id/devices/:client-id" 35] + ["/v1/users/:user-id" 36] + ["/v1/orgs/:org-id/devices" 37] + ["/v1/orgs/:org-id/members" 38] + ["/v2/orgs/:org-id/topics" 40] + ["/v1/whoami" 41] + ["/v1/orgs/:org-id" 42] + ["/v1/users/:user-id/api-key" 43] + ["/v2/schemas" 44] + ["/v2/users/:user-id/topics" 45] + ["/v1/orgs/:org-id/confirm-membership/:token" 46] + ["/v2/topics/:topic" 47] + ["/v1/messages/topic/:topic" 48] + ["/v1/users/:user-id/devices/:client-id/reset-password" 49] + ["/v2/topics" 50] + ["/v1/login" 51] + ["/v1/users/:user-id/orgs" 52] + ["/v2/public/messages/dataset/:dataset-id" 53] + ["/v1/topics" 54] + ["/v1/orgs" 55] + ["/v1/users/:user-id/bookmarks" 56] + ["/v1/orgs/:org-id/topics" 57] + ["/command1 {arg1} {arg2}" ::cmd1] + ["/command2 {arg1} {arg2} {arg3}" ::cmd2]] + (insert) + (compile) + (pretty))) diff --git a/modules/reitit-dev/src/reitit/dev/pretty.cljc b/modules/reitit-dev/src/reitit/dev/pretty.cljc index 158d09e0..78e683a3 100644 --- a/modules/reitit-dev/src/reitit/dev/pretty.cljc +++ b/modules/reitit-dev/src/reitit/dev/pretty.cljc @@ -9,8 +9,7 @@ [fipp.engine] [fipp.visit] [reitit.exception :as exception] - [spell-spec.expound] ;; expound -)) + [spell-spec.expound])) ;; expound ;; ;; colors @@ -46,17 +45,17 @@ :error 196}) (comment - (defn- -color [color & text] - (str "\033[38;5;" (colors color color) "m" (apply str text) "\u001B[0m")) + (defn- -color [color & text] + (str "\033[38;5;" (colors color color) "m" (apply str text) "\u001B[0m")) - (doseq [c (range 0 255)] - (println (-color c "kikka") "->" c)) + (doseq [c (range 0 255)] + (println (-color c "kikka") "->" c)) - (doseq [[n c] colors] - (println (-color c "kikka") "->" c n)) + (doseq [[n c] colors] + (println (-color c "kikka") "->" c n)) - (doseq [[k v] expound.ansi/sgr-code] - (println (expound.ansi/sgr "kikka" k) "->" k))) + (doseq [[k v] expound.ansi/sgr-code] + (println (expound.ansi/sgr "kikka" k) "->" k))) (defn- -start [x] (str "\033[38;5;" x "m")) (defn- -end [] "\u001B[0m") @@ -220,10 +219,10 @@ (defn exception [e] (let [data (-> e ex-data :data) message (format-exception (-> e ex-data :type) #?(:clj (.getMessage ^Exception e) :cljs (ex-message e)) data) - source #?(:clj (->> e Throwable->map :trace - (drop-while #(not= (name (first %)) "reitit.core$router")) - (drop-while #(= (name (first %)) "reitit.core$router")) - next first source-str) + source #?(:clj (->> e Throwable->map :trace + (drop-while #(not= (name (first %)) "reitit.core$router")) + (drop-while #(= (name (first %)) "reitit.core$router")) + next first source-str) :cljs "unknown")] (ex-info (exception-str message source (printer)) (assoc (or data {}) ::exception/cause e)))) diff --git a/modules/reitit-http/src/reitit/http.cljc b/modules/reitit-http/src/reitit/http.cljc index 36e96504..bf0f3ae5 100644 --- a/modules/reitit-http/src/reitit/http.cljc +++ b/modules/reitit-http/src/reitit/http.cljc @@ -1,7 +1,7 @@ (ns reitit.http - (:require [meta-merge.core :refer [meta-merge]] - [reitit.core :as r] + (:require [reitit.core :as r] [reitit.exception :as ex] + [reitit.impl :as impl] [reitit.interceptor :as interceptor] [reitit.ring :as ring])) @@ -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] :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 (impl/meta-merge top data opts)] (assoc acc method (->endpoint path data method method)))) (->methods (:handler top) data) childs)))) @@ -138,35 +138,35 @@ enrich-request (ring/create-enrich-request inject-match? inject-router?) enrich-default-request (ring/create-enrich-default-request inject-router?)] (with-meta - (fn - ([request] - (if-let [match (r/match-by-path router (:uri request))] - (let [method (:request-method request) - path-params (:path-params match) - endpoint (-> match :result method) - interceptors (or (:queue endpoint) (:interceptors endpoint)) - request (enrich-request request path-params match router)] - (or (interceptor/execute executor interceptors request) - (interceptor/execute executor default-queue request))) - (interceptor/execute executor default-queue (enrich-default-request request router)))) - ([request respond raise] - (let [default #(interceptor/execute executor default-queue % respond raise)] - (if-let [match (r/match-by-path router (:uri request))] - (let [method (:request-method request) - path-params (:path-params match) - endpoint (-> match :result method) - interceptors (or (:queue endpoint) (:interceptors endpoint)) - request (enrich-request request path-params match router) - respond' (fn [response] - (if response - (respond response) - (default request)))] - (if interceptors - (interceptor/execute executor interceptors request respond' raise) - (default request))) - (default (enrich-default-request request router)))) - nil)) - {::r/router router})))) + (fn + ([request] + (if-let [match (r/match-by-path router (:uri request))] + (let [method (:request-method request) + path-params (:path-params match) + endpoint (-> match :result method) + interceptors (or (:queue endpoint) (:interceptors endpoint)) + request (enrich-request request path-params match router)] + (or (interceptor/execute executor interceptors request) + (interceptor/execute executor default-queue request))) + (interceptor/execute executor default-queue (enrich-default-request request router)))) + ([request respond raise] + (let [default #(interceptor/execute executor default-queue % respond raise)] + (if-let [match (r/match-by-path router (:uri request))] + (let [method (:request-method request) + path-params (:path-params match) + endpoint (-> match :result method) + interceptors (or (:queue endpoint) (:interceptors endpoint)) + request (enrich-request request path-params match router) + respond' (fn [response] + (if response + (respond response) + (default request)))] + (if interceptors + (interceptor/execute executor interceptors request respond' raise) + (default request))) + (default (enrich-default-request request router)))) + nil)) + {::r/router router})))) (defn get-router [handler] (-> handler meta ::r/router)) diff --git a/modules/reitit-malli/src/reitit/coercion/malli.cljc b/modules/reitit-malli/src/reitit/coercion/malli.cljc index e7b2607c..87388add 100644 --- a/modules/reitit-malli/src/reitit/coercion/malli.cljc +++ b/modules/reitit-malli/src/reitit/coercion/malli.cljc @@ -140,7 +140,7 @@ show? (fn [key] (contains? error-keys key)) transformers (walk/prewalk #(if (satisfies? TransformationProvider %) (-transformer % opts) %) transformers) compile (if lite (fn [schema options] (compile (binding [l/*options* options] (l/schema schema)) options)) - compile)] + compile)] ^{:type ::coercion/coercion} (reify coercion/Coercion (-get-name [_] :malli) diff --git a/modules/reitit-ring/src/reitit/ring.cljc b/modules/reitit-ring/src/reitit/ring.cljc index 8cbc36d2..5c292734 100644 --- a/modules/reitit-ring/src/reitit/ring.cljc +++ b/modules/reitit-ring/src/reitit/ring.cljc @@ -1,8 +1,7 @@ (ns reitit.ring (:require [clojure.string :as str] - [meta-merge.core :refer [meta-merge]] #?@(:clj [[ring.util.mime-type :as mime-type] - [ring.util.response :as response]]) + [ring.util.response :as response]]) [reitit.core :as r] [reitit.exception :as ex] [reitit.impl :as impl] @@ -29,7 +28,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] :as opts}] (let [[top childs] (group-keys data) childs (cond-> childs (and (not (:options childs)) (not (:handler top)) default-options-endpoint) @@ -50,7 +49,7 @@ (->methods true top) (reduce-kv (fn [acc method data] - (let [data ((or meta-merge-fn meta-merge) top data)] + (let [data (impl/meta-merge top data opts)] (assoc acc method (->endpoint path data method method)))) (->methods (:handler top) data) childs)))) @@ -317,28 +316,28 @@ enrich-request (create-enrich-request inject-match? inject-router?) enrich-default-request (create-enrich-default-request inject-router?)] (with-meta - (wrap - (fn - ([request] - (if-let [match (r/match-by-path router (:uri request))] - (let [method (:request-method request) - path-params (:path-params match) - result (:result match) - handler (-> result method :handler (or default-handler)) - request (enrich-request request path-params match router)] - (or (handler request) (default-handler request))) - (default-handler (enrich-default-request request router)))) - ([request respond raise] - (if-let [match (r/match-by-path router (:uri request))] - (let [method (:request-method request) - path-params (:path-params match) - result (:result match) - handler (-> result method :handler (or default-handler)) - request (enrich-request request path-params match router)] - ((routes handler default-handler) request respond raise)) - (default-handler (enrich-default-request request router) respond raise)) - nil))) - {::r/router router})))) + (wrap + (fn + ([request] + (if-let [match (r/match-by-path router (:uri request))] + (let [method (:request-method request) + path-params (:path-params match) + result (:result match) + handler (-> result method :handler (or default-handler)) + request (enrich-request request path-params match router)] + (or (handler request) (default-handler request))) + (default-handler (enrich-default-request request router)))) + ([request respond raise] + (if-let [match (r/match-by-path router (:uri request))] + (let [method (:request-method request) + path-params (:path-params match) + result (:result match) + handler (-> result method :handler (or default-handler)) + request (enrich-request request path-params match router)] + ((routes handler default-handler) request respond raise)) + (default-handler (enrich-default-request request router) respond raise)) + nil))) + {::r/router router})))) (defn reloading-ring-handler "Returns a ring-handler that recreates the actual ring-handler for each request. diff --git a/modules/reitit-schema/src/reitit/coercion/schema.cljc b/modules/reitit-schema/src/reitit/coercion/schema.cljc index 022f3872..4c29e1c4 100644 --- a/modules/reitit-schema/src/reitit/coercion/schema.cljc +++ b/modules/reitit-schema/src/reitit/coercion/schema.cljc @@ -47,7 +47,7 @@ (-get-name [_] :schema) (-get-options [_] opts) (-get-apidocs [this specification {:keys [parameters responses]}] - ;; TODO: this looks identical to spec, refactor when schema is done. + ;; TODO: this looks identical to spec, refactor when schema is done. (case specification :swagger (swagger/swagger-spec (merge diff --git a/modules/reitit-swagger/src/reitit/swagger.cljc b/modules/reitit-swagger/src/reitit/swagger.cljc index 0286565a..3c3403cb 100644 --- a/modules/reitit-swagger/src/reitit/swagger.cljc +++ b/modules/reitit-swagger/src/reitit/swagger.cljc @@ -91,13 +91,13 @@ (if (and data (not no-doc)) [method (meta-merge - base-swagger-spec - (apply meta-merge (keep (comp :swagger :data) middleware)) - (apply meta-merge (keep (comp :swagger :data) interceptors)) - (if coercion - (coercion/get-apidocs coercion :swagger data)) - (select-keys data [:tags :summary :description :operationId]) - (strip-top-level-keys swagger))])) + base-swagger-spec + (apply meta-merge (keep (comp :swagger :data) middleware)) + (apply meta-merge (keep (comp :swagger :data) interceptors)) + (if coercion + (coercion/get-apidocs coercion :swagger data)) + (select-keys data [:tags :summary :description :operationId]) + (strip-top-level-keys swagger))])) transform-path (fn [[p _ c]] (if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))] [(swagger-path p (r/options router)) endpoint])) diff --git a/project.clj b/project.clj index edfe3e1b..8b1c06ff 100644 --- a/project.clj +++ b/project.clj @@ -27,24 +27,24 @@ [metosin/reitit-frontend "0.5.18"] [metosin/reitit-sieppari "0.5.18"] [metosin/reitit-pedestal "0.5.18"] - [metosin/ring-swagger-ui "4.3.0"] + [metosin/ring-swagger-ui "4.15.5"] [metosin/spec-tools "0.10.5"] [metosin/schema-tools "0.12.3"] [metosin/muuntaja "0.6.8"] - [metosin/jsonista "0.3.5"] + [metosin/jsonista "0.3.7"] [metosin/sieppari "0.0.0-alpha13"] - [metosin/malli "0.8.2"] + [metosin/malli "0.10.1"] ;; https://clojureverse.org/t/depending-on-the-right-versions-of-jackson-libraries/5111 [com.fasterxml.jackson.core/jackson-core "2.14.1"] [com.fasterxml.jackson.core/jackson-databind "2.14.1"] [meta-merge "1.0.0"] - [fipp "0.6.25" :exclusions [org.clojure/core.rrb-vector]] + [fipp "0.6.26" :exclusions [org.clojure/core.rrb-vector]] [expound "0.9.0"] [lambdaisland/deep-diff "0.0-47"] [com.bhauman/spell-spec "0.1.2"] - [ring/ring-core "1.9.5"] + [ring/ring-core "1.9.6"] [io.pedestal/pedestal.service "0.5.10"]] @@ -77,7 +77,7 @@ :java-source-paths ["modules/reitit-core/java-src"] - :dependencies [[org.clojure/clojure "1.10.2"] + :dependencies [[org.clojure/clojure "1.11.1"] [org.clojure/clojurescript "1.10.773"] ;; modules dependencies @@ -85,55 +85,55 @@ [metosin/spec-tools "0.10.5"] [metosin/muuntaja "0.6.8"] [metosin/sieppari "0.0.0-alpha13"] - [metosin/jsonista "0.3.5"] - [metosin/malli "0.8.2"] + [metosin/jsonista "0.3.7"] + [metosin/malli "0.10.1"] [lambdaisland/deep-diff "0.0-47"] [meta-merge "1.0.0"] [com.bhauman/spell-spec "0.1.2"] [expound "0.9.0"] - [fipp "0.6.25"] + [fipp "0.6.26"] [orchestra "2021.01.01-1"] - [ring "1.9.5"] + [ring "1.9.6"] [ikitommi/immutant-web "3.0.0-alpha1"] [metosin/ring-http-response "0.9.3"] - [metosin/ring-swagger-ui "4.3.0"] + [metosin/ring-swagger-ui "4.15.5"] [criterium "0.4.6"] [org.clojure/test.check "1.1.1"] - [org.clojure/tools.namespace "1.2.0"] + [org.clojure/tools.namespace "1.3.0"] [com.gfredericks/test.chuck "0.2.13"] [io.pedestal/pedestal.service "0.5.10"] - [org.clojure/core.async "1.5.648"] - [manifold "0.2.3"] - [funcool/promesa "6.1.434"] + [org.clojure/core.async "1.6.673"] + [manifold "0.3.0"] + [funcool/promesa "10.0.594"] - [com.clojure-goes-fast/clj-async-profiler "0.5.1"] + [com.clojure-goes-fast/clj-async-profiler "1.0.3"] [ring-cors "0.1.13"] [com.bhauman/rebel-readline "0.1.4"]]} - :1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]} + :1.10 {:dependencies [[org.clojure/clojure "1.10.3"]]} :perf {:jvm-opts ^:replace ["-server" "-Xmx4096m" "-Dclojure.compiler.direct-linking=true"] :test-paths ["perf-test/clj"] - :dependencies [[compojure "1.6.2"] - [ring/ring-defaults "0.3.3"] + :dependencies [[compojure "1.7.0"] + [ring/ring-defaults "0.3.4"] [ikitommi/immutant-web "3.0.0-alpha1"] [io.pedestal/pedestal.service "0.5.10"] [io.pedestal/pedestal.jetty "0.5.10"] [calfpath "0.8.1"] - [org.clojure/core.async "1.5.648"] - [manifold "0.2.3"] - [funcool/promesa "6.1.434"] + [org.clojure/core.async "1.6.673"] + [manifold "0.3.0"] + [funcool/promesa "10.0.594"] [metosin/sieppari] [yada "1.2.16"] - [aleph "0.4.6"] - [ring/ring-defaults "0.3.3"] - [ataraxy "0.4.2"] + [aleph "0.6.0"] + [ring/ring-defaults "0.3.4"] + [ataraxy "0.4.3"] [bidi "2.1.6"] [janus "1.3.2"]]} :analyze {:jvm-opts ^:replace ["-server" @@ -141,7 +141,7 @@ "-XX:+PrintCompilation" "-XX:+UnlockDiagnosticVMOptions" "-XX:+PrintInlining"]}} - :aliases {"all" ["with-profile" "dev,default:dev,default,1.9"] + :aliases {"all" ["with-profile" "dev,default:dev,default,1.10"] "perf" ["with-profile" "default,dev,perf"] "test-clj" ["all" "do" ["bat-test"] ["check"]] "test-browser" ["doo" "chrome-headless" "test"] diff --git a/test/clj/cljdoc/reaper.clj b/test/clj/cljdoc/reaper.clj index bce3e68c..cee3dee6 100644 --- a/test/clj/cljdoc/reaper.clj +++ b/test/clj/cljdoc/reaper.clj @@ -30,4 +30,4 @@ (spit "doc/cljdoc.edn" (with-out-str (pprint/pprint data))))) (comment - (reap!)) + (reap!)) diff --git a/test/cljc/reitit/exception_test.cljc b/test/cljc/reitit/exception_test.cljc index bb77421d..77362c44 100644 --- a/test/cljc/reitit/exception_test.cljc +++ b/test/cljc/reitit/exception_test.cljc @@ -1,6 +1,6 @@ (ns reitit.exception-test (:require [clojure.spec.alpha :as s] - [clojure.test :refer [are deftest is testing]] + [clojure.test :refer [are deftest is]] [reitit.core :as r] [reitit.dev.pretty :as pretty] [reitit.exception :as exception] diff --git a/test/cljc/reitit/impl_test.cljc b/test/cljc/reitit/impl_test.cljc index 119a5fad..0059723b 100644 --- a/test/cljc/reitit/impl_test.cljc +++ b/test/cljc/reitit/impl_test.cljc @@ -1,5 +1,5 @@ (ns reitit.impl-test - (:require [clojure.test :refer [are deftest is testing]] + (:require [clojure.test :refer [are deftest is]] [reitit.impl :as impl])) (deftest strip-nils-test diff --git a/test/cljc/reitit/interceptor_test.cljc b/test/cljc/reitit/interceptor_test.cljc index 185db2db..f8bc8b43 100644 --- a/test/cljc/reitit/interceptor_test.cljc +++ b/test/cljc/reitit/interceptor_test.cljc @@ -1,5 +1,5 @@ (ns reitit.interceptor-test - (:require [clojure.test :refer [are deftest is testing]] + (:require [clojure.test :refer [deftest is testing]] [reitit.core :as r] [reitit.interceptor :as interceptor]) #?(:clj diff --git a/test/cljc/reitit/middleware_test.cljc b/test/cljc/reitit/middleware_test.cljc index 0b7bb05e..23426461 100644 --- a/test/cljc/reitit/middleware_test.cljc +++ b/test/cljc/reitit/middleware_test.cljc @@ -1,5 +1,5 @@ (ns reitit.middleware-test - (:require [clojure.test :refer [are deftest is testing]] + (:require [clojure.test :refer [deftest is testing]] [reitit.core :as r] [reitit.middleware :as middleware]) #?(:clj diff --git a/test/cljc/reitit/ring_coercion_test.cljc b/test/cljc/reitit/ring_coercion_test.cljc index fb9879bc..e8bee456 100644 --- a/test/cljc/reitit/ring_coercion_test.cljc +++ b/test/cljc/reitit/ring_coercion_test.cljc @@ -2,7 +2,7 @@ (:require [clojure.test :refer [deftest is testing]] [malli.experimental.lite :as l] #?@(:clj [[muuntaja.middleware] - [jsonista.core :as j]]) + [jsonista.core :as j]]) [malli.core :as m] [malli.util :as mu] [meta-merge.core :refer [meta-merge]] @@ -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))))))) diff --git a/test/cljc/reitit/ring_spec_test.cljc b/test/cljc/reitit/ring_spec_test.cljc index 1112342b..5d4e4ee7 100644 --- a/test/cljc/reitit/ring_spec_test.cljc +++ b/test/cljc/reitit/ring_spec_test.cljc @@ -83,7 +83,7 @@ ExceptionInfo #"Invalid route data" (ring/router - ["/api" {:handler identity + ["/api" {:handler identity :middleware '()}] {:validate rrs/validate}))))) diff --git a/test/cljc/reitit/spec_test.cljc b/test/cljc/reitit/spec_test.cljc index e2717989..740d2df2 100644 --- a/test/cljc/reitit/spec_test.cljc +++ b/test/cljc/reitit/spec_test.cljc @@ -39,7 +39,7 @@ (are [data] (is (thrown-with-msg? ExceptionInfo - #"Call to #'reitit.core/router did not conform to spec" + #"Call to (#')*reitit.core/router did not conform to spec" (r/router data))) @@ -69,7 +69,7 @@ (are [opts] (is (thrown-with-msg? ExceptionInfo - #"Call to #'reitit.core/router did not conform to spec" + #"Call to (#')*reitit.core/router did not conform to spec" (r/router ["/api"] opts))) diff --git a/test/cljc/reitit/swagger_test.clj b/test/cljc/reitit/swagger_test.clj index 96dfed23..0958b8b1 100644 --- a/test/cljc/reitit/swagger_test.clj +++ b/test/cljc/reitit/swagger_test.clj @@ -22,35 +22,35 @@ :swagger {:info {:title "my-api"}} :handler (swagger/create-swagger-handler)}}] - ["/spec" {:coercion spec/coercion} - ["/plus/:z" - {:patch {:summary "patch" - :operationId "Patch" + ["/spec" {:coercion spec/coercion} + ["/plus/:z" + {:patch {:summary "patch" + :operationId "Patch" + :handler (constantly {:status 200})} + :options {:summary "options" + :middleware [{:data {:swagger {:responses {200 {:description "200"}}}}}] :handler (constantly {:status 200})} - :options {:summary "options" - :middleware [{:data {:swagger {:responses {200 {:description "200"}}}}}] - :handler (constantly {:status 200})} - :get {:summary "plus" - :operationId "GetPlus" - :parameters {:query {:x int?, :y int?} - :path {:z int?}} - :swagger {:responses {400 {:schema {:type "string"} - :description "kosh"}}} - :responses {200 {:body {:total int?}} - 500 {:description "fail"}} - :handler (fn [{{{:keys [x y]} :query - {:keys [z]} :path} :parameters}] - {:status 200, :body {:total (+ x y z)}})} - :post {:summary "plus with body" - :parameters {:body (ds/maybe [int?]) - :path {:z int?}} - :swagger {:responses {400 {:schema {:type "string"} - :description "kosh"}}} - :responses {200 {:body {:total int?}} - 500 {:description "fail"}} - :handler (fn [{{{:keys [z]} :path - xs :body} :parameters}] - {:status 200, :body {:total (+ (reduce + xs) z)}})}}]] + :get {:summary "plus" + :operationId "GetPlus" + :parameters {:query {:x int?, :y int?} + :path {:z int?}} + :swagger {:responses {400 {:schema {:type "string"} + :description "kosh"}}} + :responses {200 {:body {:total int?}} + 500 {:description "fail"}} + :handler (fn [{{{:keys [x y]} :query + {:keys [z]} :path} :parameters}] + {:status 200, :body {:total (+ x y z)}})} + :post {:summary "plus with body" + :parameters {:body (ds/maybe [int?]) + :path {:z int?}} + :swagger {:responses {400 {:schema {:type "string"} + :description "kosh"}}} + :responses {200 {:body {:total int?}} + 500 {:description "fail"}} + :handler (fn [{{{:keys [z]} :path + xs :body} :parameters}] + {:status 200, :body {:total (+ (reduce + xs) z)}})}}]] ["/malli" {:coercion malli/coercion} ["/plus/*z" @@ -206,6 +206,7 @@ :responses {200 {:schema {:type "object" :properties {:total {:format "int64" :type "integer"}} + :additionalProperties false :required [:total]} :description ""} 400 {:schema {:type "string"} @@ -229,6 +230,7 @@ :responses {200 {:description "" :schema {:properties {:total {:format "int64" :type "integer"}} + :additionalProperties false :required [:total] :type "object"}} 400 {:schema {:type "string"} diff --git a/test/cljs/reitit/frontend/controllers_test.cljs b/test/cljs/reitit/frontend/controllers_test.cljs index 70fbcd9c..ba7e4410 100644 --- a/test/cljs/reitit/frontend/controllers_test.cljs +++ b/test/cljs/reitit/frontend/controllers_test.cljs @@ -10,11 +10,11 @@ (let [log (atom []) controller-state (atom []) controller-1 {:start (fn [_] (swap! log conj :start-1)) - :stop (fn [_] (swap! log conj :stop-1))} + :stop (fn [_] (swap! log conj :stop-1))} controller-2 {:start (fn [_] (swap! log conj :start-2)) - :stop (fn [_] (swap! log conj :stop-2))} + :stop (fn [_] (swap! log conj :stop-2))} controller-3 {:start (fn [{:keys [foo]}] (swap! log conj [:start-3 foo])) - :stop (fn [{:keys [foo]}] (swap! log conj [:stop-3 foo])) + :stop (fn [{:keys [foo]}] (swap! log conj [:stop-3 foo])) :identity (fn [match] {:foo (-> match :parameters :path :foo)})}] @@ -70,9 +70,9 @@ (let [log (atom []) controller-state (atom []) static {:start (fn [params] (swap! log conj [:start-static])) - :stop (fn [params] (swap! log conj [:stop-static]))} + :stop (fn [params] (swap! log conj [:stop-static]))} controller {:start (fn [params] (swap! log conj [:start params])) - :stop (fn [params] (swap! log conj [:stop params])) + :stop (fn [params] (swap! log conj [:stop params])) :parameters {:path [:foo]}}] (testing "init" diff --git a/test/cljs/reitit/frontend/core_test.cljs b/test/cljs/reitit/frontend/core_test.cljs index e5c1d13a..72bf9428 100644 --- a/test/cljs/reitit/frontend/core_test.cljs +++ b/test/cljs/reitit/frontend/core_test.cljs @@ -56,9 +56,9 @@ (is (= [{:type :warn :message ["missing route" ::asd]}] (:messages - (capture-console - (fn [] - (rf/match-by-name! router ::asd))))))))) + (capture-console + (fn [] + (rf/match-by-name! router ::asd))))))))) (testing "schema coercion" (let [router (r/router ["/" @@ -124,6 +124,6 @@ :required #{:id} :path-params {}}]}] (:messages - (capture-console - (fn [] - (rf/match-by-name! router ::foo {})))))))))) + (capture-console + (fn [] + (rf/match-by-name! router ::foo {})))))))))) diff --git a/test/cljs/reitit/frontend/history_test.cljs b/test/cljs/reitit/frontend/history_test.cljs index cf5341fb..ffab3970 100644 --- a/test/cljs/reitit/frontend/history_test.cljs +++ b/test/cljs/reitit/frontend/history_test.cljs @@ -27,8 +27,8 @@ (is (= "#/bar/5?q=x" (rfh/href history ::bar {:id 5} {:q "x"}))) (let [{:keys [value messages]} (capture-console - (fn [] - (rfh/href history ::asd)))] + (fn [] + (rfh/href history ::asd)))] (is (= nil value)) (is (= [{:type :warn :message ["missing route" ::asd]}] @@ -84,8 +84,8 @@ (is (= "/bar/5?q=x" (rfh/href history ::bar {:id 5} {:q "x"}))) (let [{:keys [value messages]} (capture-console - (fn [] - (rfh/href history ::asd)))] + (fn [] + (rfh/href history ::asd)))] (is (= nil value)) (is (= [{:type :warn :message ["missing route" ::asd]}] @@ -153,7 +153,7 @@ (done))))) {:use-fragment false}) create-link #(doto - (js/document.createElement "A") + (js/document.createElement "A") (.setAttribute "href" (rfh/href history ::foo))) document-link (create-link) shadow-link (create-link)] diff --git a/test/cljs/reitit/frontend/test_utils.cljs b/test/cljs/reitit/frontend/test_utils.cljs index b70c5f37..6bd1163f 100644 --- a/test/cljs/reitit/frontend/test_utils.cljs +++ b/test/cljs/reitit/frontend/test_utils.cljs @@ -10,6 +10,6 @@ (set! js/console.warn (partial log :warn)) (f) (finally - (set! js/console.warn original-console-warn)))] + (set! js/console.warn original-console-warn)))] {:value value :messages @messages}))