hello! is there some builtin middleware that will keywordize params map for data coming from forms?
yep, this should happen by default. E.g. the starter app has keywordized params here: https://github.com/jacobobryant/biff/blob/1570ccc694c610422d70f4b63eeaa2ba456889ac/starter/src/com/example/app.clj#L16 are they not being keywordized for you?
for some reason no:
(defn create-comm [{:keys [session params] :as req}]
(println "params" (pr-str params))
...
;; params {:__anti-forgery-token "...", "comm/title" "wertgw", "comm/category" "letter", "comm/content" "etrghrtyj"}params are from a biff/form POST, with input field names like "comm/content"
Oh yeah, I think the keywordization only runs for "simple" keys for some reason, not ones with namespaces.
I just went spelunking through the middleware and found that this is the middleware which handles the keywordization: https://github.com/ring-clojure/ring/blob/f7dfe7c9b98c335e4573e61d94c523d5df9a6667/ring-core/src/ring/middleware/keyword_params.clj#L37
Given that (and https://github.com/ring-clojure/ring-defaults/blob/52a5b9e50cd64da9d92f84219f8b6240e5500002/src/ring/middleware/defaults.clj#L112), you should be able to update https://github.com/jacobobryant/biff/blob/1570ccc694c610422d70f4b63eeaa2ba456889ac/starter/src/com/example/middleware.clj#L42 to include a (-> rd/site-defaults (assoc-in [:params :keywordize :parse-namespaces?] true) ...) .
thanks! the rabbit hole isn't that deep when one knows their shit! 😄
if anybody stumbles across, the assoc might fail if keywordize parameter exists and is a bool, this works instead:
(assoc-in [:params :keywordize] {:parse-namespaces? true})ah yes, that's the way