fix: remove trailing slash from url when use x-servers

This commit is contained in:
Roman Hotsiy 2017-04-23 15:26:15 +03:00
parent bb3667d5d6
commit 2760a3410b
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 7 additions and 2 deletions

View File

@ -2,6 +2,7 @@
import { Component, ChangeDetectionStrategy, Input, OnInit, HostListener, HostBinding} from '@angular/core'; import { Component, ChangeDetectionStrategy, Input, OnInit, HostListener, HostBinding} from '@angular/core';
import { BaseComponent, SpecManager } from '../base'; import { BaseComponent, SpecManager } from '../base';
import { OptionsService } from '../../services/'; import { OptionsService } from '../../services/';
import { stripTrailingSlash } from '../../utils/';
export interface ServerInfo { export interface ServerInfo {
description: string; description: string;
@ -36,7 +37,7 @@ export class EndpointLink implements OnInit {
if (servers) { if (servers) {
this.servers = servers.map(({url, description}) => ({ this.servers = servers.map(({url, description}) => ({
description, description,
url: url.startsWith('//') ? `${this.specMgr.apiProtocol}:${url}` : url url: stripTrailingSlash(url.startsWith('//') ? `${this.specMgr.apiProtocol}:${url}` : url)
})); }));
} else { } else {
this.servers = [ this.servers = [

View File

@ -20,6 +20,10 @@ export function isBlank(obj: any): boolean {
return obj == undefined; return obj == undefined;
} }
export function stripTrailingSlash(path:string):string {
return path.endsWith('/') ? path.substring(0, path.length - 1) : path;
}
const hasOwnProperty = Object.prototype.hasOwnProperty; const hasOwnProperty = Object.prototype.hasOwnProperty;
export function groupBy<T>(array: T[], key:string):StringMap<T[]> { export function groupBy<T>(array: T[], key:string):StringMap<T[]> {
return array.reduce<StringMap<T[]>>(function(res, value) { return array.reduce<StringMap<T[]>>(function(res, value) {
@ -119,7 +123,7 @@ export function isJsonLike(contentType: string): boolean {
return contentType.search(/json/i) !== -1; return contentType.search(/json/i) !== -1;
} }
export function getJsonLike(object: object) { export function getJsonLike(object: Object) {
const jsonLikeKeys = Object.keys(object).filter(isJsonLike); const jsonLikeKeys = Object.keys(object).filter(isJsonLike);
if (!jsonLikeKeys.length) { if (!jsonLikeKeys.length) {