Fork me on GitHub
#malli
<
2019-12-31
>
borkdude10:12:49

Does malli have something like s/conform for s/cat?

ikitommi11:12:35

not yet, but it will come. Can't recall if there was an issue of conform yet, or just discussed

ikitommi12:12:31

12 added lines later:

(explain
  [:map {:closed true}
   [:xy
    [:map {:closed true}
     [:x int?]
     [:y int?]]]]
  {:xy {:x 1, :y 2, :EVIL "LYN"}
   :DARK "ORKO"})
;{:schema [:map {:closed true} [:xy [:map {:closed true} [:x int?] [:y int?]]]],
; :value {:xy {:x 1, :y 2, :EVIL "LYN"}, :DARK "ORKO"},
; :errors (#Error{:path [2 1],
;                 :in [:xy :EVIL],
;                 :schema [:map {:closed true} [:x int?] [:y int?]],
;                 :type :malli.core/extra-key}
;           #Error{:path [],
;                  :in [:DARK],
;                  :schema [:map {:closed true} [:xy [:map {:closed true} [:x int?] [:y int?]]]],
;                  :type :malli.core/extra-key})}

ikitommi12:12:43

that should contain all the needed info to get spell-spec grade error messages.

ikitommi12:12:48

e.g. :in points to the actual key and :type can be used to format suggestions on misspelled keys etc.

ikitommi13:12:01

also:

(-> [:map {:closed true} [:x int?]]
    (m/explain {:x 1, :extra "key"})
    (me/humanize))
; => {:extra ["disallowed key"]}