From 6190d11d03c2361504fd48085081f21f147cbe24 Mon Sep 17 00:00:00 2001 From: Tiago Relvao Date: Wed, 16 Apr 2014 16:48:15 +0100 Subject: [PATCH] Update index.js Fixes the case when you pass a bunch of controller files but only some of them contain jsdoc annotations. eg: app.use(swagger.init(app, { apiVersion: '1.0', ..., apis: fs.readdirSync('./controllers').map(function (filename) { return path.join(controllersPath, filename); }), ... })); --- lib/swagger-express/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/swagger-express/index.js b/lib/swagger-express/index.js index 88bea8d5..53d5cace 100644 --- a/lib/swagger-express/index.js +++ b/lib/swagger-express/index.js @@ -46,6 +46,11 @@ function parseJsDocs(file, fn) { var fragments = js.match(regex); var docs = []; + if (!fragments) { + fn(null, docs); + return; + } + for (var i = 0; i < fragments.length; i++) { var fragment = fragments[i]; var doc = doctrine.parse(fragment, { unwrap: true });