0.3.1 • Published 10 years ago

refaker v0.3.1

Weekly downloads
68
License
MIT
Repository
github
Last release
10 years ago

A JSON-schema $ref faker

Build Status NPM version Coverage Status

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.

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

0.3.1

10 years ago

0.3.0

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago