malli

https://github.com/metosin/malli :malli:
jhacks 2020-09-09T14:15:28.169700Z

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?

ikitommi 2020-09-10T15:28:31.184900Z

fixed the README

ikitommi 2020-09-09T16:04:02.171700Z

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

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

ikitommi 2020-09-09T16:04:55.172800Z

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

jhacks 2020-09-09T17:38:00.176600Z

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