This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-23
Channels
- # aws-lambda (2)
- # beginners (40)
- # calva (9)
- # cider (17)
- # clojure (84)
- # clojure-europe (13)
- # clojure-nl (1)
- # clojure-norway (77)
- # clojure-uk (26)
- # conjure (1)
- # cursive (7)
- # datomic (7)
- # events (1)
- # exercism (1)
- # gratitude (2)
- # hyperfiddle (4)
- # improve-getting-started (10)
- # jobs-discuss (12)
- # malli (4)
- # missionary (12)
- # off-topic (22)
- # other-languages (4)
- # pedestal (3)
- # portal (6)
- # reagent (6)
- # reitit (1)
- # releases (1)
- # ring (4)
- # shadow-cljs (2)
- # thejaloniki (2)
- # tools-build (27)
- # tools-deps (4)
- # vim (6)
Running into an issue with map entry attributes in the map
schema.
I haven't studied the implementation here so maybe I'm in undefined behaviour land, but since this works:
(mg/generate
[:map {:registry {:foo/bar :string}}
:foo/bar]) ;; #:foo{:bar "mWG3BP81X49181eod38930Y122oV"}
and this works
(mg/generate
[:map {:registry {:foo/bar :string}}
[:foo/bar]]) ;; #:foo{:bar "7IuHp3NFf"}
I would expect this to work:
;; expecting this to work
(mg/generate
[:map {:registry {:foo/bar :string}}
[:foo/bar {:min 100 :max 101}]]) ;; #:foo{:bar "7pU1jsi6NEnBa30MBp"} <-- too short :(
works if I write it out as documented:
(mg/generate
[:map {:registry {:foo/bar :string}}
[:foo/bar [:foo/bar {:min 100 :max 101}]]]) ;; #:foo{:bar "q348W......"} <-- works
Is this a bug, undefined behaviour or just not implementing?IIUC, in the third example, you are applying options to the key, not the value of the key-val association:
[:map [:foo/bar {:min 100 :max 101}]]
;; i.e.
[:map [:foo/bar {:min 100 :max 101} :foo/bar]]
Malli already has some amount of convenience (ie. magic) with how it tries to interpret these things, e.g:
[:map [:foo/bar]]
;; i.e.
[:map [:foo/bar :foo/bar]]
I don't see how Malli could figure out you want the third version to apply to the value and not to the key (e.g. to set {:optional true}
)(malli/ast
[:map {:registry {:foo/bar :string}}
[:foo/bar {:min 100 :max 101}]])
;; => {:type :map,
;; :keys
;; #:foo{:bar
;; {:order 0,
;; :value {:type :malli.core/schema, :value :foo/bar},
;; :properties {:min 100, :max 101}}},
;; :registry #:foo{:bar {:type :string}}}
^ yep, property of key not valueHaven't used ast before, thanks!