mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
parent
ada41ec7dd
commit
f0fc440425
3 changed files with 19 additions and 3 deletions
|
|
@ -181,7 +181,10 @@
|
||||||
|
|
||||||
(defn response-coercers [coercion responses opts]
|
(defn response-coercers [coercion responses opts]
|
||||||
(some->> (for [[status model] responses]
|
(some->> (for [[status model] responses]
|
||||||
[status (response-coercer coercion model opts)])
|
(do
|
||||||
|
(when-not (int? status)
|
||||||
|
(throw (ex-info "Response status must be int" {:status status})))
|
||||||
|
[status (response-coercer coercion model opts)]))
|
||||||
(filter second) (seq) (into {})))
|
(filter second) (seq) (into {})))
|
||||||
|
|
||||||
(defn -compile-parameters [data coercion]
|
(defn -compile-parameters [data coercion]
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
[reitit.ring.coercion]
|
[reitit.ring.coercion]
|
||||||
[reitit.ring.middleware.exception :as exception]
|
[reitit.ring.middleware.exception :as exception]
|
||||||
[ring.util.http-response :as http-response])
|
[ring.util.http-response :as http-response])
|
||||||
(:import (java.sql SQLException SQLWarning)))
|
(:import (clojure.lang ExceptionInfo)
|
||||||
|
(java.sql SQLException SQLWarning)))
|
||||||
|
|
||||||
(derive ::kikka ::kukka)
|
(derive ::kikka ::kukka)
|
||||||
|
|
||||||
|
|
@ -190,3 +191,15 @@
|
||||||
(is (contains? problems ::s/spec))
|
(is (contains? problems ::s/spec))
|
||||||
(is (contains? problems ::s/value))
|
(is (contains? problems ::s/value))
|
||||||
(is (contains? problems ::s/problems))))))))
|
(is (contains? problems ::s/problems))))))))
|
||||||
|
|
||||||
|
(deftest response-keys-test
|
||||||
|
(is (thrown-with-msg?
|
||||||
|
ExceptionInfo
|
||||||
|
#"Response status must be int"
|
||||||
|
(ring/ring-handler
|
||||||
|
(ring/router
|
||||||
|
[["/coercion"
|
||||||
|
{:middleware [reitit.ring.coercion/coerce-response-middleware]
|
||||||
|
:coercion reitit.coercion.spec/coercion
|
||||||
|
:responses {:200 {:body {:total pos-int?}}}
|
||||||
|
:handler identity}]])))))
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@
|
||||||
(ring/router
|
(ring/router
|
||||||
["/api"
|
["/api"
|
||||||
["/plus/:e"
|
["/plus/:e"
|
||||||
{:get {:responses {"200" {}}
|
{:get {:responses {200 {:description 1}}
|
||||||
:handler identity}}]]
|
:handler identity}}]]
|
||||||
{:data {:middleware [rrc/coerce-exceptions-middleware
|
{:data {:middleware [rrc/coerce-exceptions-middleware
|
||||||
rrc/coerce-request-middleware
|
rrc/coerce-request-middleware
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue