Closed Biserkov closed 4 years ago
To answer my own question: wrapping the s/or in an st/spec seems to work?
(s/def ::d (st/spec (s/merge (st/spec (s/or :one (s/keys :req-un [::a])
:two (s/keys :req-un [::b])))
(s/keys :req-un [::c]))))
Hello @Biserkov , the problem is the following: there is a bug introduced with multi-spec
support after version 0.10.0 at the parse-form
function. Your spec is decomposed by parse-form
which yields :type [:or [:map]]
to the inner most portion of your spec.
When we look at the parse-form
, we find (current-version):
(defmethod parse-form 'clojure.spec.alpha/merge [_ form]
(let [type-priority #((:type %) {:map 0
:multi-spec 1} 0)]
(apply impl/deep-merge (->> (rest form)
(map parse-spec)
(sort-by type-priority)))))
The ArityException is thrown by this operation:
#([:or [:map]] {:map 0
:multi-spec 1} 0)
;; => Wrong number of args (2) passed to: clojure.lang.PersistentVector
The same code in version 0.10.0 looks like this:
(defmethod parse-form 'clojure.spec.alpha/merge [_ form]
(apply impl/deep-merge (map parse-spec (rest form))))
Does not contain the portion to sort by priority, thus no error. I opened a PR to change the type-priority
function to be more defensive.
This code works on 0.10.0, but breaks in 0.10.1 - 0.10.4. Please advise on any workarounds?