Fork me on GitHub
#malli
<
2022-04-07
>
respatialized18:04:56

Is there a way to negatively specify a map key? Like "this map cannot contain the :ident key?"

respatialized18:04:58

I could do an :and schema with a :not but that seems clunky and was wondering if there's another way

ambrosebs21:04:23

AFAIK think it's like spec in this respect. There are hacks around it but it's not supported, https://github.com/metosin/malli/blob/3599fbd7fe1eba96c35e5c39073397cba0984b6a/src/malli/core.cljc#L975-L982 is concerning presence, not absence.

ambrosebs21:04:59

another hack I remember from spec is using map-of's keys with a restricted spec for keys.

ambrosebs21:04:08

when I https://github.com/typedclojure/typedclojure/blob/bb973bce811c111a814aad4889aa2a083a5e761d/typed/malli/src/typed/malli/parse_type.cljc#L148-L151 a Typed Clojure => malli translation, the best I could find was {:closed true} to prevent all other keys.

ambrosebs21:04:19

That might be what you want actually.

respatialized21:04:26

Unfortunately not, my use case is a data model like GeoJSON where it's open by default but some keys are reserved and cannot be used in certain contexts

Ben Sless07:04:36

You can require a map be closed in malli

respatialized18:04:58

I could do an :and schema with a :not but that seems clunky and was wondering if there's another way