diff --git a/src/compojure/api/meta.clj b/src/compojure/api/meta.clj index 8efa3e5e..fb7e8351 100644 --- a/src/compojure/api/meta.clj +++ b/src/compojure/api/meta.clj @@ -382,14 +382,13 @@ form `(~body-wrap ~@body) form (if (seq letks) `(letk ~letks ~form) form) form (if (seq lets) `(let ~lets ~form) form) - form (if (seq middleware) - `(let [wrap-mw# (mw/compose-middleware ~middleware)] - ((wrap-mw# (fn [~arg] ~form)) ~arg)) - form) - form (if (seq pre-lets) `(let ~pre-lets ~form) form) form (if routes `(compojure.core/context ~path ~arg-with-request ~form) (compojure.core/compile-route method path arg-with-request (list form))) + form (if (seq middleware) + `(compojure.core/wrap-routes ~form (mw/compose-middleware ~middleware)) + form) + form (if (seq pre-lets) `(let ~pre-lets ~form) form) ;; for routes, create a separate lookup-function to find the inner routes child-form (if routes diff --git a/test/compojure/api/coercion_test.clj b/test/compojure/api/coercion_test.clj index b7e72d2d..8adc119b 100644 --- a/test/compojure/api/coercion_test.clj +++ b/test/compojure/api/coercion_test.clj @@ -138,4 +138,12 @@ (app {:request-method :get :uri "/api/ping" :query-params {:x "abba"}}) => (contains {:body ["abba" 0]}) (app {:request-method :get :uri "/api/ping" :query-params {:x "1"}}) => (contains {:body ["1" 0]}) (app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y 2}}) => (contains {:body ["1" 2]}) - (app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y "abba"}}) => throws))) + (app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y "abba"}}) => throws)) + + (fact "context coercion is used for subroutes" + (let [app (context "/api" [] + :coercion (constantly nil) + (GET "/ping" [] + :query-params [x :- Long] + (ok x)))] + (app {:request-method :get :uri "/api/ping" :query-params {:x "abba"}}) => (contains {:body "abba"}))) )