Fork me on GitHub
#malli
<
2021-06-14
>
martinklepsch21:06:56

Hey 🙂 Is there a way to combine multiple schemas to one? Specifically I have a bunch of “base” keys and a few keys that I want to check based on the :type key in the set of “base” keys. I kind of see how I could do that with multi and a bit of repetition but I probably want :merge? Is there a way to get :merge without getting into registries and all that?

martinklepsch21:06:47

Duh, I just realized I can just into more key to existing [:map] schemas

ikitommi04:06:45

yeah. :multi is not currntly mergable, oftenly asked. would allow concise definitions like:

[:merge
 [:map [:id :uuid]]
 [:multi {:dispatch :type}
  [:pear [:size :int]]
  [:boat [:price :int]]]]

martinklepsch15:06:02

Is there a “recommended way” to achieve this currently?

martinklepsch15:06:33

It seems like a common need so if there is one I think documenting that could be useful. Happy to open a PR once I know 😄