mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +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 { OptionsContext } from '../OptionsProvider';
|
||||||
import { SelectOnClick } from '../SelectOnClick/SelectOnClick';
|
import { SelectOnClick } from '../SelectOnClick/SelectOnClick';
|
||||||
|
|
||||||
import {getBasePath, removeQueryString} from '../../utils';
|
import { getBasePath } from '../../utils';
|
||||||
import {
|
import {
|
||||||
EndpointInfo,
|
EndpointInfo,
|
||||||
HttpVerb,
|
HttpVerb,
|
||||||
|
@ -68,7 +68,7 @@ export class Endpoint extends React.Component<EndpointProps, EndpointState> {
|
||||||
<span>
|
<span>
|
||||||
{hideHostname || options.hideHostname
|
{hideHostname || options.hideHostname
|
||||||
? getBasePath(server.url)
|
? getBasePath(server.url)
|
||||||
: removeQueryString(server.url)}
|
: server.url}
|
||||||
</span>
|
</span>
|
||||||
{operation.path}
|
{operation.path}
|
||||||
</ServerUrl>
|
</ServerUrl>
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
Referenced,
|
Referenced,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { IS_BROWSER } from './dom';
|
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 {
|
function isWildcardStatusCode(statusCode: string | number): statusCode is string {
|
||||||
return typeof statusCode === 'string' && /\dxx/i.test(statusCode);
|
return typeof statusCode === 'string' && /\dxx/i.test(statusCode);
|
||||||
|
@ -367,13 +367,20 @@ export function normalizeServers(
|
||||||
specUrl: string | undefined,
|
specUrl: string | undefined,
|
||||||
servers: OpenAPIServer[],
|
servers: OpenAPIServer[],
|
||||||
): OpenAPIServer[] {
|
): OpenAPIServer[] {
|
||||||
const baseUrl =
|
const getHref = () => {
|
||||||
specUrl === undefined ? (IS_BROWSER ? window.location.href : '') : dirname(specUrl);
|
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) {
|
if (servers.length === 0) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
url: baseUrl,
|
url: stripTrailingSlash(baseUrl),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user