Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Spec by

I would like to extend issue https://clojure.atlassian.net/browse/CLJ-2648 by stating that generate/valid?/exercise all dont work for any schema spec with a nested schema spec on it.

(s/def :another-entity/id uuid?)
(s/def :another-entity/some-attr int?)
(s/def ::another-entity (s/schema [:another-entity/id :another-entity/some-attr]))

(s/def :entity/id uuid?)
(s/def :entity/another-attr string?)
(s/def :entity/ref ::another-entity)
(s/def ::complex-entity (s/schema [:entity/id :entity/another-attr :entity/ref]))

(s/valid? ::complex-entity {:entity/id (random-uuid)
                            :entity/another-attr "oi"})
;;=> true
(s/valid? ::complex-entity {:entity/id (random-uuid)
                            :entity/another-attr "oi"
                            :entity/ref #:another-entity{:id (random-uuid)}})
;;=> Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1960$fn$G (protocols.clj:11).
;    No implementation of method: :conform* of protocol: #'clojure.alpha.spec.protocols/Spec found for class: clojure.lang.Keyword

(generators/generate (s/gen ::complex-entity))
;;=> Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1960$fn$G (protocols.clj:11).
;    No implementation of method: :conform* of protocol: #'clojure.alpha.spec.protocols/Spec found for class: clojure.lang.Keyword

Thanks :)

2 Answers

+1 vote
by

I think it's very much undecided whether nested schema specs will work like this so this is still in TBD land.

0 votes
by

Indirect spec references often result in this exception. There are a couple of workarounds:

Defining :entity/ref with a single-clause s/and:

(s/def :entity/ref (s/and ::another-entity))

Or registering it with s/register and s/get-spec

(s/register :entity/ref (s/get-spec ::another-entity))

In any case, this is probably not the intended behavior.

...