This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-22
Channels
- # adventofcode (12)
- # announcements (17)
- # babashka (46)
- # beginners (105)
- # calva (7)
- # chlorine-clover (7)
- # cider (9)
- # clj-kondo (41)
- # cljsrn (16)
- # clojure (67)
- # clojure-australia (1)
- # clojure-europe (24)
- # clojure-france (6)
- # clojure-germany (10)
- # clojure-italy (1)
- # clojure-losangeles (3)
- # clojure-nl (4)
- # clojure-uk (11)
- # clojurescript (8)
- # cursive (8)
- # data-oriented-programming (1)
- # data-science (1)
- # datomic (11)
- # defnpodcast (4)
- # events (1)
- # fulcro (34)
- # graalvm (6)
- # helix (3)
- # jackdaw (19)
- # jobs-discuss (1)
- # leiningen (9)
- # luminus (2)
- # malli (15)
- # mathematics (2)
- # meander (5)
- # mental-health (1)
- # off-topic (4)
- # pathom (23)
- # podcasts-discuss (1)
- # polylith (4)
- # quil (3)
- # re-frame (81)
- # react (1)
- # reagent (19)
- # reitit (4)
- # releases (1)
- # reveal (11)
- # shadow-cljs (54)
- # specter (14)
- # tools-deps (16)
- # vscode (2)
- # xtdb (3)
Hey all. I might be missing something essential here but I don’t fundamentally understand why this won’t compile:
(defn longer-than-5? [x] (<= 5 (count x)))
(def MySchema [:map [:some-key [:and string? longer-than-5?]]])
; :malli.core/invalid-schema {:schema #function[example/longer-than-5?]}
Is there something special about string?
, int?
ect that makes them more than just a function from a -> bool
?What is special is that they are in the m/predicate-schemas
registry which is merged into the default registry
@U4MB6UKDL That’s interesting. Thank you
Hi,
I think the strip-extra-keys-transformer
removes mandatory fields if there are in an [:or ... ]
vector:
(def my-schema [:and
[:map [:a int?]]
[:or
[:map [:b int?]]
[:map [:c int?]]]])
=> #'...
(m/validate my-schema {:a 1})
=> false
(m/validate my-schema {:a 1 :b 1 :c 1})
=> true
(m/decode my-schema {:a 1 :b 1 :c 1} (mt/transformer mt/strip-extra-keys-transformer))
=> {:a 1}
Did I configure the schema wrong?
How can I work around it?maybe:
[:and
[:map
[:a int?]
[:b {:optional true} int?]
[:c {:optional true} int?]]
[:fn {:error/messag "only :a or :b is allowed"}
(fn [{:keys [b c]}] (not (and b c)))]]
or:
[:or
[:map
[:a int?]
[:b int?]]
[:map
[:a int?]
[:c int?]]]
would those work for you?Checking, I want to see how they integrate with reitit
’s swagger docs
you can run from repl:
(malli.swagger/transform
[:and
[:map
[:a int?]
[:b {:optional true} int?]
[:c {:optional true} int?]]
[:fn {:error/messag "only :a or :b is allowed"}
(fn [{:keys [b c]}] (not (and b c)))]])
to see what comes out.swagger doesn’t support anyOf
JSON Schema, so the latter will not show in swaggr docs.
I’ve used the first option, it worked for me. Thanks!
Hi @ikitommi I am facing interesting behavior with explain. I don't understand why order matters...
(def params-function?
(malli/schema
[:function
[:=> [:cat map? [:maybe map?] map?] map?]]
{::malli/function-checker malli.generator/function-checker}))
(def next-function?
(malli/schema
[:function
[:=> [:cat map? [:maybe map?] map?] keyword?]]
{::malli/function-checker malli.generator/function-checker}))
@U0D8J9T5K oh, that’s bad. will fix it.