(s/def ::users (s/coll-of ::user :distinct true))
The spec above requires each user map to be distinct but How can I specify it to check for distinct :user/ids
only
The collection bellow shouldn't be allowed:
[{:id 10 :name "Jessica"} {:id 10 :name "Erica"}]
(s/def ::id (s/int-in 0 40)) ; just for testing purposes
(s/def ::name string?)
(s/def ::user (s/and (s/keys :req-un [::id ::name])))
(s/def ::user-list (s/and
(s/coll-of ::user :distinct true :into [])
#(if (empty? %) true (apply distinct? (mapv :id %)))))
(deftest so-test
(let [users [{:id 11 :name "Jessica"} {:id 11 :name "Erica"}]]
(prn (g/generate (s/gen ::user-list)))
(s/assert ::user-list users)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With