reitit

dominic 2025-01-08T16:27:25.393419Z

Hi there - from the docs / reading the code I think the answer is no, but just in case: Is it possible to create a reitit http router (not ring) that accepts interceptors as the handlers rather than ring-style request->response functions? My use case is wanting to replace the router in code that currently uses Pedestal and has all the handlers implemented as interceptors without having to rewrite the handlers (and handle the fact that many of them expect the full context to be available rather than just the request). Thanks!

ikitommi 2025-01-08T20:05:18.739099Z

With http-router, :handler gets coerced into interceptor using reitit.interceptor/IntoInterceptor protocol. Function is mapped to ring-style req-res thing, but just use anything else and it should just work.

ikitommi 2025-01-08T20:05:41.195849Z

(let [app (http/ring-handler
           (http/router
            ["/" {:handler {:enter #(assoc % :response {:status 200, :body "fine"})}}])
           nil
           {:executor sieppari/executor})]
  (app {:request-method :get, :uri "/"}))
; => {:status 200, :body "fine"}

ikitommi 2025-01-08T20:06:32.032609Z

not sure if that is what you asked thou 🙂

dominic 2025-01-09T08:49:22.187279Z

Huh - when I tried I got some errors about interceptors not conforming to IntoInterceptor protocol I think 🤔 - I’ll have another look, thanks

dominic 2025-01-10T10:47:25.307169Z

Thanks a lot for the response and making me look at it again, turns out some of the interceptors were pedestal Interceptor records rather than just maps which is why IntoInterceptor was failing picard-facepalm

gtbono 2025-01-08T18:17:37.343289Z

folks, I have the following plumatic schema:

;; (s/defschema BirthdayRequest (st/open-schema {:name s/Str
;;                                 :birthday s/Str}))
which is an open schema so my request body is a tolerant reader, and it is added this way into reitit router
;; [["/birthday"
;; {:post {:parameters {:body requests.birthday/BirthdayRequest}
;;         :handler birthday-add-handler}}]
but on swagger, I get the following as the request body schema, with additional parameters that I didn't want to document (as in the image) how should I define my schema so there additional properties aren't generated?

opqdonut 2025-01-09T05:41:27.501999Z

FYI, those additionalProp keys are added by swagger ui, they're not inserted into the swagger.json by reitit

opqdonut 2025-01-09T05:41:49.617259Z

not sure what's the easiest way to avoid that...

gtbono 2025-01-08T18:20:21.424299Z

also, if my response returns a status code of 204 with no parameters, if I define the response as follows:

["/birthday/delete/{birthday-id}"
      {:delete {:parameters {:path {:birthday-id s/Uuid}}
                :responses {204 {:body nil}
it shows as "string" on the response, how do I make not show anything?

opqdonut 2025-01-09T05:49:42.841459Z

try 204 {} instead

gtbono 2025-01-09T15:30:05.873389Z

didn't work, same thing apparently 😕