Fork me on GitHub

I can’t get Union working on my schemas


This is the gist with the schemas in it.


@grounded_sage it seems neither of those are valid schemas, I split the first one and reduced it into this which fails

user=> (m/validator [:map
  #_=>  [:Data
  #_=>   [:map
  #_=>    [:GroupMemberships [:vector [:or]]]]]])
Execution error (ExceptionInfo) at malli.core/fail! (core.cljc:73).


That :or seems lingering, typo?


Yea I thought that was strange. Can malli generate invalid schemas?


Because this was after doing schema inference.


If that is a result of inferring then I guess the answer is yes 🙂 If you can figure out the minimal set of input data which produces invalid inferred schemas, I’m sure an issue is warmly welcomed.


Sounds like a bug.


Anyone now if this is possible? :spritesheet/frame and :spritesheet/animation are technically both optional. But the map MUST have one or the other. This code snippet is invalid, the :or doesn't work (disclaimer, I'm working off of this PR which is why I can use this qualified-keyword syntax)


The way I've done such xor-like unions in regular spec is to move the or up one level:



Let's say I have a value that is an enum:

(def Weighting
  [:enum :dB-A :dB-C :dB-Z])
I can specify that as a value in another schema:
(def MyMap
    [:weighting Weighting]]))
Is there a way to turn the value schema into a "type" that malli understands? Let's say I need to transform the numbers 0,1,2 into the enumerated values...
(defn weighting->kw
  (if (int? n)
    (case n
      0 :dB-C
      1 :dB-A
      2 :dB-Z
I specify a value transformer as:
 {:name :weighting
  :decoders {:enum weighting->kw}})
But in writing this, I am reaching into Weighting to pull out the :enum If I had two different enum values then dispatching via "value is an enum" doesn't seem like it will work, they will both resolve to enum. How does one handle this? Seems like I would want to specify the decoder as {:Weighting weighting->kw}