From 622f6176f39203f987b5072e0fb902ae983be7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 13 Oct 2014 17:24:58 +0200 Subject: [PATCH] Extend `consumes` and `produces` metadata - Include XML content-types for both input and output - Include JSONP (javascript) content-types for output --- lib/swagger.js | 13 +++++++++++-- test/swagger.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/swagger.js b/lib/swagger.js index 7b5644c..f570500 100644 --- a/lib/swagger.js +++ b/lib/swagger.js @@ -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() }); diff --git a/test/swagger.test.js b/test/swagger.test.js index b07f0bb..c6f0987 100644 --- a/test/swagger.test.js +++ b/test/swagger.test.js @@ -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() {