@mkvlr fixed the root cause, the path-splitting was done n^2 times, now just n times. For 100 routes, on JVM, it’s 200ms -> 13ms.
@marcus.akre there is no two-way mapping from swagger :consumes
and :produces
to muuntaja (the content-negotiation library). It only works one-way: setting the values to muuntaja will set the defaults for swagger. If you want to change the content-negotiation default to edn (and strip away support for other formats), you need to change the muuntaja config for the given routes.
Now it kind of works. 🙂 In the code below application/json must be kept because if not the swagger ui reports a parsing error. But it means that I still can request json with the accept header.
(def mun
(m/create
(m/select-formats
m/default-options
["application/edn", "application/json"])))
and to have default edn in swagger ui:
:swagger {:produces #{"application/edn"}
:consumes #{"application/edn"}}
here’s the config guide for muuntaja: https://cljdoc.org/d/metosin/muuntaja/0.6.6/doc/configuration
sorry, this could be much simpler, the could be reitit-level :consumes
and :produces
that both configurate the content-negotiation for the routes and set the swagger info.
OpenApi3 would give better tools for defining these, but not integrated into reitit yet. there is an issue of that, going to reitit 1.0.0
@ikitommi thank you so much! I hope this n^2 performance problem didn’t didn’t give you nightmares
no nightmares 🙂 a fun challenge.
❤️
thank you very much! 🙂 I will look into the muutaja config guide.
🖤
can unsurprisingly confirm that the PR makes our router creation a lot faster
hi, is there a way to remove blank query params, will i need a custom middleware for this ?
currently I am replacing a legacy api, and the forntend send query params with out values which my specs barf on, I would like to strip the blanks before spec processes them instead of modifying the specs to accept blanks
well I made a middleware, but seems the coercion runs before my middleware, as in if i modify parameters query and disable the coercion I can see they are removed. if I add in the coercion I can see that it errors on a parameter that should have been removed
(defn mw2 [handler]
(fn [request]
(handler
(assoc-in request [:parameters :query]
(reduce-kv
(fn [m k v]
(if (= "" v) m (assoc m k v)))
{}
(-> request :parameters :query))))))
Using this to filter out anything with ""I want to set up some client-side routing. Did this once before and it was extraordinarily complicated. Last time I placed a *
route on the backend which returned some empty html, and on the frontend I wrote https://pastebin.com/VVzn9NQT, which is just an intelligent way of hooking into goog.history.Html5History, but extremely brittle and complicated. Is there a better way to do this now?
I found this: https://github.com/metosin/reitit/blob/master/doc/frontend/browser.md
It talks about doing a *
route but that won't be possible the standard way since I've got a bunch of REST endpoints in the app.