plumatic / schema

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

schema.core/validate: StackOverFlowError with either and recursive #359

Closed elahti closed 8 years ago

elahti commented 8 years ago

Schema validation seems to fail to StackOverFlowError when using recursive schemas combined with either.

The following validation works:

(s/defschema Recursive {:children [(s/recursive #'Recursive)]})
=> #'user/Recursive
(s/validate Recursive {:children []})
=> {:children []}

But the following doesn't:

(s/defschema Recursive {:children [(s/either s/Str (s/recursive #'Recursive))]})
=> #'user/Recursive
(s/validate Recursive {:children []})
StackOverflowError   clojure.core/drop-while/fn--4862 (core.clj:2868)

I'm unsure if I'm just misusing the either there but it does work like that when it isn't used with recursive. For example (s/either s/Str s/Int) works just fine, allowing Integers or Strings.

I'm using schema.core version 1.1.1 with Clojure.

w01fe commented 8 years ago

Thanks for the report. either is deprecated as of 1.0.0, and does not work with recursive anymore. Please replace either with conditional, if, or cond-pre (when applicable). In this case, since Str and Recursive are superficially different, cond-pre will work as a drop-in replacement for either.

elahti commented 8 years ago

My bad. Thanks!