Open sirmspencer opened 1 year ago
You can use :vector
to get all errors:
(malli.core/explain [:vector :int] [1 2 "a" "b"])
;{:schema [:vector :int],
; :value [1 2 "a" "b"],
; :errors ({:path [0], :in [2], :schema :int, :value "a"}
; {:path [0], :in [3], :schema :int, :value "b"})}
What is your use case this these with sequence schemas?
Does :vector
allow an empty vector? This sounds like it should work.
Yes, it does. You can control the size requirements with :min
and :max
property.
(m/validate [:vector :any] []) ; => true
(m/validate [:vector {:min 1} :any] []) ; => false
(m/validate [:vector {:min 1} :any] [1]) ; => true
(malli.core/explain [:* :int] [1 2 "a" "b"])
{:schema #object[malli.core.t_malli$core91001], :value [1 2 "a" "b"], :errors ({:path [0], :in [2], :schema #object[malli.core.t_malli$core90615], :value "a"} {:path [], :in [2], :schema #object[malli.core.t_malli$core91001], :value "a", :type :malli.core/input-remaining})}
The second error here is a generic one that appear to show up as the error for the vector, after the error for the invalid item.