Fork me on GitHub
#malli
<
2021-03-11
>
ikitommi05:03:40

@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.

ikitommi05:03:18

(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

Ed08:03:55

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.

Ed08:03:07

Although maybe ::m/default might be better

Ed08:03:33

Ah ... I see someone has already commented to that effect on the pr 😉

Adam Helins10:03:46

Hehe, sometimes I dream about creating a sub-community of "Clojurists against too much abbreviation"

Ed10:03:59

😉 ... 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

👍 6
armed14:03:40

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 []}))

Sam H17:03:54

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"]]}

armed18:03:04

Thanks, thats interesting. My code works if I replace :+ with :vector

armed18:03:55

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’.

armed14:03:25

I get {:items [["unknown error"]]} error

emccue17:03:34

How would I represent values like this

emccue17:03:58

:keyword-a
:keyword-b
{:map "with" :some 'shape}

emccue18:03:12

(in the same schema)

emccue18:03:53

at least with the online tool, alt doesn't seem to do what I would expect

ikitommi18:03:23

the http://malli.io is not updated for 0.3.0, so no :alt there yet. PR welcome to update deps

emccue18:03:35

would alt work in that case?

nilern18:03:32

:alt is for sequences only

nilern18:03:39

[:alt [:= :a] [:= :b]] matches [:a] and (:b) but not :a

emccue19:03:31

interesting that [:enum :a :b] is different than [:or [:= :a] [:= :b]]

ikitommi19:03:31

different, how?

emccue20:03:36

like, they are inferred differently

emccue00:03:14

(looped back to this, i'm probably wrong and got confused by the "inferred schema" part and also my bad memory)

ikitommi19:03:29

updated http://malli.io, with few sequence samples (args & hiccup)

ikitommi19:03:31

the Hiccup in JSON Schema looks fishy:

{:$ref "#/definitions/hiccup", :definitions {"hiccup" {}}}

ikitommi19:03:13

but, there are no sequence schemas there, so i guess it’s the best we can do.