diff --git a/src/components/Endpoint/Endpoint.tsx b/src/components/Endpoint/Endpoint.tsx index 67e8da8d..9579eeca 100644 --- a/src/components/Endpoint/Endpoint.tsx +++ b/src/components/Endpoint/Endpoint.tsx @@ -68,18 +68,18 @@ export class Endpoint extends React.Component { ? expandDefaultServerVariables(server.url, server.variables) : server.url; const basePath = getBasePath(normalizedUrl); - const serverBaseUrl = - hideHostname || options.hideHostname - ? basePath === '/' - ? '' - : basePath - : normalizedUrl; return ( - {serverBaseUrl} + + {hideHostname || options.hideHostname + ? basePath === '/' + ? '' + : basePath + : normalizedUrl} + {operation.path} diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 3e521601..16ed57c1 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -175,15 +175,6 @@ export function getBasePath(serverUrl: string): string { } } -export function getBaseUrl(serverUrl: string): string { - try { - return parseURL(serverUrl).origin; - } catch (e) { - // when using with redoc-cli serverUrl can be empty resulting in crash - return serverUrl; - } -} - export function titleize(text: string) { return text.charAt(0).toUpperCase() + text.slice(1); } diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index 7101644f..564fe7de 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -16,7 +16,7 @@ import { Referenced, } from '../types'; import { IS_BROWSER } from './dom'; -import { isNumeric, resolveUrl, isArray, isBoolean, getBaseUrl } from './helpers'; +import { isNumeric, removeQueryString, resolveUrl, isArray, isBoolean } from './helpers'; function isWildcardStatusCode(statusCode: string | number): statusCode is string { return typeof statusCode === 'string' && /\dxx/i.test(statusCode); @@ -606,7 +606,8 @@ export function normalizeServers( return href.endsWith('.html') ? dirname(href) : href; }; - const baseUrl = specUrl === undefined ? getBaseUrl(getHref()) : dirname(specUrl); + const baseUrl = specUrl === undefined ? removeQueryString(getHref()) : dirname(specUrl); + if (servers.length === 0) { // Behaviour defined in OpenAPI spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#openapi-object servers = [