plumatic / schema

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

Fix sequence generation (fixes #321) #342

Closed w01fe closed 8 years ago

w01fe commented 8 years ago

The existing :cardinality key was not expressive enough to capture the semantics of sequence schemas (namely, that if you don't generate an s/optional element, you have to stop there.

This PR replaces :cardinality with a nested structure of optional tails that can properly express the semantics of existing collection schemas for the purpose of generation. It also slightly generalizes the types of schemas that can be expressed with the collection spec, although probably not in a way that's useful to anyone.

The changes feel a bit heavyweight for what's accomplished, but I tried a few alternatives and couldn't get them to work without reasonable performance (and really didn't feel good about the option of adding another pseudo-:cardinality that expressed the missing constraint. Suggestions for alternative approaches very welcome!

w01fe commented 8 years ago

Anyone want to take a look / comment? I'd like to get this merged so we can finish splitting out generators as well. Thanks!