Skip to content

javascript-forks/gextech.refaker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A JSON-schema $ref faker

Inspired on json-schema-validator for JAVA, the --fakeroot option, actually.

If you're validating some RAML (like me) then you should validate your JSON-schemas and examples also.

For this purpose I'm using ramlev which is using tv4, but you're encouraged to download any $ref manually before validating.

Solution?

var tv4 = require('tv4'),
    refaker = require('refaker');

var data = { /* ... */ },
    schema = { /* ... */ };

refaker({
  schema: schema,
  fakeroot: 'http://example.com',
  directory: '/path/to/schemas'
}, function(err, refs, schemas) {
  if (err) {
    console.log(err);
  } else {
    for (var id in refs) {
      // register resolved refs
      tv4.addSchema(id, refs[id]);
    }

    // validates the first passed schema
    console.log(tv4.validateResult(data, schemas[0]));
  }
});

That's it.

Options

  • schema (object|aray)

    The JSON-schema to validate.

  • schemas (object|array)

    Multiple JSON-schemas to validate at once.

    This is an alias for the schema option.

  • fakeroot (string)

    If provided, any matching $ref will be resolved under the specified directory.

  • directory (string)

    A local path containing the JSON-schemas.

    If missing, will use process.cwd() instead.

Any $ref found will be downloaded or faked locally.

Callback

The given callback will receive three arguments:

  • err (mixed)

    Empty means success.

  • refs (object)

    Hash of resolved $refs.

  • schemas (array)

    Normalized schemas if success (same order as input).

Build status

Build Status NPM version Coverage Status

About

Download or fake JSON schemas from $ref values

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 72.2%
  • CoffeeScript 27.8%