malli 2026-09-03

do :multi schemas have to be defined with literals? or is it possible to have some sort of... look-up table for the multi? i was thinking about something where i have an atom that i insert entries into, and then in a :multi , i can say [:multi {:dispatch :type} multi-registry] . looking at the docs and playing around int he repl, the only thing i can get to work is saying (def Example (m/schema [:multi {:dispatch :type} ~@@multi-registry]))` which requires defining every branch schema before defining the top-level schema

there's the lazy registry/lazy multi example, but that requires writing all of the lazy keys in there, so i'd need to duplicate or inline with a syntax quote like i did above

i tried out :validate and works okay but i found it to be lacking in a couple small ways, which i've detailed here: https://github.com/metosin/malli/issues/1311

Not sure if it helps and maybe it conforms want you already found, but here is something using lazy-multi from a some years ago. The schema is generated https://github.com/jeroenvandijk/aws.cloudformation.malli/blob/master/src/adgoji/aws/cloudformation/malli/validation.clj

that's close but not quite, as i'm looking to have something like a dynamic registry, but for :multi schemas. i'd like to be able to add a new entry with (swap! registry assoc :some-key (m/schema ...)) and not have to reload the (def Example (m/schema [:multi ...]))

yeah for actual schemas you can use mutable registry support, but that doesn't help with adding cases to a :multi

I think a feature like this could be it's own schema, something like ':dynamic-multi`. Could be under malli.experimental at first.

as it is, :multi will parse the keys in the -into-schema stage, so you can't change the cases after m/schema, unfortunately

👍 1