This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-18
Channels
- # architecture (33)
- # asami (1)
- # aws (1)
- # babashka (19)
- # beginners (48)
- # bristol-clojurians (1)
- # calva (5)
- # cider (12)
- # cljdoc (15)
- # cljsrn (7)
- # clojure (151)
- # clojure-europe (19)
- # clojure-losangeles (1)
- # clojure-nl (2)
- # clojure-provo (4)
- # clojure-spec (9)
- # clojure-uk (21)
- # clojuredesign-podcast (28)
- # clojurescript (33)
- # core-typed (1)
- # cryogen (2)
- # css (6)
- # cursive (10)
- # data-science (1)
- # datomic (20)
- # events (3)
- # expound (72)
- # figwheel-main (5)
- # fulcro (43)
- # graalvm (6)
- # helix (1)
- # kaocha (13)
- # leiningen (2)
- # malli (1)
- # meander (93)
- # membrane (4)
- # off-topic (17)
- # pathom (6)
- # portland-or (5)
- # re-frame (25)
- # reagent (6)
- # reitit (7)
- # reveal (30)
- # shadow-cljs (25)
- # vim (2)
Hey there, I am new to using reitit and am wondering about how to handle error responses when using swagger. That is, I want specify a response such as
400 {:body {:code s/Int
:message s/Str}}
so that it appears in Swagger, but when some data comes in and doesn't validate against the schema in the :parameters
map, it seems that the issue occurs higher up the middleware chain - so I am looking for a way for this to be a part of the swagger documentation for every route my middleware is applied to, as opposed to specifying it manually in the :responses
map for every route. Is there a simple way to do this?Hmm, not sure I totally grok your question -- are you saying you want to describe a generic 400 response on a subset of routes, without manually adding that description to each route?
ie. if I apply my middleware to some routes, every route I apply it to will have that 400 response added to its swagger documentation
Ah, so I think conceptually what you want is for the 400 response to end up as data on each endpoint -- that's how it gets picked up by swagger. So this is the general problem of "how do I add data to a subset of endpoints". I think there are a few way to do this, and someone probably knows more than I do 🙂 One question first -- how are you selectively applying your middleware to those routes? Since data is applied recursively with meta-merge, you may be able to add the :response
data at the same "level" of the route tree at which you're applying your middleware, and it will propagate down to the leaves.
hmmm... Currently I just apply it to each route, but I guess I could apply it to groups. Thanks
Honestly I wouldn't mind just putting that schema manually in each response map, I just wanted to make sure there wasn't a better way or obvious thing I missed before going ahead and doing it