Fork me on GitHub
#malli
<
2020-09-09
>
jhacks14:09:28

Following along with the example here: https://github.com/metosin/malli#custom-registry

(def registry
  (merge
    (m/class-schemas)
    (m/comparator-schemas)
    (m/base-schemas)
    {:int (m/fn-schema :int int?)
     :bool (m/fn-schema :bool boolean?)}))

(m/validate [:or :int :bool] 'kikka {:registry registry})
; => false

(m/validate [:or :int :bool] 123 {:registry registry})
; => true
It looks like m/fn-schema no longer exists. I tried using m/-fn-schema (which does exist) but that didn’t work. How does this example work with the current code?

ikitommi15:09:31

fixed the README

ikitommi16:09:02

@jhacks oh, the README is out of sync. This should work:

(m/-simple-schema {:type :boolean, :pred boolean?})

ikitommi16:09:55

there seems to be (m/-predicate-schema :boolean boolean?) too

jhacks17:09:00

@ikitommi Thanks, both methods work! Is there a way to register a default error message for schemas in the custom registry? For example, the custom :boolean schema has "unknown error" for the error message. Could I define a different message?