diff --git a/lib/components/EndpointLink/endpoint-link.ts b/lib/components/EndpointLink/endpoint-link.ts index 7922a6f132..51dad69bea 100644 --- a/lib/components/EndpointLink/endpoint-link.ts +++ b/lib/components/EndpointLink/endpoint-link.ts @@ -2,6 +2,7 @@ import { Component, ChangeDetectionStrategy, Input, OnInit, HostListener, HostBinding} from '@angular/core'; import { BaseComponent, SpecManager } from '../base'; import { OptionsService } from '../../services/'; +import { stripTrailingSlash } from '../../utils/'; export interface ServerInfo { description: string; @@ -36,7 +37,7 @@ export class EndpointLink implements OnInit { if (servers) { this.servers = servers.map(({url, description}) => ({ description, - url: url.startsWith('//') ? `${this.specMgr.apiProtocol}:${url}` : url + url: stripTrailingSlash(url.startsWith('//') ? `${this.specMgr.apiProtocol}:${url}` : url) })); } else { this.servers = [ diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index a52ffe27d1..da30e1fc01 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -20,6 +20,10 @@ export function isBlank(obj: any): boolean { return obj == undefined; } +export function stripTrailingSlash(path:string):string { + return path.endsWith('/') ? path.substring(0, path.length - 1) : path; +} + const hasOwnProperty = Object.prototype.hasOwnProperty; export function groupBy(array: T[], key:string):StringMap { return array.reduce>(function(res, value) { @@ -119,7 +123,7 @@ export function isJsonLike(contentType: string): boolean { return contentType.search(/json/i) !== -1; } -export function getJsonLike(object: object) { +export function getJsonLike(object: Object) { const jsonLikeKeys = Object.keys(object).filter(isJsonLike); if (!jsonLikeKeys.length) {