mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 10:04:08 +03:00
chore: refactor expandServerVariables function (#978)
This commit is contained in:
parent
afc7e36cf8
commit
7db7d4fc91
|
@ -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<EndpointProps, EndpointState> {
|
|||
/>
|
||||
</EndpointInfo>
|
||||
<ServersOverlay expanded={expanded}>
|
||||
{operation.servers.map(server => (
|
||||
<ServerItem key={server.url}>
|
||||
{operation.servers.map(server => {
|
||||
const normalizedUrl = expandDefaultServerVariables(server.url, server.variables);
|
||||
return (
|
||||
<ServerItem key={normalizedUrl}>
|
||||
<Markdown source={server.description || ''} compact={true} />
|
||||
<SelectOnClick>
|
||||
<ServerUrl>
|
||||
<span>
|
||||
{hideHostname || options.hideHostname
|
||||
? getBasePath(server.url)
|
||||
: server.url}
|
||||
? getBasePath(normalizedUrl)
|
||||
: normalizedUrl}
|
||||
</span>
|
||||
{operation.path}
|
||||
</ServerUrl>
|
||||
</SelectOnClick>
|
||||
</ServerItem>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</ServersOverlay>
|
||||
</OperationEndpointWrap>
|
||||
)}
|
||||
|
|
|
@ -453,7 +453,7 @@ export function mergeSimilarMediaTypes(types: Dict<OpenAPIMediaType>): Dict<Open
|
|||
return mergedTypes;
|
||||
}
|
||||
|
||||
function expandVariables(url: string, variables: object = {}) {
|
||||
export function expandDefaultServerVariables(url: string, variables: object = {}) {
|
||||
return url.replace(
|
||||
/(?:{)(\w+)(?:})/g,
|
||||
(match, name) => (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 || '',
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user