This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-18
Channels
- # announcements (10)
- # babashka (21)
- # beginners (99)
- # biff (66)
- # catalyst (3)
- # cherry (1)
- # cider (11)
- # clojure (38)
- # clojure-austin (3)
- # clojure-dev (23)
- # clojure-europe (21)
- # clojure-hungary (10)
- # clojure-nl (2)
- # clojure-norway (57)
- # clojure-uk (2)
- # clojurescript (9)
- # cursive (6)
- # fulcro (5)
- # hyperfiddle (14)
- # integrant (4)
- # introduce-yourself (3)
- # lsp (24)
- # off-topic (14)
- # reagent (12)
- # reitit (13)
- # releases (8)
- # sci (16)
- # shadow-cljs (8)
- # solo-full-stack (1)
- # spacemacs (5)
- # squint (3)
- # xtdb (14)
that sounds like a better plan, yeah
If you’ve got some routes, are there any helpers to add standard responses + schemas e.g. 400 bad request, to all the routes?
I guess it’s just data so I can use normal clojure functions, just wondering if there’s some helpers
I couldn't find any helpers so that's what I ended up doing (though I used specter's transform instead). This is what I did in case it is helpful for you
(defn add-bad-request-response
"Adds bad-request error schema to response docs for routes that may have coercion errors"
[[route-uri route-data]]
[route-uri
(transform [(submap [:post :put :patch]) MAP-VALS :responses]
#(merge {bad-request {:body schemas/ErrorResponseSchema}} %)
route-data)])
(defn routes
[component]
(let [flattened-base-routes (reitit/routes (ring/router (base-routes component)))]
(map add-bad-request-response flattened-base-routes))
Nice, yep I’ll do something similar then, thanks so much for the comment!
No problem 👍
This is really for the docs, but for authenticated routes, I want to add 401 and 403 as responses, and for all routes 400 as incorrect.
The last one is a default handler (optional argument) The first two can be done via middlewares probably, no need for transformation In which cases do you want to return those codes?
I’m generating the docs using the new openapi feature, so as far as I understand the data needs to be there, for the open api middleware to work. I’ve got things working with the data transformation now, but I might be doing things not quite right.