Skip to content

Commit

Permalink
fix: remove trailing slash from url when use x-servers
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Apr 23, 2017
1 parent bb3667d commit 2760a34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/components/EndpointLink/endpoint-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(array: T[], key:string):StringMap<T[]> {
return array.reduce<StringMap<T[]>>(function(res, value) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2760a34

Please sign in to comment.