Skip to content

Commit 24eb00d

Browse files
author
Viktor Holmberg
committed
getAbsoluteBasePath now works with relative path "/"
1 parent bc6e0b6 commit 24eb00d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/swagger.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,24 @@ var SwaggerResource = function(resourceObj, api) {
368368
}
369369
}
370370

371-
SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) {
372-
var parts, pos, url;
371+
SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
372+
var pos, url;
373373
url = this.api.basePath;
374374
pos = url.lastIndexOf(relativeBasePath);
375-
if (pos === -1) {
376-
parts = url.split("/");
377-
url = parts[0] + "//" + parts[2];
375+
var parts = url.split("/");
376+
var rootUrl = parts[0] + "//" + parts[2];
377+
//if the relative path is '/' return the root url
378+
if (relativeBasePath === '/'){
379+
return rootUrl
380+
}
381+
//if the relative path is not in the base path
382+
else if (pos === -1 ) {
378383
if (relativeBasePath.indexOf("/") === 0) {
379384
return url + relativeBasePath;
380385
} else {
381386
return url + "/" + relativeBasePath;
382387
}
383-
} else if (relativeBasePath === "/") {
384-
return url.substring(0, pos);
388+
//If the relative path is in the base path
385389
} else {
386390
return url.substring(0, pos) + relativeBasePath;
387391
}

0 commit comments

Comments
 (0)