Skip to content

Commit

Permalink
* Bugfix: was using path instead of resourcePath
Browse files Browse the repository at this point in the history
  • Loading branch information
stelcheck committed Apr 23, 2013
1 parent 98fe645 commit 579f1bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
54 changes: 30 additions & 24 deletions lib/swagger-express/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var _ = require('underscore');
var async = require('async');
var fs = require('fs');
var path = require('path');
var yaml = require('js-yaml');
Expand Down Expand Up @@ -66,9 +66,11 @@ function getSwagger(fragment, fn) {
for (var i = 0; i < fragment.tags.length; i++) {
var tag = fragment.tags[i];
if ('swagger' === tag.title) {
yaml.loadAll(tag.description, fn);
return yaml.loadAll(tag.description, fn);
}
}

return fn(false);
}

/**
Expand All @@ -78,34 +80,36 @@ function getSwagger(fragment, fn) {
* @param {Function} fn
*/
function readJsDoc(file, fn) {
parseJsDocs(file, function (err, doc) {
parseJsDocs(file, function (err, docs) {

if (err) {
fn(err);
}

var resource = {};
resource.apis = [];
var resource = { apis: [] };

function onGetSwagger(api) {
if (api.resourcePath) {
descriptor.apis.push(api);
resource.resourcePath = api.resourcePath;
} else if (api.models) {
resource.models = api.models;
} else {
resource.apis.push(api);
}
async.eachSeries(docs, function (doc, cb) {
getSwagger(doc, function (api) {

if (i === doc.length - 1) {
resources[api.path] = resource;
fn();
}
}
if (!api) {
return cb();
}

for (var i = 0; i < doc.length; i++) {
getSwagger(doc[i], onGetSwagger);
}
if (api.resourcePath) {
descriptor.apis.push(api);
resource.resourcePath = api.resourcePath;
} else if (api.models) {
resource.models = api.models;
} else {
resource.apis.push(api);
}

cb();
});
}, function (err) {
resources[resource.resourcePath] = resource;
fn();
});
});
}

Expand Down Expand Up @@ -211,10 +215,12 @@ exports.init = function (app, opt) {

match = regex.exec(req.path);

if (match !== null) {
if (match) {
result = _.clone(descriptor);

if (match[1] !== null) {
if (match[1]) {

console.log(resources);
resource = resources[match[1]];

if (!resource) {
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"author": "fliptoo <[email protected]>",
"main": "./index",
"dependencies": {
"express": "*"
, "underscore": "*"
, "doctrine": "*"
, "js-yaml": "*"
"express": "*",
"underscore": "*",
"doctrine": "*",
"js-yaml": "*",
"async": "~0.2.7"
},
"devDependencies": {
"jade": "*",
Expand Down

0 comments on commit 579f1bb

Please sign in to comment.