Comparing version 0.0.5 to 0.0.6
10
index.js
@@ -301,4 +301,6 @@ var express = require('express') | ||
if (types.indexOf(req.header('content-type')) > -1) { | ||
if (contentTypes[req.header('content-type')]) { | ||
var mime = req.header('content-type').split(';')[0]; | ||
if (types.indexOf(mime) > -1) { | ||
if (contentTypes[mime]) { | ||
if (!req.body) { | ||
@@ -309,7 +311,7 @@ return next(new Error("Missing req.body for " + req.path)); | ||
req.body, | ||
contentTypes[req.header('content-type')] | ||
contentTypes[mime] | ||
); | ||
if (report.errors.length > 0) { | ||
res.send(400, { | ||
error: 'Body does not match schema for ' + req.header('content-type'), | ||
error: 'Body does not match schema for ' + mime, | ||
errors: report.errors | ||
@@ -316,0 +318,0 @@ }); |
{ | ||
"name": "flair-doc", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Swagger-compliant REST API documentation generator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -608,3 +608,29 @@ var should = require('should') | ||
describe('#consumes', function() { | ||
var app = express(); | ||
app.post( | ||
'/blah', | ||
flair.consumes("application/vnd.something+json"), | ||
function(req, res) { | ||
res.send("Yay!"); | ||
} | ||
); | ||
it('should handle request content-types with extra information', function(done) { | ||
supertest(app) | ||
.post('/blah') | ||
.set('Content-Type', 'application/vnd.something+json; charset=utf-8') | ||
.expect(200, function(err, res) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
supertest(app) | ||
.post('/blah') | ||
.set('Content-Type', 'application/vnd.wrong+json; charset=utf-8') | ||
.expect(400, done); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42233
1201