Skip to content

Commit

Permalink
fix: throw correct errors located in files that are $ref of another $…
Browse files Browse the repository at this point in the history
…ref (#188)
  • Loading branch information
derberg authored Oct 24, 2020
1 parent e05550b commit e40bead
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getAST = (asyncapiYAMLorJSON, initialFormat) => {

const findNode = (obj, location) => {
for (const key of location) {
obj = obj[utils.untilde(key)];
obj = obj ? obj[utils.untilde(key)] : null;
}
return obj;
};
Expand Down
13 changes: 13 additions & 0 deletions test/parse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,19 @@ describe('parse()', function() {
}, expectedErrorObject);
});

it('should throw proper error even if issue is inside $refed file of a $refed file', async function() {
const expectedErrorObject = {
type: 'https://github.com/asyncapi/parser-js/schema-validation-errors',
title: 'This is not a valid AsyncAPI Schema Object.'
};

await checkErrorWrapper(async () => {
await parser.parse(fs.readFileSync(path.resolve(__dirname, './wrong/good-ref-to-broken-file.yaml'), 'utf8'), {
path: __filename,
});
}, expectedErrorObject);
});

it('should throw error if document is invalid YAML', async function() {
const expectedErrorObject = {
type: 'https://github.com/asyncapi/parser-js/invalid-yaml',
Expand Down
9 changes: 9 additions & 0 deletions test/wrong/good-ref-to-broken-file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
asyncapi: 2.0.0
info:
title: My API
version: '1.0.0'
channels:
mychannel:
publish:
message:
$ref: 'wrong/good-refed-file.yml'
2 changes: 2 additions & 0 deletions test/wrong/good-refed-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
payload:
$ref: refed-file-broken-schema.yml
4 changes: 4 additions & 0 deletions test/wrong/refed-file-broken-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type: string
properties:
name:
type: string

0 comments on commit e40bead

Please sign in to comment.