fix: wrong base url format causing error when constructing new URL (#1996)

Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>
Co-authored-by: Alex Varchuk <olexandr.varchuk@gmail.com>
Co-authored-by: Anastasiia Derymarko <anastasiia@redocly.com>
This commit is contained in:
Andrew Tatomyr 2022-05-12 12:05:22 +03:00 committed by GitHub
parent 311d2ce64d
commit d2cdaa1221
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 4 deletions

View File

@ -5,7 +5,7 @@ describe('build', () => {
it('should use .redocly.yaml', () => {
const r = spawnSync(
'ts-node',
['../../../index.ts', 'build', ' ../../../../demo/openapi.yaml', '--output=redocTest.html'],
['../../../index.ts', 'build', ' ../../../../demo/openapi.yaml', '--output=redoc-test.html'],
{
cwd: __dirname,
shell: true,
@ -17,7 +17,7 @@ describe('build', () => {
const result = `${out}\n${err}`;
try {
const redocStaticFile = readFileSync(`${__dirname}/redocTest.html`, 'utf8');
const redocStaticFile = readFileSync(`${__dirname}/redoc-test.html`, 'utf8');
expect(redocStaticFile).toContain('"options":{"disableSearch":true}');
expect(redocStaticFile).not.toContain('role="search"');
} catch (err) {

View File

@ -0,0 +1,25 @@
import { spawnSync } from 'child_process';
describe('build with url', () => {
// FIXME: remove skip after release
it.skip('should not fail on resolving url', () => {
const r = spawnSync(
'ts-node',
[
'../../../index.ts',
'build',
'http://petstore.swagger.io/v2/swagger.json',
'--output=url-test.html',
],
{
cwd: __dirname,
shell: true,
},
);
const out = r.stdout.toString('utf-8');
const err = r.stderr.toString('utf-8');
const result = `${out}\n${err}`;
expect(result).toContain('bundled successfully');
});
});

View File

@ -58,7 +58,7 @@ export class OpenAPIParser {
this.spec = spec;
this.allowMergeRefs = spec.openapi.startsWith('3.1');
const href = IS_BROWSER ? window.location.href : '';
const href = IS_BROWSER ? window.location.href : undefined;
if (typeof specUrl === 'string') {
this.specUrl = new URL(specUrl, href).href;
}

View File

@ -21,7 +21,7 @@ export class ExampleModel {
this.summary = example.summary;
this.description = example.description;
if (example.externalValue) {
this.externalValueUrl = new URL(example.externalValue, parser.specUrl || '').href;
this.externalValueUrl = new URL(example.externalValue, parser.specUrl).href;
}
parser.exitRef(infoOrRef);