Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Enable basepath #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module.exports = function getSchema(listingUrl, callback){
}

var declarationUrl = resourceObject.path.replace('{format}', 'json');
getApiDeclarations(listingUrl, declarationUrl, apiDeclarationHandler);
var baseUrl = resourceListing.basePath || listingUrl;
getApiDeclarations(baseUrl, declarationUrl, apiDeclarationHandler);
});

};
Expand All @@ -43,8 +44,11 @@ function getApiDeclarationUrl(listingUrl, declarationUrl) {
// declaration path should be relative, but may be absolute
declarationUrl = url.parse(declarationUrl);
if(declarationUrl.hostname) return url.format(declarationUrl);

listingUrl.pathname += declarationUrl.path;

if (listingUrl.pathname[listingUrl.pathname.length - 1] == '/') {
listingUrl.pathname = listingUrl.pathname.substr(0, listingUrl.pathname.length - 1);
}
listingUrl.pathname += declarationUrl.pathname;
return url.format(listingUrl);
}

Expand All @@ -67,4 +71,4 @@ function getJson(resource, callback){
}
});
}).on('error', callback);
}
}