From a5c03abbe4d9d247c426a63ee657500a336e7bfb Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 14 Feb 2017 09:49:58 +0200 Subject: [PATCH] fix: Fix extra slash if basePath is not present fixes #201 --- lib/utils/spec-manager.ts | 2 +- tests/unit/SpecManager.spec.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/utils/spec-manager.ts b/lib/utils/spec-manager.ts index fcf2c681..92b1c4ec 100644 --- a/lib/utils/spec-manager.ts +++ b/lib/utils/spec-manager.ts @@ -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); diff --git a/tests/unit/SpecManager.spec.ts b/tests/unit/SpecManager.spec.ts index 942fd9f8..d5488c35 100644 --- a/tests/unit/SpecManager.spec.ts +++ b/tests/unit/SpecManager.spec.ts @@ -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');