Skip to content

Commit

Permalink
Merge pull request #5 from tlivings/master
Browse files Browse the repository at this point in the history
added cache of schemas to allow override schemas by name
  • Loading branch information
tlivings committed Sep 8, 2014
2 parents 17e8d4c + 5a8363b commit e3e5a6b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swaggerize-builder",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"author": "Trevor Livingston <[email protected]>",
"description": "Swagger based route building.",
"main": "./lib/index",
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/listing.json
Original file line number Diff line number Diff line change
@@ -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."
}
]
}
8 changes: 8 additions & 0 deletions test/test-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e3e5a6b

Please sign in to comment.