Merge pull request #579 from metosin/mm

2023 Cleanup Branch
This commit is contained in:
Tommi Reiman 2023-01-22 14:26:07 +02:00 committed by GitHub
commit e5bd123740
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 291 additions and 267 deletions

View file

@ -12,6 +12,29 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino
[breakver]: https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md
## UNRELEASED
* Remove redundant s/and [#552](https://github.com/metosin/reitit/pull/552)
* FIX: redirect-trailing-slash-handler strips query-params [#565](https://github.com/metosin/reitit/issues/565)
* **BREAKING**: Drop tests for Clojure 1.9, run tests with 1.10 & 1.11
* NEW option `:meta-merge` on a router for custom merge strategy on route data
* Swagger: support operationId in generated swagger json [#452](https://github.com/metosin/reitit/pull/452) & [#569](https://github.com/metosin/reitit/pull/569)
* Update documentation and link to the startrek project [#578](https://github.com/metosin/reitit/pull/578)
* Upgrade jackson for CVE-2022-42003 and CVE-2022-42004 [#577](https://github.com/metosin/reitit/pull/577)
* Improved coercion errors perf [#576](https://github.com/metosin/reitit/pull/576)
* Add example for Reitit + Pedestal + Malli coercion [#572](https://github.com/metosin/reitit/pull/572)
* Handle empty seq as empty string in query-string [#566](https://github.com/metosin/reitit/pull/566)
* Polish pedestal chains when printing context diffs [#557](https://github.com/metosin/reitit/pull/557)
* Updated dependencies:
```clojure
[metosin/ring-swagger-ui "4.15.5"] is available but we use "4.3.0"
[metosin/jsonista "0.3.7"] is available but we use "0.3.5"
[metosin/malli "0.10.1"] is available but we use "0.8.2"
[fipp "0.6.26"] is available but we use "0.6.25"
[ring/ring-core "1.9.6"] is available but we use "1.9.5"
```
## 0.5.18 (2022-04-05)
* FIX [#334](https://github.com/metosin/reitit/pull/334) - Frontend: there is no way to catch the exception if coercion fails (via [#549](https://github.com/metosin/reitit/pull/549))

View file

@ -184,6 +184,6 @@ Roadmap is mostly written in [issues](https://github.com/metosin/reitit/issues).
## License
Copyright © 2017-2021 [Metosin Oy](http://www.metosin.fi)
Copyright © 2017-2023 [Metosin Oy](http://www.metosin.fi)
Distributed under the Eclipse Public License, the same as Clojure.

View file

@ -3,7 +3,7 @@
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 `{}`)
@ -11,7 +11,7 @@ Routers can be configured via options. The following options are available for t
| `: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
| `: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

View file

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

View file

@ -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,8 +154,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 opts]
(let [opts (impl/meta-merge {:compile compile-result} opts opts)]
(r/router data opts))))
(defn interceptor-handler [router]

View file

@ -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,8 +137,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 opts]
(let [opts (impl/meta-merge {:compile compile-result} opts opts)]
(r/router data opts))))
(defn middleware-handler [router]

View file

@ -9,8 +9,7 @@
[fipp.engine]
[fipp.visit]
[reitit.exception :as exception]
[spell-spec.expound] ;; expound
))
[spell-spec.expound])) ;; expound
;;
;; colors

View file

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

View file

@ -1,6 +1,5 @@
(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]])
[reitit.core :as r]
@ -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))))

View file

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

View file

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

View file

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

View file

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

View file

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

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,9 +574,9 @@
{: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"
: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)))

View file

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

View file

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