Skip to content

Commit 2fe4892

Browse files
committed
Merge pull request #214 from metosin/coercion-context
Coercion context
2 parents ecf2a04 + 79de230 commit 2fe4892

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/compojure/api/meta.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,13 @@
382382
form `(~body-wrap ~@body)
383383
form (if (seq letks) `(letk ~letks ~form) form)
384384
form (if (seq lets) `(let ~lets ~form) form)
385-
form (if (seq middleware)
386-
`(let [wrap-mw# (mw/compose-middleware ~middleware)]
387-
((wrap-mw# (fn [~arg] ~form)) ~arg))
388-
form)
389-
form (if (seq pre-lets) `(let ~pre-lets ~form) form)
390385
form (if routes
391386
`(compojure.core/context ~path ~arg-with-request ~form)
392387
(compojure.core/compile-route method path arg-with-request (list form)))
388+
form (if (seq middleware)
389+
`(compojure.core/wrap-routes ~form (mw/compose-middleware ~middleware))
390+
form)
391+
form (if (seq pre-lets) `(let ~pre-lets ~form) form)
393392

394393
;; for routes, create a separate lookup-function to find the inner routes
395394
child-form (if routes

test/compojure/api/coercion_test.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,12 @@
138138
(app {:request-method :get :uri "/api/ping" :query-params {:x "abba"}}) => (contains {:body ["abba" 0]})
139139
(app {:request-method :get :uri "/api/ping" :query-params {:x "1"}}) => (contains {:body ["1" 0]})
140140
(app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y 2}}) => (contains {:body ["1" 2]})
141-
(app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y "abba"}}) => throws)))
141+
(app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y "abba"}}) => throws))
142+
143+
(fact "context coercion is used for subroutes"
144+
(let [app (context "/api" []
145+
:coercion (constantly nil)
146+
(GET "/ping" []
147+
:query-params [x :- Long]
148+
(ok x)))]
149+
(app {:request-method :get :uri "/api/ping" :query-params {:x "abba"}}) => (contains {:body "abba"}))) )

0 commit comments

Comments
 (0)