diff --git a/lib/schema/index.js b/lib/schema/index.js index b46cdd6..f50dc8f 100644 --- a/lib/schema/index.js +++ b/lib/schema/index.js @@ -3,6 +3,7 @@ var tv4 = require('tv4'), assert = require('assert'), fs = require('fs'), + thing = require('core-util-is'), path = require('path'); var schemaPath, baseSchemaPath, baseSchema, modelSchema; @@ -34,6 +35,10 @@ module.exports = { validate: function validate(data, schema) { var results; + if (thing.isString(schema)) { + schema = require(path.join(schemaPath, schema)); + } + results = tv4.validateResult(data, schema || baseSchema, true); return results; diff --git a/package.json b/package.json index ccbf9bd..bfb3a6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swaggerize-builder", - "version": "1.0.0-rc.1", + "version": "1.0.0-rc.2", "author": "Trevor Livingston ", "description": "Swagger based route building.", "main": "./lib/index", diff --git a/test/fixtures/listing.json b/test/fixtures/listing.json new file mode 100644 index 0000000..70a0115 --- /dev/null +++ b/test/fixtures/listing.json @@ -0,0 +1,14 @@ +{ + "swaggerVersion": "1.2", + "apiVersion": "v1", + "info": { + "title": "Greetings", + "description": "This is a resource listing document for greetings api." + }, + "apis": [ + { + "path": "/greetings", + "description": "operations on greetings." + } + ] +} diff --git a/test/test-schema.js b/test/test-schema.js index fe5598c..019840f 100644 --- a/test/test-schema.js +++ b/test/test-schema.js @@ -14,6 +14,14 @@ test('schema', function (t) { t.ok(results.valid, 'no errors'); }); + t.test('validate against cached schema', function (t) { + t.plan(1); + + var results = schema.validate(require('./fixtures/listing.json'), 'resourceListing.json'); + + t.ok(results.valid, 'no errors'); + }); + t.test('bad api', function (t) { t.plan(2);