I mean, you could write your own spec-outputting function that works like you describe 🙂
This is not what you want, the failure message would not be very helpful. But just a back-of-the-napkin sketch to inspire you 🙂
(defn map-spec [validation-map]
(s/def (fn [input]
(and (clojure.set/subset? (set (keys input))
(set (keys validation-map)))
(->> input
(filter (fn [[k v]]
(contains? (set (keys validation-map))
k)))
(map (fn [[k v]]
(let [validation-fn (get validation-map k)]
(validation-fn v))))
(every? identity))))))Actually, it might be a bit difficult to get the usually good feedback messages from the spec validating functions unless you venture into macro territory, so it’s probably a bit harder than the initial impression I gave. Still, might be an interesting exercise. But probably, it’s a good idea to follow the conventions laid out by spec, as @alexmiller says. Wrapping spec generation in macros can also deter tool usage (such as “go to spec definition of keyword” in Cursive - I specifically lived through that 🙂 )