Skip to content

Commit

Permalink
add base swagger schema to subschemas for reference resolution in api…
Browse files Browse the repository at this point in the history
… validate as per krakenjs#33"
  • Loading branch information
Trevor Livingston committed Mar 3, 2015
1 parent 690127e commit 0198692
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var assert = require('assert'),
path = require('path'),
caller = require('caller'),
utils = require('./utils'),
buildroutes = require('./buildroutes');
buildroutes = require('./buildroutes'),
swaggerSchema = require('./schema/swagger-spec/schemas/v2.0/schema.json');


function swaggerize(options) {
Expand All @@ -31,10 +32,12 @@ function swaggerize(options) {

options.basedir = options.basedir || path.dirname(caller());

schemas = {
'#': swaggerSchema
};

// Map and validate API against schemas
if (thing.isArray(options.schemas)) {
schemas = {};

options.schemas.forEach(function (schema) {
assert.ok(thing.isObject(schema), 'Expected schema option to be an object.');
assert.ok(thing.isString(schema.name), 'Expected schema name to be a string.');
Expand All @@ -49,11 +52,10 @@ function swaggerize(options) {
});
}

enjoi(require('./schema/swagger-spec/schemas/v2.0/schema.json'), schemas).validate(options.api, function (error) {
enjoi(swaggerSchema, schemas).validate(options.api, function (error) {
assert.ifError(error);
});


// Resolve path to handlers
options.handlers = options.handlers || './handlers';

Expand Down

0 comments on commit 0198692

Please sign in to comment.