This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-30
Channels
- # aleph (2)
- # announcements (8)
- # babashka (12)
- # beginners (34)
- # calva (36)
- # cherry (3)
- # cider (1)
- # clj-kondo (11)
- # clj-otel (6)
- # cljdoc (31)
- # clojure (121)
- # clojure-conj (1)
- # clojure-czech (2)
- # clojure-europe (109)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (3)
- # cursive (3)
- # datahike (1)
- # datomic (9)
- # deps-new (6)
- # docker (5)
- # emacs (21)
- # fulcro (4)
- # hoplon (16)
- # introduce-yourself (2)
- # london-clojurians (5)
- # lsp (87)
- # malli (17)
- # missionary (1)
- # nbb (27)
- # off-topic (257)
- # pathom (4)
- # portal (42)
- # practicalli (1)
- # rdf (3)
- # releases (2)
- # shadow-cljs (49)
- # slack-help (3)
- # timbre (2)
Is there a conventient way to recursively make all keys optional using mu/optional-keys
?
(defn make-all-keys-optional
"Recursively apply mu/optional-keys to map schemas"
[schema]
(m/walk
schema
(m/schema-walker
(fn [schema]
(if (= :map (m/type schema))
(mu/optional-keys schema)
schema)))))
Hi all, I have a question regarding Reitit Malli request coercion: When receiving a Transit request, the string decoders defined in my schema are executed, if it is a JSON request, it is only transformed by Muuntaja, but the Malli string decoders seems to be skipped… does that make sense? Background: I’m using the string decoders to convert strings into dates or big decimals.
Found the solution:
I had to add an additional :decode/json
property on my LocalDate / BigDecimal type, which a copy of the :decode/string
property.
Looks like this for LocalDate:
(def LocalDate
(mc/-simple-schema
{:type 'LocalDate
:pred #(instance? java.time.LocalDate %)
:type-properties {:error/message "invalid date"
:decode/string #(t/date %)
:decode/json #(t/date %)
:json-schema {:type "string"
:format "date"}
:gen/gen (gen/fmap #(t/>> (t/today) (t/new-period % :days)) (gen/choose -365 365))}}))
Hi all, one more question: is it possible to walk a spec + value in Malli? Say for example from the following spec
[:schema {:registry {::id :int
::address [:map
[::street :string]
[::city ::id]]
::user [:map
[:name ::id]
::address]}}
::user]
and example data
{:name -10257,
:my-ns/address
#:my-ns{:street "bhvZWkA2KL37u7y25O3R", :city 122054499}}
one wants to extract all values corresponding to an ::id
key, that is: [122054499, -10257]
Can this be done? I look at value transformations but they seem to be hardcoded for a prewalk, while here we need a postwalk. Am I missing something? :thinking_face:Duh, a transformer's encode operation can take an interceptor as an operator for a certain schema.
Or a :compile
key if you also need to access the schema, like in this case 🎉