mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-24 17:43:45 +03:00
fix: fix regression double slashes added to full URL display
This commit is contained in:
parent
672ef56507
commit
f29a4fe2ee
6
e2e/e2e.html
Normal file
6
e2e/e2e.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<html>
|
||||
<body>
|
||||
<script src="../bundles/redoc.standalone.js">{}</script>
|
||||
<div id="redoc" />
|
||||
</body>
|
||||
</html>;
|
6
e2e/index.html
Normal file
6
e2e/index.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<html>
|
||||
<body>
|
||||
<script src="../bundles/redoc.standalone.js">{}</script>
|
||||
<div id="redoc" />
|
||||
</body>
|
||||
</html>;
|
64
e2e/integration/misc.e2e.ts
Normal file
64
e2e/integration/misc.e2e.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
// tslint:disable:no-implicit-dependencies
|
||||
import * as yaml from 'yaml-js';
|
||||
|
||||
async function loadSpec(url: string): Promise<any> {
|
||||
const spec = await (await fetch(url)).text();
|
||||
return yaml.load(spec);
|
||||
}
|
||||
|
||||
function initReDoc(win, spec, options = {}) {
|
||||
(win as any).Redoc.init(spec, options, win.document.getElementById('redoc'));
|
||||
}
|
||||
|
||||
describe('Servers', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('e2e/');
|
||||
});
|
||||
|
||||
it('should have valid server', () => {
|
||||
cy.window().then(async win => {
|
||||
const spec = await loadSpec('/demo/openapi.yaml');
|
||||
initReDoc(win, spec, {});
|
||||
|
||||
// TODO add cy-data attributes
|
||||
cy.get('[data-section-id="operation/addPet"]').should(
|
||||
'contain',
|
||||
'http://petstore.swagger.io/v2/pet',
|
||||
);
|
||||
|
||||
cy.get('[data-section-id="operation/addPet"]').should(
|
||||
'contain',
|
||||
'http://petstore.swagger.io/sandbox/pet',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have valid server for when servers not provided', () => {
|
||||
cy.window().then(async win => {
|
||||
const spec = await loadSpec('/demo/openapi.yaml');
|
||||
delete spec.servers;
|
||||
initReDoc(win, spec, {});
|
||||
|
||||
// TODO add cy-data attributes
|
||||
cy.get('[data-section-id="operation/addPet"]').should(
|
||||
'contain',
|
||||
'http://localhost:' + win.location.port + '/e2e/pet',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have valid server for when servers not provided at .html pages', () => {
|
||||
cy.visit('e2e/e2e.html');
|
||||
cy.window().then(async win => {
|
||||
const spec = await loadSpec('/demo/openapi.yaml');
|
||||
delete spec.servers;
|
||||
initReDoc(win, spec, {});
|
||||
|
||||
// TODO add cy-data attributes
|
||||
cy.get('[data-section-id="operation/addPet"]').should(
|
||||
'contain',
|
||||
'http://localhost:' + win.location.port + '/e2e/pet',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -5,7 +5,7 @@ import { Markdown } from '../Markdown/Markdown';
|
|||
import { OptionsContext } from '../OptionsProvider';
|
||||
import { SelectOnClick } from '../SelectOnClick/SelectOnClick';
|
||||
|
||||
import {getBasePath, removeQueryString} from '../../utils';
|
||||
import { getBasePath } from '../../utils';
|
||||
import {
|
||||
EndpointInfo,
|
||||
HttpVerb,
|
||||
|
@ -68,7 +68,7 @@ export class Endpoint extends React.Component<EndpointProps, EndpointState> {
|
|||
<span>
|
||||
{hideHostname || options.hideHostname
|
||||
? getBasePath(server.url)
|
||||
: removeQueryString(server.url)}
|
||||
: server.url}
|
||||
</span>
|
||||
{operation.path}
|
||||
</ServerUrl>
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
Referenced,
|
||||
} from '../types';
|
||||
import { IS_BROWSER } from './dom';
|
||||
import { isNumeric, resolveUrl } from './helpers';
|
||||
import { isNumeric, removeQueryString, resolveUrl, stripTrailingSlash } from './helpers';
|
||||
|
||||
function isWildcardStatusCode(statusCode: string | number): statusCode is string {
|
||||
return typeof statusCode === 'string' && /\dxx/i.test(statusCode);
|
||||
|
@ -367,13 +367,20 @@ export function normalizeServers(
|
|||
specUrl: string | undefined,
|
||||
servers: OpenAPIServer[],
|
||||
): OpenAPIServer[] {
|
||||
const baseUrl =
|
||||
specUrl === undefined ? (IS_BROWSER ? window.location.href : '') : dirname(specUrl);
|
||||
const getHref = () => {
|
||||
if (!IS_BROWSER) {
|
||||
return '';
|
||||
}
|
||||
const href = window.location.href;
|
||||
return href.endsWith('.html') ? dirname(href) : href;
|
||||
};
|
||||
|
||||
const baseUrl = specUrl === undefined ? removeQueryString(getHref()) : dirname(specUrl);
|
||||
|
||||
if (servers.length === 0) {
|
||||
return [
|
||||
{
|
||||
url: baseUrl,
|
||||
url: stripTrailingSlash(baseUrl),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user