ericgj / json-schema-suite

JSON Schema tools suite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

json-schema-suite

JSON Schema components bundled for easy use.

  • Configures Schema with validation and hyperlink plugins.

  • Configures the Agent to use visionmedia/superagent as the underlying http client.

  • Exposes Agent, as well as Schema and Validator for further configuration.

Installation

component:

$ component install ericgj/json-schema-suite

npm:

$ npm install json-schema-suite

browser standalone:

Include build.js or build.min.js in a script tag. This will give you a window.jsonSchema global. If you would prefer a different global, clone this repo and rebuild like:

$ component install
$ component build --standalone myGlobal

Then move the build/build.js file into your project.

Examples

var suite = require('json-schema-suite')

// Simple validation
// see json-schema-valid for more details

var validator = new suite.Validator()

validator.validateRaw(schema,instance); // boolean
validator.error();   // validation error(s) wrapped in error object


// HTTP correlation

var agent = new suite.Agent()

agent.get('/api', function(err,correlation){

  // validation
  correlation.once('error', function(e){
    console.error(e);
  })

  if (correlation.validate()) {
    //...
  }

  
  // follow resolved links in correlations
  agent.follow( correlation.rel('instances'), function(){
    //...
  });

})

API

See json-schema-agent, json-schema-valid, json-schema-core for details.

Running tests

In browser

$ node test/server.js

And browse http://localhost:3000.

In node

$ node test/server.js &
$ npm test

License

MIT

About

JSON Schema tools suite


Languages

Language:JavaScript 98.9%Language:CSS 1.1%