Add support for default values

This commit is contained in:
Tommi Reiman 2019-12-30 22:58:05 +02:00
parent 5df07ea0cf
commit 91a2945578
2 changed files with 13 additions and 5 deletions

View file

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

View file

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