This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-01
Channels
- # adventofcode (2)
- # announcements (3)
- # babashka-sci-dev (79)
- # beginners (76)
- # biff (2)
- # calva (32)
- # cider (2)
- # clj-kondo (42)
- # clj-on-windows (17)
- # clojure (28)
- # clojure-belgium (1)
- # clojure-berlin (1)
- # clojure-europe (95)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-uk (5)
- # clojurescript (27)
- # conjure (5)
- # cursive (3)
- # data-science (16)
- # datomic (67)
- # graalvm (12)
- # hyperfiddle (36)
- # jobs (3)
- # jobs-discuss (1)
- # kaocha (2)
- # klipse (1)
- # leiningen (28)
- # lsp (16)
- # luminus (3)
- # malli (10)
- # nrepl (3)
- # off-topic (57)
- # other-languages (18)
- # re-frame (4)
- # reitit (8)
- # releases (1)
- # remote-jobs (1)
- # scittle (4)
- # shadow-cljs (7)
- # test-check (1)
- # tools-deps (4)
- # vim (11)
- # xtdb (25)
Hello
In the context of this issue: https://github.com/metosin/malli/issues/739#issuecomment-1232938081
Should :my/int
represent something different from [:my/int]
? or they both different notations with the same meaning?
This behavior can be considered a bug?
(m/ast :my/int opts) #_#_=> {:type :malli.core/schema, :value :my/int}
(m/ast [:my/int] opts) #_#_=> {:type :my/int}
the extra wrapping makes one turn into $ref
and another turn into a simple type, in json-schema generation.
How do I modify this:
[:map
[:key-0 uuid?]
[:key-1 string?]
[:key-2 [:string {:max 9 :min 9}]]
such that a map must have one of these three keys? For example,
{:key-0 (UUID/randomUUID)}
{:key-1 "HELLO WORLD"}
{:key-2 "123456789"}
{:key-1 "HELLO WORLD" :key-2 "123456789"}
are all valid, but
{}
{:key-4 "SOME OTHER KEY"}
are not.
I didn't find a direct way of doing this in the docs, so I thought I'd ask before I ventured down the path of cobbling it together with :and, :or, etc.While it's not explicitly described as such, there is a hint about that possibility in the example shown in the paragraph with the text "Finding all subschemas with paths, retaining order:" There, the :fn
schema is used to check that either the :streeet
or the :lonlat
keys are present in the :map
schema (using the :and
schema to tie both conditions). So something like this should work:
(mapv (fn [m]
(malli/validate [:and
[:map
[:key-0 {:optional true} uuid?]
[:key-1 {:optional true} string?]
[:key-2 {:optional true} [:string {:max 9 :min 9}]]]
[:fn (fn [{:keys [key-0 key-1 key-2]}]
(or key-0 key-1 key-2))]]
m))
[{:key-0 (UUID/randomUUID)}
{:key-1 "HELLO WORLD"}
{:key-2 "123456789"}
{:key-1 "HELLO WORLD" :key-2 "123456789"}
{}
{:key-4 "SOME OTHER KEY"}])
[:or
[:map {:closed true}
[:key-0 uuid?]]
[:map {:closed true}
[:key-1 string?]]
[:map {:closed true}
[:key-2 [:string {:max 9 :min 9}]]
[:map {:closed true}
[:key-0 uuid?]
[:key-1 string?]]
[:map {:closed true}
[:key-1 string?]
[:key-2 [:string {:max 9 :min 9}]]]
[:map {:closed true}
[:key-0 uuid?]
[:key-2 [:string {:max 9 :min 9}]]]
[:map {:closed true}
[:key-0 uuid?]
[:key-1 string?]
[:key-2 [:string {:max 9 :min 9}]]]
Thank you both for your help. I was about to go down the road @U3JH98J4R demonstrated, but was hoping for something less redundant. @U8T05KBEW’s nudge is exactly what I was looking for.