You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coming from Clojure Spec, I would expect merging a :map with a :multi to work intuitively. Instead, I hit the merge-default behavior in malli.util/merge, which drops the first schema in favor of the second one. Naively, it seems like :multi could be handled more elegantly. Take the following scenario.
;; Malli Schema
(defBase [:map [:a string?]])
(defFull [:merge Base [:multi {:dispatch:type}
[:type1 [:map [:type1-k string?]]]]])
;; Same Schema, written in Spec
(s/def::astring?)
(s/def::base (s/keys:req-un [::a]))
(defmultibase-spec:type)
(s/def::type1-kstring?)
(defmethodbase-spec:type1 [_] (s/keys:req-un [::type1-k]))
(s/def::full
(s/merge::base (s/multi-spec base-spec :type)))
If I m/explain a value missing the :a key, Malli will return true. I expected an explain that tells me I am missing a key.
Hi @kennyjwilli - did you solve this issue non-natively with Malli for the time being? If so, is it possible to share with the above as an example please? Thank you!
Yes @oryband, though I'm not fully satisfied with the solution, it does work for our use case -- just data validation. At each :merge, I am able to loop through the children, validating if the data passes the child schema.
Coming from Clojure Spec, I would expect merging a
:map
with a:multi
to work intuitively. Instead, I hit themerge-default
behavior inmalli.util/merge
, which drops the first schema in favor of the second one. Naively, it seems like :multi could be handled more elegantly. Take the following scenario.If I
m/explain
a value missing the:a
key, Malli will return true. I expected an explain that tells me I am missing a key.Here is Spec's output.
For our use cases, merging a :map with a :multi is a very common scenario. Is there interest in supporting this natively?
The text was updated successfully, but these errors were encountered: