Works by default with Muuntaja

This commit is contained in:
Tommi Reiman 2018-07-16 15:57:12 +03:00
parent 346fbad775
commit 0f03d0786c
2 changed files with 3 additions and 10 deletions

View file

@ -4,15 +4,11 @@
[reitit.middleware :as middleware] [reitit.middleware :as middleware]
[reitit.ring.coercion :as rrc])) [reitit.ring.coercion :as rrc]))
;; unlift Middleware Record into vanilla Ring middlewareL ;; unlift Middleware Record into vanilla Ring middleware
;; NOTE: to support format-based body coercion, an options map needs
;; to be set with :extract-request-format and extract-response-format
(defn wrap-coercion [handler resource] (defn wrap-coercion [handler resource]
(middleware/chain (middleware/chain
[rrc/coerce-exceptions-middleware [rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware rrc/coerce-request-middleware
rrc/coerce-response-middleware] rrc/coerce-response-middleware]
handler handler
resource resource))
{:extract-request-format (comp :format :muuntaja/request)
:extract-response-format (comp :format :muuntaja/response)}))

View file

@ -69,10 +69,7 @@
"application/transit+json"} "application/transit+json"}
:consumes #{"application/json" :consumes #{"application/json"
"application/edn" "application/edn"
"application/transit+json"}}} "application/transit+json"}}}})
;; TODO: these should work by default!
:extract-request-format (comp :format :muuntaja/request)
:extract-response-format (comp :format :muuntaja/response)})
(ring/routes (ring/routes
(swagger-ui/create-swagger-ui-handler (swagger-ui/create-swagger-ui-handler
{:path "/", :url "/api/swagger.json"}) {:path "/", :url "/api/swagger.json"})