parser-js
parser-js copied to clipboard
parser doesn't validates the `$ref` links
Bug Description
If there is a typo in $ref value the parser should throw an error instead of passing the actual $ref.
How to Reproduce
const parser = require('@asyncapi/parser');
parser.parse(`
asyncapi: 2.0.0
info:
title: Streetlights API
version: '1.0.0'
channels:
smartylighting/event/lighting/measured:
subscribe:
message:
$ref: "#components/messages/message1"
components:
messages:
message1:
name: unusedMessage
title: This is most definityly a message.
`).then((doc) => {
console.log(doc.channel('smartylighting/event/lighting/measured').subscribe().message().json());
});
Actual Result
{
'$ref': '#components/messages/message1',
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-parsed': true,
'x-parser-message-name': '<anonymous-message-1>'
}
Expected Result
It should give an error message saying that my $ref path is broken or does not exist.
Since we don't want errors to be thrown but rather bundled together, to throw one big error in the end (I would assume so? git blame @derberg @fmvilas), this option is set to true: https://github.com/asyncapi/parser-js/blob/235efd5cb33df00c206bea3e9b09be9cd9587d87/lib/parser.js#L153
However, we never check that the dereference succedded, not sure if the dereference call actually returns any content, docs say nothing.
Yeah, the idea is that it continues to throw one big error at the end. I'm now wondering if continueOnError actually does that 🤔
I'm now wondering if continueOnError actually does that
it does, it gives an array of all errors
continueOnError: true
it is just an option in refs parser library that we leverage. As you know, when I added custom validations, I did not follow this principle, as far as I remember, my bad. The same option to group errors is also used in Ajv.
hard to say why there is no error, would require some debugging
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
Can we solve this with a pattern field on the JSON Schema Reference Object ?
dunno, maybe there is already some super bullet-proof regex created by the community that can validate $ref as it can represent, link to file, URL or location inside the existing document. It definitely exceeds my knowledge of regex 😄
Otherwise, AJV should throw an error (MissingRefError) anyway. See this example I built: https://onecompiler.com/nodejs/3y9pgk7py
Issue is resolved in v2 ParserJS - now in https://github.com/asyncapi/parser-js/tree/next-major branch thanks to Spectral. Pending to add a test.
cc @magicmatatjahu
Resolved by https://github.com/asyncapi/parser-js/pull/676
:tada: This issue has been resolved in version 2.0.0-next-major.11 :tada:
The release is available on:
Your semantic-release bot :package::rocket: