diff --git a/index.js b/index.js index 9b3a921..c90194b 100644 --- a/index.js +++ b/index.js @@ -208,15 +208,16 @@ function getData(swagger, apiPath, operation, response, config, info) { // if we have requestData, fill the path params accordingly var mockParameters = {}; - data.pathParameters.forEach(function(parameter) { - // find the mock data for this parameter name - mockParameters[parameter.name] = data.requestData.filter(function(mock) { - return mock.hasOwnProperty(parameter.name); - })[0][parameter.name]; - }); - // only write parameters if they are not already defined in config - // @todo we should rework this with code above to be more readable - if (!config.pathParams) { + if (config.pathParams) { + data.pathParams = config.pathParams; + } else { + // no path params in config, get them from per-endpoint data + data.pathParameters.forEach(function(parameter) { + // find the mock data for this parameter name + mockParameters[parameter.name] = data.requestData.filter(function(mock) { + return mock.hasOwnProperty(parameter.name); + })[0][parameter.name]; + }); data.pathParams = mockParameters; } } diff --git a/templates/request/delete/delete.handlebars b/templates/request/delete/delete.handlebars index df4e360..f3a324a 100644 --- a/templates/request/delete/delete.handlebars +++ b/templates/request/delete/delete.handlebars @@ -58,7 +58,7 @@ validator.validate(body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#is assertion 'expect'}} diff --git a/templates/request/get/get.handlebars b/templates/request/get/get.handlebars index a8c07c8..65eb642 100644 --- a/templates/request/get/get.handlebars +++ b/templates/request/get/get.handlebars @@ -58,7 +58,7 @@ validator.validate(body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/request/patch/patch.handlebars b/templates/request/patch/patch.handlebars index e72bc10..89960cb 100644 --- a/templates/request/patch/patch.handlebars +++ b/templates/request/patch/patch.handlebars @@ -87,7 +87,7 @@ validator.validate(body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/request/post/post.handlebars b/templates/request/post/post.handlebars index 0b1d8b0..45dce50 100644 --- a/templates/request/post/post.handlebars +++ b/templates/request/post/post.handlebars @@ -85,7 +85,7 @@ validator.validate(body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/request/put/put.handlebars b/templates/request/put/put.handlebars index d0bcc4c..70852b3 100644 --- a/templates/request/put/put.handlebars +++ b/templates/request/put/put.handlebars @@ -85,7 +85,7 @@ validator.validate(body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/delete/delete.handlebars b/templates/supertest/delete/delete.handlebars index c7b8581..4a2d828 100644 --- a/templates/supertest/delete/delete.handlebars +++ b/templates/supertest/delete/delete.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#is assertion 'expect'}} @@ -53,7 +53,7 @@ res.body.should.equal(null); // non-json response or no schema {{/is}} {{#is assertion 'assert'}} - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema {{/is}} {{/validateResponse}} done(); diff --git a/templates/supertest/get/get.handlebars b/templates/supertest/get/get.handlebars index c217952..5b74f1b 100644 --- a/templates/supertest/get/get.handlebars +++ b/templates/supertest/get/get.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#isPdfMediaType returnType}} @@ -64,7 +64,7 @@ res.body.should.equal(null); // non-json response or no schema {{/is}} {{#is assertion 'assert'}} - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema {{/is}} {{/isPdfMediaType}} {{/validateResponse}} diff --git a/templates/supertest/options/options.handlebars b/templates/supertest/options/options.handlebars index d4a71a9..f89422d 100644 --- a/templates/supertest/options/options.handlebars +++ b/templates/supertest/options/options.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#is assertion 'expect'}} @@ -53,7 +53,7 @@ res.body.should.equal(null); // non-json response or no schema {{/is}} {{#is assertion 'assert'}} - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema {{/is}} {{/validateResponse}} done(); diff --git a/templates/supertest/patch/patch.handlebars b/templates/supertest/patch/patch.handlebars index 2f6553b..f364072 100644 --- a/templates/supertest/patch/patch.handlebars +++ b/templates/supertest/patch/patch.handlebars @@ -68,7 +68,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#isPdfMediaType returnType}} @@ -89,7 +89,7 @@ res.body.should.equal(null); // non-json response or no schema {{/is}} {{#is assertion 'assert'}} - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema {{/is}} {{/isPdfMediaType}} {{/validateResponse}} diff --git a/templates/supertest/post/post.handlebars b/templates/supertest/post/post.handlebars index f5672d5..5c6a4dc 100644 --- a/templates/supertest/post/post.handlebars +++ b/templates/supertest/post/post.handlebars @@ -67,7 +67,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#isPdfMediaType returnType}} @@ -88,7 +88,7 @@ res.body.should.equal(null); // non-json response or no schema {{/is}} {{#is assertion 'assert'}} - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema {{/is}} {{/isPdfMediaType}} {{/validateResponse}} diff --git a/templates/supertest/put/put.handlebars b/templates/supertest/put/put.handlebars index 05bddd2..c987674 100644 --- a/templates/supertest/put/put.handlebars +++ b/templates/supertest/put/put.handlebars @@ -67,7 +67,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#isPdfMediaType returnType}} @@ -88,7 +88,7 @@ res.body.should.equal(null); // non-json response or no schema {{/is}} {{#is assertion 'assert'}} - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema {{/is}} {{/isPdfMediaType}} {{/validateResponse}} diff --git a/test/loadTest/compare/request/assert/base-path-test.js b/test/loadTest/compare/request/assert/base-path-test.js index 93972bd..2d3e637 100644 --- a/test/loadTest/compare/request/assert/base-path-test.js +++ b/test/loadTest/compare/request/assert/base-path-test.js @@ -88,7 +88,7 @@ describe('/', function() { assert.equal(res.statusCode, 200); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -120,7 +120,7 @@ describe('/', function() { assert.equal(res.statusCode, 400); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -164,7 +164,7 @@ describe('/', function() { assert.equal(res.statusCode, 500); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -210,7 +210,7 @@ describe('/', function() { assert.equal(res.statusCode, 200); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -242,7 +242,7 @@ describe('/', function() { assert.equal(res.statusCode, 400); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -274,7 +274,7 @@ describe('/', function() { assert.equal(res.statusCode, 500); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); diff --git a/test/loadTest/compare/supertest/assert/base-path-test.js b/test/loadTest/compare/supertest/assert/base-path-test.js index dde725f..6787eb4 100644 --- a/test/loadTest/compare/supertest/assert/base-path-test.js +++ b/test/loadTest/compare/supertest/assert/base-path-test.js @@ -82,7 +82,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -107,7 +107,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -144,7 +144,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -185,7 +185,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -212,7 +212,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -239,7 +239,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); diff --git a/test/loadTest/compare/supertest/assert/user-test.js b/test/loadTest/compare/supertest/assert/user-test.js index 86efa3b..b4cf85f 100644 --- a/test/loadTest/compare/supertest/assert/user-test.js +++ b/test/loadTest/compare/supertest/assert/user-test.js @@ -17,7 +17,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -60,7 +60,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -103,7 +103,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -155,7 +155,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -174,7 +174,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -193,7 +193,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -215,7 +215,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -270,7 +270,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -325,7 +325,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -380,7 +380,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -396,7 +396,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); diff --git a/test/minimal/compare/supertest/assert/base-path-test.js b/test/minimal/compare/supertest/assert/base-path-test.js index ba1a728..1c9e26b 100644 --- a/test/minimal/compare/supertest/assert/base-path-test.js +++ b/test/minimal/compare/supertest/assert/base-path-test.js @@ -18,7 +18,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); diff --git a/test/robust/compare/request/assert/base-path-test.js b/test/robust/compare/request/assert/base-path-test.js index 786e010..09df808 100644 --- a/test/robust/compare/request/assert/base-path-test.js +++ b/test/robust/compare/request/assert/base-path-test.js @@ -88,7 +88,7 @@ describe('/', function() { assert.equal(res.statusCode, 200); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -120,7 +120,7 @@ describe('/', function() { assert.equal(res.statusCode, 400); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -164,7 +164,7 @@ describe('/', function() { assert.equal(res.statusCode, 500); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -210,7 +210,7 @@ describe('/', function() { assert.equal(res.statusCode, 200); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -242,7 +242,7 @@ describe('/', function() { assert.equal(res.statusCode, 400); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); @@ -274,7 +274,7 @@ describe('/', function() { assert.equal(res.statusCode, 500); - assert.true(validator.validate(body, schema)); + assert(validator.validate(body, schema), 'Schema validation failed'); done(); }); }); diff --git a/test/robust/compare/supertest/assert/base-path-test.js b/test/robust/compare/supertest/assert/base-path-test.js index ee3ad4a..0573dbd 100644 --- a/test/robust/compare/supertest/assert/base-path-test.js +++ b/test/robust/compare/supertest/assert/base-path-test.js @@ -82,7 +82,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -107,7 +107,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -144,7 +144,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -183,7 +183,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -208,7 +208,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -233,7 +233,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert.true(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); diff --git a/test/robust/compare/supertest/assert/user-test.js b/test/robust/compare/supertest/assert/user-test.js index 03d7810..8a685e5 100644 --- a/test/robust/compare/supertest/assert/user-test.js +++ b/test/robust/compare/supertest/assert/user-test.js @@ -16,7 +16,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -29,7 +29,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -42,7 +42,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -64,7 +64,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -83,7 +83,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -102,7 +102,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -124,7 +124,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -143,7 +143,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -162,7 +162,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -181,7 +181,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); }); @@ -197,7 +197,7 @@ describe('/user', function() { .end(function(err, res) { if (err) return done(err); - assert.isNull(res.body); // non-json response or no schema + assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema done(); }); });