This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-14
Channels
- # announcements (7)
- # babashka (13)
- # beginners (98)
- # biff (20)
- # calva (3)
- # clj-kondo (5)
- # clj-otel (6)
- # cljs-dev (96)
- # clojure (22)
- # clojure-austin (30)
- # clojure-conj (4)
- # clojure-europe (53)
- # clojure-nl (2)
- # clojure-norway (63)
- # clojure-uk (3)
- # clojurescript (18)
- # cursive (10)
- # data-science (11)
- # datalevin (2)
- # datomic (7)
- # deps-new (1)
- # fulcro (3)
- # graphql (1)
- # gratitude (4)
- # hyperfiddle (43)
- # kaocha (4)
- # malli (15)
- # pathom (6)
- # polylith (2)
- # reagent (3)
- # reitit (2)
- # releases (6)
- # remote-jobs (1)
- # rewrite-clj (45)
- # ring (4)
- # shadow-cljs (47)
- # sql (5)
- # xtdb (8)
Hello! I'm having some trouble to define a custom registry in Malli
(def custom-registry
{::decimal [:double {:min 2}]})
(def registry
(-> custom-registry
(mr/registry)
(mr/composite-registry m/default-registry)))
(m/validate [::decimal] 2.5 {:registry registry})
Running the above code throws the following exception: :malli.core/invalid-schema {:schema [:double {:min 2}]}
What am I doing wrong? Thx in advanceIt's a bit confusing but storing vector schemas in the registry and using vector lookup syntax ins't valid. I had the same thought and opened a PR to "fix" it
https://github.com/metosin/malli/pull/848
but it's not a bug, it's how schemas work. You can get around it using either [:ref ::decimal]
or [:schema ::decimal]
Maybe the docs should be updated to have a note about it
you registry is fine, the problem is in [::decimal]
. This is invalid syntax for malli.
(m/validate ::decimal 2.5 {:registry registry})
works just fine
You are right, just tested that (m/validate ::decimal 2.5 {:registry registry})` works. But what happens if I want to have a schema with children?
This fails again:
(def custom-registry
{::decimal [:double {:min 2}]
::object [:map]})
(def registry
(-> custom-registry
(mr/registry)
(mr/composite-registry m/default-registry)))
(m/validate [::object [:item-1 ::decimal]] {:item-1 2.5} {:registry registry})
@U051V5LLP if I understood right the workaround you suggest doesn't work in this case, does it?
yea, looks like it won't work in that case, I'm not sure what's the reasoning behind why though
> But what happens if I want to have a schema with children?
@UK14W219B you have to create a schema that can accept parameters. Adding just [:map]
into the registry doesn't allow your ref schema to have children.
There is a way to add custom schema type - https://github.com/metosin/malli#custom-schema-types
@U051V5LLP [:int]
is valid because :int
schema can accept parameters like :min/:max
Understood! Thank you both a lot
@U04V4KLKC it would be awesome, if you don't mind, to put together a little cheat-shee/table of what constitutes an invalid schema and when you have to create your own custom schema type vs just creating a ref schema. I think this would be a great addition to the readme :)
I ported the new experemental.time
schemas to cljs https://github.com/metosin/malli/pull/853