From 37179f3e61352e56d4114bf0f1c7f1a410971304 Mon Sep 17 00:00:00 2001 From: Shelby Sanders Date: Wed, 6 Aug 2014 23:52:59 -0700 Subject: [PATCH 1/4] Pull model description from ctor.settings first --- lib/class-helper.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/class-helper.js b/lib/class-helper.js index 333b5ea..860e008 100644 --- a/lib/class-helper.js +++ b/lib/class-helper.js @@ -43,7 +43,8 @@ var classHelper = module.exports = { generateResourceDocAPIEntry: function(aClass) { return { path: aClass.http.path, - description: aClass.ctor.sharedCtor && aClass.ctor.sharedCtor.description + description: aClass.ctor.settings.description || + aClass.ctor.sharedCtor && aClass.ctor.sharedCtor.description }; } }; From 4d0e711087a9b9ad628a13ec8d003ac7aca37bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 13 Oct 2014 16:32:12 +0200 Subject: [PATCH 2/4] route-helper: include `notes` and `deprecated` --- lib/route-helper.js | 5 +++-- test/route-helper.test.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/route-helper.js b/lib/route-helper.js index 263bbd2..b47b850 100644 --- a/lib/route-helper.js +++ b/lib/route-helper.js @@ -137,8 +137,9 @@ var routeHelper = module.exports = { parameters: accepts, // TODO(schoon) - We don't have descriptions for this yet. responseMessages: [], - summary: route.description, // TODO(schoon) - Excerpt? - notes: '' // TODO(schoon) - `description` metadata? + summary: route.description, + notes: route.notes, + deprecated: route.deprecated })] }; diff --git a/test/route-helper.test.js b/test/route-helper.test.js index 396007c..a25d993 100644 --- a/test/route-helper.test.js +++ b/test/route-helper.test.js @@ -75,6 +75,19 @@ describe('route-helper', function() { expect(opDoc.format).to.equal('byte'); }); + it('includes `notes` metadata', function() { + var doc = createAPIDoc({ + notes: 'some notes' + }); + expect(doc.operations[0].notes).to.equal('some notes'); + }); + + it('includes `deprecated` metadata', function() { + var doc = createAPIDoc({ + deprecated: 'true' + }); + expect(doc.operations[0].deprecated).to.equal('true'); + }); }); // Easy wrapper around createRoute 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 3/4] 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() { From be36f116298fdc7bdf4aef5c3e5462c4a53db083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 13 Oct 2014 17:27:52 +0200 Subject: [PATCH 4/4] Use `1.0.0` as the default app version. Change the default version number returned when the version number cannot be read from `package.json` in CWD. --- lib/swagger.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/swagger.js b/lib/swagger.js index f570500..0edd55f 100644 --- a/lib/swagger.js +++ b/lib/swagger.js @@ -110,17 +110,17 @@ function addRoute(app, uri, doc, opts) { app.get(urlJoin('/', uri), function(req, res) { // There's a few forces at play that require this "hack". The Swagger spec - // requires a `basePath` to be set in the API descriptions. However, we - // can't guarantee this path is either reachable or desirable if it's set + // requires a `basePath` to be set in the API descriptions. However, we + // can't guarantee this path is either reachable or desirable if it's set // as a part of the options. - // + // // The simplest way around this is to reflect the value of the `Host` HTTP // header as the `basePath`. Because we pre-build the Swagger data, we don't // know that header at the time the data is built. if (hasBasePath) { var headers = req.headers; var host = headers.Host || headers.host; - doc.basePath = (opts.protocol || req.protocol) + '://' + + doc.basePath = (opts.protocol || req.protocol) + '://' + host + initialPath; } res.status(200).send(doc); @@ -156,7 +156,7 @@ function getVersion() { try { version = require(path.join(process.cwd(), 'package.json')).version; } catch(e) { - version = ''; + version = '1.0.0'; } return version; }