Suppose we want to validate this YAML document that represents a (portion of a) Venue object here at Songkick (I made up the capacity figure):
name: Astoria street: 157 Charing Cross Road city: London, UK zip: WC2H 0EN lat: 51.500152 lng: -0.126236 capacity: 12345
The schema in Kwalify:
type: map mapping: name: type: str street: type: str city: type: str zip: type: str lat: type: float lng: type: float capacity: type: int
- easy to learn.
- useful validation errors
- excellent documentation
- can have complex validations such as regexes and arbitrary ruby code
- Ruby and Java only
- arrays and maps can only have the same type elements or values
The document schema in Rx:
type: //rec optional: name: //str street: //str city: //str zip: //str lat: //num lng: //num capacity: //int
- can validate YAML and JSON
- can have arrays, maps with different type elements
- resulting schemas are much more concise
- easy to extend type system
- documentation lacks examples, so a little harder to grasp
- validation errors don’t contain any useful information
- missing some important Ruby types, such as date and time.
We’ve gone with Rx, because it’s minor shortcomings are easy to fix. I hope to find the time to extend at least the Ruby implementation to add some more types and add a few examples and useful exceptions.