This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-27
Channels
- # aws (19)
- # babashka (47)
- # beginners (111)
- # boot (3)
- # bristol-clojurians (3)
- # chlorine-clover (2)
- # cider (13)
- # cljs-dev (8)
- # clojure (143)
- # clojure-europe (11)
- # clojure-germany (10)
- # clojure-italy (3)
- # clojure-losangeles (1)
- # clojure-nl (1)
- # clojure-spec (6)
- # clojure-survey (3)
- # clojure-uk (42)
- # clojurescript (229)
- # conjure (131)
- # cursive (21)
- # data-science (18)
- # datomic (4)
- # emacs (21)
- # events (2)
- # figwheel-main (12)
- # fulcro (18)
- # graalvm (1)
- # hoplon (40)
- # jobs (1)
- # joker (17)
- # kaocha (1)
- # lambdaisland (1)
- # off-topic (19)
- # rdf (7)
- # re-frame (31)
- # reagent (26)
- # reitit (20)
- # rum (4)
- # shadow-cljs (106)
- # sql (17)
- # testing (5)
- # vim (2)
@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.
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
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"}}
@ikitommi thank you so much! I hope this n^2 performance problem didn’t didn’t give you nightmares
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.