Skip to content

Commit

Permalink
fix: wrong base url format causing error when constructing new URL (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
4 people committed May 12, 2022
1 parent 311d2ce commit d2cdaa1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cli/__test__/build/configRedoc/index.test.ts
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions cli/__test__/build/configRedoc/url.test.ts
@@ -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');
});
});
2 changes: 1 addition & 1 deletion src/services/OpenAPIParser.ts
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/models/Example.ts
Expand Up @@ -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);

Expand Down

0 comments on commit d2cdaa1

Please sign in to comment.