Fork me on GitHub
Max Anderson03:11:56

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 Russell17:11:15

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?

Max Anderson18:11:15

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 Russell21:11:53

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.

Max Anderson22:11:40

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

Max Anderson22:11:08

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