@manutter51 Thanks! I will look into it. 🙂
Anyone using reitit with pedestal + coercions? I’m not getting any exceptions when my route’s params type’s mismatch
I have an endpoint that downloads an excel file. For testing purposes, here is the handler:
(defn download-handler [_request]
(let [file "book.xlsx"]
(-> (file-response file)
(content-type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
(header "Content-Disposition" (str "attachment;filename=" (gensym "book") ".xlsx")))))
This is invoked with the following router and handler:
(def router
(ring/router
[["/download" {:get download-handler
:summary "downloads an xlsx file"
:swagger {:produces ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]}}]
["" {:no-doc true}
["/swagger.json"
{:get {:no-doc true
:swagger {:info {:title "Download API"}
:basePath "/"}
:handler (swagger/create-swagger-handler)}}]
["/api-docs*" {:get (swagger-ui/create-swagger-ui-handler {:url "/swagger.json"})}]]]
{:data {:coercion rc-spec/coercion
:middleware [params/wrap-params
middleware/wrap-format
parameters/parameters-middleware
muuntaja/format-negotiate-middleware
muuntaja/format-response-middleware
exception/exception-middleware
muuntaja/format-request-middleware
coercion/coerce-response-middleware
coercion/coerce-request-middleware
multipart/multipart-middleware]}}))
(def handler
(ring/ring-handler
router
(constantly (not-found "Not found"))))
When I invoked the download endpoint directly (just putting http://localhost:3000/download) it works as expected in the browser. When I use the generated Swagger UI I get the "Try it out!" button for the endpoint, which I press. It then gives me a link (e.g. <blob:http://localhost:3000/50986c29-ba76-4acb-a022-c121aca29157|Download book6651.xlsx>). When I click the link and download the file it somehow changes the file. The file is larger and is not openable by Excel. Any idea what's going on or how I fix it?If anyone cares to check this out, I've created a spike solution at https://github.com/markbastian/download-xlsx. I've added both lein and tools.deps support.