JSON SCHEMA SUITE to the rescue

Finally Found You

This is a love song to https://github.com/ericgj/json-schema-suite. Eric C. J., did some bang up work putting together a JSON Hyper Schema client written in Javascript. It is compatible with NodeJS and browser implementations. I've been trying to build my own HATEOAS client using Angular, and made significant progress, but there is still much more I can take advatnage of in the JSON Hyper-Schema specs (http://json-schema.org/documentation.html http://json-schema.org/latest/json-schema-hypermedia.html). I am really excited that Eric has taken the time to write this fantastic library.

I spent most of last night setting up a project to experiment using this client library with my own Hyper Schema Hypermedia API (http://www.passportedu.com/api/v1). Tonight I plan to get pretty hot and heavy with Eric's library and get some working examples of how I can use it in my own project. It seems like it works just as I would have designed it.

It creates a Correlation between schema and instance

For each endpoint you provide to the suite, it produces what it calls a correlation. A correlation is the result of interpolating the resource instances with the resource schema. Here is just a teaser of some of the functionality offered by a correlation.

Validate

correlation.validate()

Validates correlation instance against correlation schema.

NOTE: validation errors are inaccessible here; if you need them, use the standalone validate().

Resolve Links

correlation.resolveLinks()

Validates, and builds a links object, concatenating all link specifications from all valid schemas. Links are then resolved against the correlation instance.
 
Typically this method is not called directly but instead via correlation.links(), defined in json-schema-hyper.

Sub Schemas

correlation.subschema()

Validates, and builds a 'collated' schema (Schema.allOf) for the given property/array-index from all valid schemas. Note if only one valid schema (the "top-level schema"), the behavior is identical to the basic subschema() method provided in json-schema-core.

Schema coercion

correlation.coerce()

Validates, and coerces instance according to: 
(1) the first valid schema that specifies either `type` or `default` or both;
(2) the "top-level schema", otherwise, whether instance is valid or invalid.

NOTE: that the ordering of valid schemas cannot be relied on, so it is recommended that either the top-level schema specify type and/or default, or _only one_ combination schema specify these.

Just the beginning

I plan to dive deep into this library and learn as much as I can. I'll keep this blopg posted with my progress, however big or small.