Fork me on GitHub

I’m not a fond of too much extra syntax for :map. If the spec-like :or or :and are liked, I guess there could be :keys schema for that?


Thanks! This does exactly what I need. One question for clarification though; When talking about too much extra syntax, do you mean :or / :and or are you referring to my pull request?


just referring to the :or and :and , like spec1 has.


will check the PRs as soon as have time. busy times.


Ahh ok thanks. Take your time!


I need something similar and even a bit more complex. I want to require a value either at top level or nested:

{:key1 "yo"}

;Also valid
{:nested {:key2 "yo"}}
It’s not the same key but they have the same meaning and one must exist. Currently I have this schema:
  [:key1 any?]
  [:nested {:optional true} [:map [:key2 {:optional true} any?]]]]
  [:key1 {:optional true} any?]
  [:nested [:map [:key2 any?]]]]]
but I have more keys like this, and some options can be either of 3 keys so I need 3 maps for each key and then combine all of it with :and.


@dcj easiest way to attach a decoder just for that enum would be:

(def Weighting
  [:enum {:decode/enum weighting->kw} :dB-A :dB-C :dB-Z])
and then applying it with:
(m/decode MyMap {:weighting 0} (mt/transformer {:name :enum}))
; => {:weighting :dB-C}


if you want to have a transformer for that, you can do the same as I gisted about the :postgres/table => add some hint to the enum and create a transformer that attaches in :compile just for that schema. hope this helps.


Yeah that's a good option as well. But that will probably lead to a lot of duplication (since my example was just a stripped down version)


Yup, it was quite annoying