This is a very good question, and the clojure.spec API gives a (provided, short and unsatisfactory) answer:
The: opt keys serve as documentation and can be used by the generator.
I don’t think that you can cancel the card if it contains additional (this is what you mean by “forbidden”, I think) key using this method. However, you can use this specification to make sure :: bad-key is not:
(s/def ::m (s/and (s/keys :req [::a])
You can limit the number of keys to the desired set using this specification:
(s/def ::r (s/and (s/keys :req [::reqd1 ::reqd2])
However, the best way to deal with this IMO is to simply ignore that there is a key point that you are not interested in.
Let's hope that over time they will be added. Or maybe they are already there (this is changing rapidly), and I just don’t know about it. This is a very new concept in clojure, so most of us have a lot to learn.
UPDATE - December 2016. I just wanted to come back to this 6 months from the moment of writing. It seems like my initial comment on ignoring keys that you don't care about is the preferred way. In fact, at the clojure / conj conference I attended two weeks ago, Rich Keynote specifically addressed the concept of version control at all software levels, from function level to application level. He even specifically mentions this concept of key prohibition in a conversation, which can be found on youtube . He says that it was intentionally designed so that only the right keys could be used. The ban on the keys does not really bring the intended purpose, and this should be done with caution.
As for the keys :opt , I think the original answer is still very good - this is the documentation, and practically, it allows you to create these optionally defined keys:
(s/def ::name #{"Bob" "Josh" "Mary" "Susan"}) (s/def ::height-inches (s/int-in 48 90)) (s/def ::person (s/keys :req-un [::name] :opt-un [::height-inches])) (map first (s/exercise ::person)) ; some generated data have :height-inches, some do not ({:name "Susan"} {:name "Mary", :height-inches 48} {:name "Bob", :height-inches 49} {:name "Josh"}