Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove obsolete try...catch #176

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ export const resolve = async (
) => {
const docs = [];

try {
for (const asyncapiDocument of asyncapiDocuments) {
await parse(asyncapiDocument, specVersion, options);
docs.push(asyncapiDocument);
}
} catch (e) {} // eslint-disable-line
for (const asyncapiDocument of asyncapiDocuments) {
await parse(asyncapiDocument, specVersion, options);
docs.push(asyncapiDocument);
}

return docs;
};
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import { describe, expect, test } from '@jest/globals';
import bundle from '../../src';
import { isExternalReference } from '../../src/util';
import path from 'path';
import { JSONParserError } from '@apidevtools/json-schema-ref-parser';

describe('[integration testing] bundler should ', () => {
// as the working directory might get changed, make sure to reset it
let workingDirectory: string = process.cwd();
afterEach(() => {
process.chdir(workingDirectory);
});

test('should return bundled doc', async () => {
const files = ['./tests/camera.yml', './tests/audio.yml'];
const response = await bundle(files, {
Expand Down Expand Up @@ -41,6 +48,21 @@ describe('[integration testing] bundler should ', () => {
).resolves;
});

test('should throw if external `$ref` cannot be resolved', async () => {
const files = ['wrong-external-ref.yaml'];

await expect(
async () => {
await bundle(files, {
xOrigin: true,
base: 'base.yml',
baseDir: path.resolve(process.cwd(), './tests'),
noValidation: true,
})
}
).rejects.toThrow(JSONParserError);
});

test('should be able to bundle base file', async () => {
const files = [
'./tests/base-option/lights.yaml',
Expand Down
10 changes: 10 additions & 0 deletions tests/wrong-external-ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
asyncapi: '2.2.0'
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signups
channels:
user/signedup:
subscribe:
message:
$ref: "./audio.yml#/components/messages/WrongReference"
Loading