Fork me on GitHub
#clojure-spec
<
2018-08-06
>
ben.mumford13:08:12

hi spec, i have two types i want to spec that have some fields in common. is it possible to derive specs from a common base spec (like a superclass in java)?

ben.mumford13:08:52

in schema i could merge the base schema with new stuff.

ben.mumford13:08:45

nvm sorted it using a combination of s/and s/keys

🦆 4
favila14:08:08

s/merge is a thing also

Alex Miller (Clojure team)16:08:08

s/merge is better for this

hmaurer20:08:33

@U064X3EF3 @U09R86PA4 I was wondering a couple of months back if there would be a way to do this using derived keywords. i.e. with two specs :foo/a and :foo/b and the relation :foo/b derives :foo/a, enforce that :foo/b has to include :foo/a’s spec (or pass both, equivalently)

favila20:08:41

(s/def :foo/b (s/and :foo/a EXTRA-STUFF))

favila20:08:43

if :foo/b and :foo/a are both map specs, s/merge is better because it can intelligently combine the key's generators

favila20:08:19

s/and of two map specs likely cannot create a usable generator

Alex Miller (Clojure team)11:08:40

There is no support for keyword hierarchies in spec, sorry

hmaurer12:08:44

@U064X3EF3 out of curiosity, is that a design choice? or just a “not for now” kind of thing?

Alex Miller (Clojure team)12:08:49

We’ve never talked about it