fix: Fix extra slash if basePath is not present

fixes #201
This commit is contained in:
Roman Hotsiy 2017-02-14 09:49:58 +02:00
parent defef011eb
commit a5c03abbe4
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 8 additions and 1 deletions

View File

@ -67,7 +67,7 @@ export class SpecManager {
}
let host = this._schema.host || urlParts.host;
this.basePath = this._schema.basePath || '/';
this.basePath = this._schema.basePath || '';
this.apiUrl = protocol + '://' + host + this.basePath;
if (this.apiUrl.endsWith('/')) {
this.apiUrl = this.apiUrl.substr(0, this.apiUrl.length - 1);

View File

@ -63,6 +63,13 @@ describe('Utils', () => {
specMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
});
it('should use empty basePath when basePath is not present', () => {
specMgr._schema.basePath = undefined;
specMgr._url = 'https://petstore.swagger.io';
specMgr.init();
specMgr.basePath.should.be.equal('');
});
describe('byPointer method', () => {
it('should return correct schema part', ()=> {
let part = specMgr.byPointer('/tags/0');