Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion test/compojure/api/coercion_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"}))) )