reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
2020-11-18T03:34:56.343100Z

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?

Dave Russell 2020-11-18T17:52:15.343200Z

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?

2020-11-18T18:37:32.343500Z

yep!

2020-11-18T18:38:15.343700Z

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

Dave Russell 2020-11-18T21:49:53.344Z

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.

2020-11-18T22:28:40.344200Z

hmmm... Currently I just apply it to each route, but I guess I could apply it to groups. Thanks

2020-11-18T22:29:08.344400Z

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