malli 2025-01-27

Hi again 😄 What would be the best way to transform keys of [:map ...] schema? I found m/walk but I don't think you can return modified keys as it is a postwalk but does not visit them, correct?

I did end up using clojure.walk as ::m/walk-entry-valsstill processes the "schema" side of an entry and not the key itself

(cwalk/postwalk (fn [node] (if (vector? node) (let [k (first node)] (if (= "TEST" (namespace k)) (into [(csk/->camelCaseKeyword (name (first node)))] (rest node)) node)) node)) schema)

I'll take a look but basaicaally I would like to transform this [:map [:foo-bar :string]] into this [:map {:FooBar :string]]

probably I need some custom clojure.walkfor that

In the link, I think the 3rd example is what you want.

you mean mu/update-in Address [:address] mu/assoc :country [:enum "fi" "po"] ?

I must be blind 😄

I haven't played with malli in a while. But if this doesn't help, ask again, and I think someone can answer.

I think the ::m/walk-entry-vals walk option could be useful. you can update the keys in a map entry using it.

for a non-recursive transformation it might be easier to just use mu/keys, mu/dissoc and mu/assoc

user=> (def schema [:map [:foo :int] [:bar :string]])
#'user/schema
user=> (mu/keys schema)
(:foo :bar)
user=> (reduce (fn [s k] (-> s
                             (mu/dissoc k)
                             (mu/assoc (keyword (.toUpperCase (name k))) (mu/get s k))))
               schema
               (mu/keys schema))
[:map [:FOO :int] [:BAR :string]]