refaker-local-id

0.1.0 • Public • Published

A JSON-schema $ref faker

Build Status NPM version Coverage Status

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

This fork also allows non-standard references via "id".

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-local-id');
 
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.

  • timeout (number)

    Timeout when resolving remote schemas, default to 200ms.

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).

Bitdeli Badge

Readme

Keywords

none

Package Sidebar

Install

npm i refaker-local-id

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • forivall