Skip to content

Commit 251fbaa

Browse files
committed
fix resources
1 parent fed18da commit 251fbaa

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

lib/swagger-express/index.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ exports.init = function (app, opt) {
2727
fs.readFile(opt.swaggerUI + '/index.html', function (err, data) {
2828
if (err) fn(err);
2929
var html = data.toString();
30-
var regex = /discoveryUrl:"(.*?),/;
31-
html = html.replace(regex, 'discoveryUrl: "' + opt.basePath + '/api-docs.json"');
30+
var regex = /discoveryUrl:(.*?),/;
31+
html = html.replace(regex, 'discoveryUrl: "' + opt.basePath + '/api-docs.json",');
3232
fs.writeFile(opt.swaggerUI + '/index.html', html, function (err) {
3333
if (err) throw err;
3434
});
@@ -52,12 +52,9 @@ exports.init = function (app, opt) {
5252
if (match != null) {
5353
result = _.clone(descriptor);
5454
if (match[1] != null) {
55-
resource = _.find(resources, function(res) {
56-
return match[1] === '/'+path.basename(req.path);
57-
});
58-
if (resource == null) {
59-
return res.send(404);
60-
}
55+
resource = resources[match[1]];
56+
if (!resource)
57+
return res.send(404);
6158
result.resourcePath = resource.resourcePath;
6259
result.apis = resource.apis;
6360
result.models = resource.models;
@@ -130,7 +127,7 @@ function readYml(file, fn) {
130127
api.resourcePath = resource.resourcePath;
131128
api.description = resource.description;
132129
descriptor.apis.push(api);
133-
resources[resource.path] = resource;
130+
resources[resource.resourcePath] = resource;
134131
fn();
135132
};
136133

0 commit comments

Comments
 (0)