I am setting up a service using reitit, muuntaja and malli. So far configuration has been simple and has worked. However, I have run into an issue related to multi schema. My schema was setup as follows:
[:multi {:dispatch :occasion}
[:carry-out [...]]
[:delivery [...]]]
This did not work as the value of occasion contained a string (coming from a JSON request) and coercion was not applied yet as first the correct schema needs to be determined. Once I found the documentation, all of this made sense. Following the documentation on how to resolve this issue, I change my schema to the following:
[:multi {:dispatch :occasion
:decode/string #(do
(println "decode data")
(println (pr-str %))
(update % :occasion keyword))}
[:carry-out [...]]
[:delivery [...]]]
I was not exactly sure what was being passed in which is why I included the println for debugging. Unfortunately, my decode function does not seem to be called at all. Running decode in a REPL with just malli works correctly so it seems to be something with the configuration of malli + reitit + muuntaja that is off. Any debugging avenue suggestions would be greatly appreciated as I have seem to hit a dead end.This is the example I found on the https://github.com/metosin/malli?tab=readme-ov-file#multi-schemas page:
(m/decode
[:multi {:dispatch :type
:decode/string #(update % :type keyword)}
[:sized [:map [:type [:= :sized]] [:size int?]]]
[:human [:map [:type [:= :human]] [:name string?] [:address [:map [:country keyword?]]]]]]
{:type "human"
:name "Tiina"
:age "98"
:address {:country "finland"
:street "this is an extra key"}}
(mt/transformer mt/strip-extra-keys-transformer mt/string-transformer))
;; => {:type :human
;; :name "Tiina"
;; :address {:country :finland}}try :decode/json as key