Extend `consumes` and `produces` metadata

- Include XML content-types for both input and output
 - Include JSONP (javascript) content-types for output
This commit is contained in:
Miroslav Bajtoš 2014-10-13 17:24:58 +02:00
parent 4d0e711087
commit 622f6176f3
2 changed files with 38 additions and 2 deletions

View File

@ -28,8 +28,17 @@ function Swagger(loopbackApplication, swaggerApp, opts) {
basePath: loopbackApplication.get('restApiRoot') || '/api',
resourcePath: 'resources',
// Default consumes/produces
consumes: ['application/json', 'application/x-www-form-urlencoded'],
produces: ['application/json'],
consumes: [
'application/json',
'application/x-www-form-urlencoded',
'application/xml', 'text/xml'
],
produces: [
'application/json',
'application/xml', 'text/xml',
// JSONP content types
'application/javascript', 'text/javascript'
],
version: getVersion()
});

View File

@ -104,6 +104,33 @@ describe('swagger definition', function() {
done();
});
});
it('includes `consumes`', function(done) {
var app = mountSwagger();
getAPIDeclaration(app, 'products').end(function(err, res) {
if (err) return done(err);
expect(res.body.consumes).to.have.members([
'application/json',
'application/x-www-form-urlencoded',
'application/xml', 'text/xml'
]);
done();
});
});
it('includes `produces`', function(done) {
var app = mountSwagger();
getAPIDeclaration(app, 'products').end(function(err, res) {
if (err) return done(err);
expect(res.body.produces).to.have.members([
'application/json',
'application/xml', 'text/xml',
// JSONP content types
'application/javascript', 'text/javascript'
]);
done();
});
});
});
describe('Cross-origin resource sharing', function() {