From 7db7d4fc914691ed89f5c81289c2af2f69ff20d6 Mon Sep 17 00:00:00 2001 From: Anna Stasiuk Date: Mon, 29 Jul 2019 13:08:17 +0300 Subject: [PATCH] chore: refactor expandServerVariables function (#978) --- src/components/Endpoint/Endpoint.tsx | 35 +++++++++++++++------------- src/utils/openapi.ts | 7 +++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/components/Endpoint/Endpoint.tsx b/src/components/Endpoint/Endpoint.tsx index 00d7bda0..4fd937c0 100644 --- a/src/components/Endpoint/Endpoint.tsx +++ b/src/components/Endpoint/Endpoint.tsx @@ -5,7 +5,7 @@ import { Markdown } from '../Markdown/Markdown'; import { OptionsContext } from '../OptionsProvider'; import { SelectOnClick } from '../SelectOnClick/SelectOnClick'; -import { getBasePath } from '../../utils'; +import { expandDefaultServerVariables, getBasePath } from '../../utils'; import { EndpointInfo, HttpVerb, @@ -60,21 +60,24 @@ export class Endpoint extends React.Component { /> - {operation.servers.map(server => ( - - - - - - {hideHostname || options.hideHostname - ? getBasePath(server.url) - : server.url} - - {operation.path} - - - - ))} + {operation.servers.map(server => { + const normalizedUrl = expandDefaultServerVariables(server.url, server.variables); + return ( + + + + + + {hideHostname || options.hideHostname + ? getBasePath(normalizedUrl) + : normalizedUrl} + + {operation.path} + + + + ); + })} )} diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index 143e7255..294c8f32 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -453,7 +453,7 @@ export function mergeSimilarMediaTypes(types: Dict): Dict (variables[name] && variables[name].default) || match, @@ -482,15 +482,14 @@ export function normalizeServers( ]; } - function normalizeUrl(url: string, variables: object | undefined): string { - url = expandVariables(url, variables); + function normalizeUrl(url: string): string { return resolveUrl(baseUrl, url); } return servers.map(server => { return { ...server, - url: normalizeUrl(server.url, server.variables), + url: normalizeUrl(server.url), description: server.description || '', }; });