@l0st3d & everyone else, opinions on :m/default
or :malli/default
?
[:multi {:dispatch :type}
["object" [:map-of :keyword :string]]
[:m/default :string]]
vs:
[:multi {:dispatch :type}
["object" [:map-of :keyword :string]]
[:malli/default :string]]
… same could be used for extra-keys in maps, e.g. :m/extra
vs :malli/extra
. Personally fond of the :m
.That would definitely solve my problem and make my code easier to read ... it get's my vote ... many thanks for the impressively fast feedback.
Although maybe ::m/default
might be better
Ah ... I see someone has already commented to that effect on the pr 😉
Hehe, sometimes I dream about creating a sub-community of "Clojurists against too much abbreviation"
😉 ... I think it's not about abbreviation, but scope ... :m/
is a public namespace that may be being used by an application and may well be a target in that multi dispatch, whereas ::m/
is scoped to malli.core
and therefore shouldn't have meaning in your application - so it's fine to use as a default ... I think where clojure pushes back against brevity it tends to be for reasons of applicability in different contexts - which makes it a more generally useful language
(def valid?
(m/validator
[:multi {:dispatch :type}
["object" [:map-of :keyword :string]]
[:m/default :string]]))
(valid? {:type "object", :key "1", :value "100"})
; => true
(valid? "SUCCESS!")
; => true
(valid? :failure)
; => false
Hello, how to attach custom error message to seqexp? For example:
(malli.error/humanize
(malli/explain
[:map
[:items
[:+
{:error/message "Items must not be empty"}
[:map [:foo string?
:bar int?]]]]]
{:items []}))
I get {:items [["unknown error"]]}
error
looks like the :error/message
is in the wrong place:
(me/humanize
(m/explain
[:map
[:items
[:+
[:map {:error/message "Items must not be empty"}
[:foo string?
:bar int?]]]]]
{:items []}));; => {:items [["Items must not be empty"]]}
How would I represent values like this
:keyword-a
:keyword-b
{:map "with" :some 'shape}
(in the same schema)
at least with the online tool, alt doesn't seem to do what I would expect
the http://malli.io is not updated for 0.3.0, so no :alt
there yet. PR welcome to update deps
would alt work in that case?
:alt
is for sequences only
[:alt [:= :a] [:= :b]]
matches [:a]
and (:b)
but not :a
Thanks, thats interesting. My code works if I replace :+
with :vector
And if I put error inside :map, then all other map validation errors replaced with that one, even ‘missing key’ is becomes ‘items must not be empty’.
interesting that [:enum :a :b]
is different than [:or [:= :a] [:= :b]]
updated http://malli.io, with few sequence samples (args & hiccup)
the Hiccup in JSON Schema looks fishy:
{:$ref "#/definitions/hiccup", :definitions {"hiccup" {}}}
but, there are no sequence schemas there, so i guess it’s the best we can do.
different, how?
like, they are inferred differently