Fork me on GitHub
#malli
<
2021-08-27
>
martinklepsch12:08:04

How would I express that a schema can only have key :a OR key :b but not both?

lread13:08:24

Would something like this work?:

[:and
   [:map
    [:x {:optional true} int?]
    [:y {:optional true} int?]]
   [:fn {:error/message "Only one of :x or :y allowed"} (fn [{:keys [x y]}] (not (and x y)))]]

☝️ 6
ikitommi13:08:35

there are ideas around declarative way of doing that in the future, either using datascript or meander syntax.

mike_ananev13:08:29

Hello! I'm trying to use an example from malli docs. Why I got an error?

(defn plus1 [x] (inc x))
(m/=> plus1 [:=> [:cat [:int {:max 5}]] [:int {:max 6}]])
;; Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:119). :malli.core/invalid-schema {:schema :=>}

mike_ananev13:08:12

hmm, I see a strange behaviour. If I run in terminal repl, everything woks fine. If I run via Idea+Cursive then I see this error. Btw, I deleted .cpcache completely.

mike_ananev13:08:45

In Emacs I see the same error

mike_ananev14:08:43

@U055NJ5CC I've found the reason of that error. If I add `

:jvm-opts    ["-Dmalli.registry/type=custom"]
to deps.end alias, then I see this behaviour. Is it normal?

mike_ananev16:08:12

found solution for this: `

(mr/set-default-registry! (m/default-schemas))

ikitommi16:08:07

good to hear you got it reaolved

mike_ananev13:08:49

malli version 0.6.1

Brett Rowberry14:08:04

I think the answer to this question is probably going to be "just use reitit". Anyway, compojure.api has support for coercion and validation via Schema and spec. Are there examples on how to use malli instead?

Tiago Dall'Oca14:08:30

MALLI-&gt;TS - a sneak peek