mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Fix #407
This commit is contained in:
parent
28962e75df
commit
a2d8208600
1 changed files with 18 additions and 0 deletions
|
|
@ -199,11 +199,22 @@
|
|||
(let [{:keys [status]} (app invalid-request2)]
|
||||
(is (= 500 status))))))))
|
||||
|
||||
(def or-maps-schema
|
||||
[:or [:map [:x int?]] [:map [:y int?]]])
|
||||
|
||||
(deftest malli-coercion-test
|
||||
(let [create (fn [middleware]
|
||||
(ring/ring-handler
|
||||
(ring/router
|
||||
["/api"
|
||||
|
||||
["/or" {:post {:summary "accepts either of two map schemas"
|
||||
:parameters {:body or-maps-schema}
|
||||
:responses {200 {:body [:map [:msg string?]]}}
|
||||
:handler (fn [{{{:keys [x]} :body} :parameters}]
|
||||
{:status 200
|
||||
:body {:msg (if x "you sent x" "you sent y")}})}}]
|
||||
|
||||
["/plus/:e" {:get {:parameters {:query [:map [:a {:optional true} int?]]
|
||||
:body [:map [:b int?]]
|
||||
:form [:map [:c [int? {:default 3}]]]
|
||||
|
|
@ -254,6 +265,13 @@
|
|||
rrc/coerce-request-middleware
|
||||
rrc/coerce-response-middleware])]
|
||||
|
||||
(testing "or #407"
|
||||
(is (= {:status 200
|
||||
:body {:msg "you sent x"}}
|
||||
(app {:uri "/api/or"
|
||||
:request-method :post
|
||||
:body-params {:x 1}}))))
|
||||
|
||||
(testing "all good"
|
||||
(is (= {:status 200
|
||||
:body {:total 15}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue