clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Sean H 2020-12-04T00:07:29.457700Z

Is there a good way to have multiple generators for clojure.spec.test.alpha & clojure.spec.gen.alpha on the same spec on a namespaced keyword? In particular, in cases where we know that a spec is restricted in certain contexts, such as Datomic refs (which when sent TO datomic are either a 2-tuple, an int, or a map [component], while when received FROM datomic are an int or a map). If not, my guess would be the most sensible way to do this is to just override the spec’s generator with a generator that generates the more restrictive form (e.g. int/map in the above example, or just int for non-component refs) and then do generation some other way (or not at all) for cases where you need the more general form? Thanks! EDIT: I think I’ve figured it out. For anyone who’s curious, this can be done by clojure.spec.test.alpha/instrument options

Thomas Moerman 2020-12-04T17:51:13.458800Z

Q: consider following snippet:

(s/valid? (s/keys :req [:nexus.annotation/id]) {:nexus.annotation/id             1
                                                :nexus.annotation/annotation-set {:invalid :map}}) => false

Thomas Moerman 2020-12-04T17:51:47.459500Z

1. Why does spec take the second (invalid) key into account? 2. Is there a way to make spec ignore the second key

Thomas Moerman 2020-12-04T17:59:03.460200Z

Apparently this is by design:

Thomas Moerman 2020-12-04T17:59:07.460500Z

> > In addition, the values of all namespace-qualified keys will be validated > (and possibly destructured) by any registered specs. Note: there is > no support for inline value specification, by design.

alexmiller 2020-12-04T18:11:05.460700Z

yes, it is by design

alexmiller 2020-12-04T18:11:26.461Z

attributes have global meaning

1