From fbff819909dd8a6b325678f1ed5c49b1f5d8034f Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Sat, 26 Sep 2020 12:11:14 +0300 Subject: [PATCH] update deps --- .gitignore | 1 + CHANGELOG.md | 24 +++++++++++++++++ .../ring-malli-swagger/src/example/server.clj | 19 -------------- .../src/reitit/coercion/malli.cljc | 7 +++-- project.clj | 26 +++++++++---------- test/cljc/reitit/ring_coercion_test.cljc | 7 ++++- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 15461851..e0b0772e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ pom.xml.asc /_book figwheel_server.log /.idea +.clj-kondo \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 309e0443..87665452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,30 @@ We use [Break Versioning][breakver]. The version numbers follow a `. {:status 400, :body {:errors {:x ["missing required key"]}}} +``` + ## 0.5.5 (2020-07-15) * recompile with Java8 diff --git a/examples/ring-malli-swagger/src/example/server.clj b/examples/ring-malli-swagger/src/example/server.clj index 1339b38c..1a5d7d89 100644 --- a/examples/ring-malli-swagger/src/example/server.clj +++ b/examples/ring-malli-swagger/src/example/server.clj @@ -18,19 +18,6 @@ [clojure.java.io :as io] [malli.util :as mu])) -(def sample-request - [:map {:registry {::age [:and int? [:> 18]]}} - [:age ::age]]) - -(malli.core/accept - (malli.core/schema sample-request) - (malli.core/schema-visitor identity)) - -(defn handle [request] - (prn (:parameters request)) - {:status 200 - :body {:status "ok"}}) - (def app (ring/ring-handler (ring/router @@ -67,12 +54,6 @@ ["/math" {:swagger {:tags ["math"]}} - ["/api/v1/overview" - {:swagger {:tags ["Overview"]} - :post {:summary "get an overview data" - :parameters {:body sample-request} - :handler handle}}] - ["/plus" {:get {:summary "plus with malli query parameters" :parameters {:query [:map [:x int?] [:y int?]]} diff --git a/modules/reitit-malli/src/reitit/coercion/malli.cljc b/modules/reitit-malli/src/reitit/coercion/malli.cljc index 1ea9951e..23ec65b9 100644 --- a/modules/reitit-malli/src/reitit/coercion/malli.cljc +++ b/modules/reitit-malli/src/reitit/coercion/malli.cljc @@ -123,6 +123,8 @@ :strip-extra-keys true ;; add/set default values :default-values true + ;; encode-error + :encode-error nil ;; malli options :options nil}) @@ -130,7 +132,7 @@ ([] (create nil)) ([opts] - (let [{:keys [transformers compile options error-keys] :as opts} (merge default-options opts) + (let [{:keys [transformers compile options error-keys encode-error] :as opts} (merge default-options opts) show? (fn [key] (contains? error-keys key)) transformers (walk/prewalk #(if (satisfies? TransformationProvider %) (-transformer % opts) %) transformers)] ^{:type ::coercion/coercion} @@ -171,7 +173,8 @@ (show? :schema) (update :schema edn/write-string opts) (show? :errors) (-> (me/with-error-messages opts) (update :errors (partial map #(update % :schema edn/write-string opts)))) - (seq error-keys) (select-keys error-keys))) + (seq error-keys) (select-keys error-keys) + encode-error (encode-error))) (-request-coercer [_ type schema] (-coercer (compile schema options) type transformers :decode nil opts)) (-response-coercer [_ schema] diff --git a/project.clj b/project.clj index 8daa1f5b..0b753abd 100644 --- a/project.clj +++ b/project.clj @@ -28,16 +28,16 @@ [metosin/reitit-sieppari "0.5.5"] [metosin/reitit-pedestal "0.5.5"] [metosin/ring-swagger-ui "3.25.3"] - [metosin/spec-tools "0.10.3"] + [metosin/spec-tools "0.10.4"] [metosin/schema-tools "0.12.2"] [metosin/muuntaja "0.6.7"] - [metosin/jsonista "0.2.6"] + [metosin/jsonista "0.2.7"] [metosin/sieppari "0.0.0-alpha13"] - [metosin/malli "0.0.1-20200715.082439-21"] + [metosin/malli "0.0.1-20200924.063109-27"] ;; https://clojureverse.org/t/depending-on-the-right-versions-of-jackson-libraries/5111 - [com.fasterxml.jackson.core/jackson-core "2.11.0"] - [com.fasterxml.jackson.core/jackson-databind "2.11.0"] + [com.fasterxml.jackson.core/jackson-core "2.11.2"] + [com.fasterxml.jackson.core/jackson-databind "2.11.2"] [meta-merge "1.0.0"] [fipp "0.6.23" :exclusions [org.clojure/core.rrb-vector]] @@ -52,7 +52,7 @@ ;[lein-virgil "0.1.7"] [lein-doo "0.1.11"] [lein-cljsbuild "1.1.8"] - [lein-cloverage "1.1.2"] + [lein-cloverage "1.2.1"] [lein-codox "0.10.7"] [metosin/bat-test "0.4.4"]] @@ -82,10 +82,10 @@ ;; modules dependencies [metosin/schema-tools "0.12.2"] - [metosin/spec-tools "0.10.3"] + [metosin/spec-tools "0.10.4"] [metosin/muuntaja "0.6.7"] [metosin/sieppari] - [metosin/jsonista "0.2.6"] + [metosin/jsonista "0.2.7"] [metosin/malli] [lambdaisland/deep-diff "0.0-47"] [meta-merge "1.0.0"] @@ -93,7 +93,7 @@ [expound "0.8.5"] [fipp "0.6.23"] - [orchestra "2019.02.06-1"] + [orchestra "2020.09.18-1"] [ring "1.8.1"] [ikitommi/immutant-web "3.0.0-alpha1"] @@ -101,13 +101,13 @@ [metosin/ring-swagger-ui "3.25.3"] [criterium "0.4.6"] - [org.clojure/test.check "1.0.0"] + [org.clojure/test.check "1.1.0"] [org.clojure/tools.namespace "1.0.0"] [com.gfredericks/test.chuck "0.2.10"] [io.pedestal/pedestal.service "0.5.8"] - [org.clojure/core.async "1.2.603"] + [org.clojure/core.async "1.3.610"] [manifold "0.1.8"] [funcool/promesa "5.1.0"] @@ -120,13 +120,13 @@ "-Xmx4096m" "-Dclojure.compiler.direct-linking=true"] :test-paths ["perf-test/clj"] - :dependencies [[compojure "1.6.1"] + :dependencies [[compojure "1.6.2"] [ring/ring-defaults "0.3.2"] [ikitommi/immutant-web "3.0.0-alpha1"] [io.pedestal/pedestal.service "0.5.8"] [io.pedestal/pedestal.jetty "0.5.8"] [calfpath "0.7.2"] - [org.clojure/core.async "1.2.603"] + [org.clojure/core.async "1.3.610"] [manifold "0.1.8"] [funcool/promesa "5.1.0"] [metosin/sieppari] diff --git a/test/cljc/reitit/ring_coercion_test.cljc b/test/cljc/reitit/ring_coercion_test.cljc index e6294eb9..3e38029e 100644 --- a/test/cljc/reitit/ring_coercion_test.cljc +++ b/test/cljc/reitit/ring_coercion_test.cljc @@ -255,7 +255,7 @@ {:data {:middleware middleware :coercion malli/coercion}})))] - (testing "withut exception handling" + (testing "without exception handling" (let [app (create [rrc/coerce-request-middleware rrc/coerce-response-middleware])] @@ -394,6 +394,11 @@ (is (= {:status 200, :body {:x 1, :request true, :response true}} (app (->request "open"))))))) + (testing "encoding errors" + (let [app (->app {:encode-error (fn [error] {:errors (:humanized error)})})] + (is (= {:status 400, :body {:errors {:x ["missing required key"]}}} + (app (assoc (->request "closed") :body-params {})))))) + (testing "when schemas are not closed and extra keys are not stripped" (let [app (->app {:compile (fn [v _] v) :strip-extra-keys false})] (testing "default: keys are NOT stripped"