This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-07
Channels
- # babashka (31)
- # babashka-sci-dev (10)
- # beginners (64)
- # biff (11)
- # clerk (5)
- # cljdoc (2)
- # clojure (84)
- # clojure-boston (3)
- # clojure-conj (2)
- # clojure-europe (11)
- # data-science (19)
- # datomic (118)
- # fulcro (3)
- # graalvm (3)
- # hoplon (6)
- # inf-clojure (146)
- # instaparse (5)
- # lsp (13)
- # malli (3)
- # off-topic (13)
- # pedestal (5)
- # proletarian (5)
- # re-frame (14)
- # reitit (12)
- # releases (1)
- # ring (19)
- # scittle (2)
- # shadow-cljs (155)
- # slack-help (3)
I have an endpoint expecting a Mailli schema of [:vector string?]
, but when a single item is provided in the query string, it is parsed as a single string. For example, var=str1
gives "str1"
instead of ["str1"]
Is there a fix? Obviously it's breaking whenever var
is a vector of 1 item. 😕
Presuming you are using the default ring middleware, and want to use e.g. ?foo=1&foo=2
for multiple query string values, you can provide your own decode function to wrap a single string to vector.
:decode/string (fn [v] (if (string? v) [v] v))
(in the vector schema)
Thanks!
I have also been struggling with this! Would be great to see how you implement this @U0ERZQ1K2
An example should be added somewhere
Unfortunately the Reitit examples folder is such a mess currently it is quite a hard to add anything there
Hmm... I'm still getting errors. Is this how the declaration is expected?
[:vector [string? {:decode/string #(if (string? %) [%] %)}]]
You need to decode the string to vector
[:vector {:decode/string #(if (string? %) [%] %)} :string]
If you have the decode fn on string schema, coercion fails on :vector
level and the children decode fn is never called
So happy I pinned this thread - I needed a vector query string now and this worked perfect. Thank you for raising the question @U0ERZQ1K2 and answering it @U061V0GG2 If someone else stumbles upon this, here is the complete parameters declaration
:parameters {:query [:map [:foo [:vector {:decode/string #(if (string? %) [%] %)} :string]]]}