diff --git a/modules/reitit-malli/src/reitit/coercion/malli.cljc b/modules/reitit-malli/src/reitit/coercion/malli.cljc index 89f2618f..1b596c60 100644 --- a/modules/reitit-malli/src/reitit/coercion/malli.cljc +++ b/modules/reitit-malli/src/reitit/coercion/malli.cljc @@ -16,15 +16,19 @@ (def string-transformer (mt/transformer mt/strip-extra-keys-transformer - mt/string-transformer)) + mt/string-transformer + mt/default-value-transformer)) (def json-transformer (mt/transformer mt/strip-extra-keys-transformer - mt/json-transformer)) + mt/json-transformer + mt/default-value-transformer)) (def default-transformer - mt/strip-extra-keys-transformer) + (mt/transformer + mt/strip-extra-keys-transformer + mt/default-value-transformer)) ;; TODO: are these needed? (defmulti coerce-response? identity :default ::default) @@ -107,7 +111,7 @@ :response {:default default-transformer :formats {"application/json" json-transformer}}} ;; set of keys to include in error messages - :error-keys #{:type :coercion :in #_:schema #_:value :errors :humanized #_:transformed} + :error-keys #{:type :coercion :in :schema :value :errors :humanized #_:transformed} ;; malli options :options nil}) diff --git a/test/cljc/reitit/ring_coercion_test.cljc b/test/cljc/reitit/ring_coercion_test.cljc index 73b3d338..c4f69583 100644 --- a/test/cljc/reitit/ring_coercion_test.cljc +++ b/test/cljc/reitit/ring_coercion_test.cljc @@ -207,7 +207,7 @@ ["/plus/:e" {:get {:parameters {:query [:map [:a {:optional true} int?]] :body [:map [:b int?]] - :form [:map [:c int?]] + :form [:map [:c [int? {:default 3}]]] :header [:map [:d int?]] :path [:map [:e int?]]} :responses {200 {:body [:map [:total pos-int?]]} @@ -230,6 +230,10 @@ (is (= {:status 200 :body {:total 15}} (app valid-request3))) + (testing "default values work" + (is (= {:status 200 + :body {:total 15}} + (app (update valid-request3 :form-params dissoc :c))))) (is (= {:status 500 :body {:evil true}} (app (assoc-in valid-request1 [:query-params "a"] "666")))))