mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +03:00
fix: operation url in static page (#2093)
This commit is contained in:
parent
8869aff406
commit
98eec19647
|
@ -68,18 +68,18 @@ export class Endpoint extends React.Component<EndpointProps, EndpointState> {
|
|||
? expandDefaultServerVariables(server.url, server.variables)
|
||||
: server.url;
|
||||
const basePath = getBasePath(normalizedUrl);
|
||||
const serverBaseUrl =
|
||||
hideHostname || options.hideHostname
|
||||
? basePath === '/'
|
||||
? ''
|
||||
: basePath
|
||||
: normalizedUrl;
|
||||
return (
|
||||
<ServerItem key={normalizedUrl}>
|
||||
<Markdown source={server.description || ''} compact={true} />
|
||||
<SelectOnClick>
|
||||
<ServerUrl>
|
||||
<span>
|
||||
{hideHostname || options.hideHostname
|
||||
? basePath === '/'
|
||||
? ''
|
||||
: basePath
|
||||
: normalizedUrl}
|
||||
</span>
|
||||
<span>{serverBaseUrl}</span>
|
||||
{operation.path}
|
||||
</ServerUrl>
|
||||
</SelectOnClick>
|
||||
|
|
|
@ -175,6 +175,15 @@ 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);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
Referenced,
|
||||
} from '../types';
|
||||
import { IS_BROWSER } from './dom';
|
||||
import { isNumeric, removeQueryString, resolveUrl, isArray, isBoolean } from './helpers';
|
||||
import { isNumeric, resolveUrl, isArray, isBoolean, getBaseUrl } from './helpers';
|
||||
|
||||
function isWildcardStatusCode(statusCode: string | number): statusCode is string {
|
||||
return typeof statusCode === 'string' && /\dxx/i.test(statusCode);
|
||||
|
@ -606,8 +606,7 @@ export function normalizeServers(
|
|||
return href.endsWith('.html') ? dirname(href) : href;
|
||||
};
|
||||
|
||||
const baseUrl = specUrl === undefined ? removeQueryString(getHref()) : dirname(specUrl);
|
||||
|
||||
const baseUrl = specUrl === undefined ? getBaseUrl(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 = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user