plumatic / schema

Clojure(Script) library for declarative data description and validation
Other
2.41k stars 257 forks source link

No field `post` found for `schema.spec.variant.VariantSpec` with conditional schema #333

Closed aew closed 8 years ago

aew commented 8 years ago

Using version 1.0.4, when attempting to generate values from the following conditional schema (cond-schema):

(require '[schema.core :as s])

(def type-details-sign {:neg #{-1} :pos #{1}})

(def schema*
  {:id          s/Uuid
   :type-detail (s/enum :neg :pos)
   :amount      BigDecimal})

(defn valid? [{:keys [type-detail amount]}]
  (contains? (type-details-sign type-detail) (.signum amount)))

(def cond-schema (s/conditional valid? schema*))

I received this error:

java.lang.IllegalArgumentException: No matching field found: post for class schema.spec.variant.VariantSpec schema.experimental.generators$eval36960$fn__36961$fn__36962.invoke(generators.clj:42)

It seems to be a field access here:

https://github.com/plumatic/schema/blob/master/src/clj/schema/experimental/generators.clj#L42

Of this field:

https://github.com/plumatic/schema/blob/master/src/cljx/schema/spec/variant.cljx#L41

w01fe commented 8 years ago

Thanks for the report. Can you please provide the generator invocation you are using? When I attempt to replicate, it works as expected.

w01fe commented 8 years ago

Any updates on this? Only think I can think of is that if you were somehow including an earlier version of schema as well as 1.0.4 (via AOT?) you could possibly get this error, since :post wasn't present in 1.0.0.