mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
Add support for default values
This commit is contained in:
parent
5df07ea0cf
commit
91a2945578
2 changed files with 13 additions and 5 deletions
|
|
@ -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})
|
||||
|
||||
|
|
|
|||
|
|
@ -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")))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue