Repository navigation
Conversation
There was a problem hiding this comment.
Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
derberg
left a comment
There was a problem hiding this comment.
I think I found your problem, have a look at my comments
I have to say that it is super hard to review this PR because of all the autoformatted changes. Can we do something about it?
|
@derberg I am not able to figure out what to pass inside |
derberg
left a comment
There was a problem hiding this comment.
I provided a few hints. Sorry, I just realized this code related to validation that I wrote is complicated and provided JSDoc is lame 😞
Lemme know if you need more help. And please remember to remove all the autoformatted parts before next review as is is really hard to review
| 'server does not have a corresponding schema object', | ||
| new Map(), | ||
| fileFormat, | ||
| parser |
There was a problem hiding this comment.
here you should pass information if original AsyncAPI file passed into parser was YAML or JSON. It is in fileFormat variable.
| 'servers', | ||
| 'server does not have a corresponding schema object', | ||
| new Map(), | ||
| fileFormat, |
There was a problem hiding this comment.
it should be originalAsyncAPIDocument, the oryginal file as string. It is needed because returned error will have to indicate where exactly in the file (line, column) the error is in, so original document is needed. So later in the UI you can highlight the error
| detail: | ||
| 'You shall not pass, no schema parser available that can parse this schema. The good news is that we have one for Avro, just install @asyncapi/avro-schema-parser and use registerSchemaParser to register it with the current parser', | ||
| validationErrors: groupValidationErrors( | ||
| 'servers', |
There was a problem hiding this comment.
it is not server, it is channels
| validationErrors: groupValidationErrors( | ||
| 'servers', | ||
| 'server does not have a corresponding schema object', | ||
| new Map(), |
There was a problem hiding this comment.
this is a map of errors, so definitely cannot be empty.
you choose to use groupValidationErrors, which is much better from initial implementation.
Why?
because you will not throw error immediately when it is found. The intention with groupValidationErrors is to use it in error when you want to throw it after thing through all messages.
without such approach, you would get error for one message, then you fix, then error for another message, and fix, and so on, not so nice.
JSDoc say this about the map
map of error elements cause the validation error might happen in many places in the document.
The key should have a path information where the error was found, the value holds information about error element but it is not mandatory
so the key is the json path pointing to the affected place in the document. Later it ends up in error object under location.jsonPointer. You will need to use tilde util for sure.
So from your test example,
- first you need to make
validateAndConvertMessageaware of the channel name and operation where validated message is located. - Then in this map, the key would be something like `tilde(${channelName})/${operationName}/message/schemaFormat
- and value is, I don't remember but probably broken value 🤷🏼
does it make sense?
| const parser = PARSERS[String(schemaFormat)]; | ||
|
|
||
| if (!parser) { | ||
| throw new ParserError({ |
There was a problem hiding this comment.
when using groupValidationErrors, do not throw error immediately. Let parser go through all messages, so they you throw error a the end, with all broken schemaFormats from all messages. Look into customValidators how they use it.
I think it will be trick, but yeah, try
|
@derberg I have made changes as you have suggested but I am still getting errors while running the test and am not sure about the implementation of throwing all the errors at once.😅 |
|
Hi @derberg |
derberg
left a comment
There was a problem hiding this comment.
please convert it to regular PR so we can have tests running in a PR. Also please remove autoformatting also from test/parse_test.js file 😅
|
@derberg Done! 😁 |
@magicmatatjahu Will using the above be a good idea because I can't clear the array after the throw command. Please suggest if any other better solution exists. |
|
@derberg @magicmatatjahu I have implemented the requested changes but failed the |
There was a problem hiding this comment.
I'm sorry, but I won't accept the current solution with the global array schemaValidationErrors and the reason is simple: parsing is done in an asynchronous way and if we run the function 100 or even more times in a row it may happen that the array schemaValidationErrors will have some data (or will be deleted) at the moment when other independent parsing is done. This can happen in our server-api project as well as in studio. If we still want to have schemaValidationErrors we need create that array in local scope (e.g. at the beginning of the parse function) and pass it to the corresponding functions. Global values should be independent.
|
@derberg @magicmatatjahu I have made the requested changes kindly review the PR :) |
derberg
left a comment
There was a problem hiding this comment.
I found why your tests fail, also added some comments to improve naming of variables and text of error messages.
good work so far 🚀
| const defaultSchemaFormat = getDefaultSchemaFormat(parsedAsyncAPIDocument.asyncapi); | ||
| const schemaFormat = msg.schemaFormat || defaultSchemaFormat; | ||
| const parser = PARSERS[String(schemaFormat)]; | ||
| const errorMap = new Map(); |
There was a problem hiding this comment.
this whole error map creation is related to if (!parser) { only, so better move it there for clarity
|
hi @derberg While implementing the requested changes I am confused about some requested changes like
Screenshot of error i am currently facing while running |
|
@derberg @magicmatatjahu sorry I was caught up with some college work 😅. I have made some changes kindly review them.🙂 |
derberg
left a comment
There was a problem hiding this comment.
hey, left some comments
also please make sure that you always run npm run lint before you submit something for review
| if(schemaValidationErrors.length) { | ||
| const errors = schemaValidationErrors.map(e => ({ | ||
| ...e, | ||
| dataPath: e.dataPath.replace(/^\./, ''), | ||
| })); | ||
| schemaValidationErrors.length=0; | ||
| throw new ParserError({ | ||
| type: validationError, | ||
| title: 'The document uses a schema format that parser does not support', | ||
| detail:'Parser is not able to parse messages as they are provided in not supported schema. Parser can be extended to parse other schemas, you can also use existing custom schema parsers for Avro, RAML Data Types and OpenAPI Schema. Install one of them, @asyncapi/avro-schema-parser, @asyncapi/openapi-schema-parser or @asyncapi/ramldt-schema-parser and use registerSchemaParser function to register it with the this parser', | ||
| parsedJSON, | ||
| validationErrors: errors, | ||
| }); | ||
| } |
There was a problem hiding this comment.
| if(schemaValidationErrors.length) { | |
| const errors = schemaValidationErrors.map(e => ({ | |
| ...e, | |
| dataPath: e.dataPath.replace(/^\./, ''), | |
| })); | |
| schemaValidationErrors.length=0; | |
| throw new ParserError({ | |
| type: validationError, | |
| title: 'The document uses a schema format that parser does not support', | |
| detail:'Parser is not able to parse messages as they are provided in not supported schema. Parser can be extended to parse other schemas, you can also use existing custom schema parsers for Avro, RAML Data Types and OpenAPI Schema. Install one of them, @asyncapi/avro-schema-parser, @asyncapi/openapi-schema-parser or @asyncapi/ramldt-schema-parser and use registerSchemaParser function to register it with the this parser', | |
| parsedJSON, | |
| validationErrors: errors, | |
| }); | |
| } | |
| if (schemaValidationErrors.size) { | |
| throw new ParserError({ | |
| type: validationError, | |
| title: 'The document uses a schema format that parser does not support', | |
| detail: 'Parser is not able to parse messages as they are provided in not supported schema. Parser can be extended to parse other schemas, you can also use existing custom schema parsers for Avro, RAML Data Types and OpenAPI Schema. Install one of them, @asyncapi/avro-schema-parser, @asyncapi/openapi-schema-parser or @asyncapi/ramldt-schema-parser and use registerSchemaParser function to register it with the this parser', | |
| parsedJSON, | |
| validationErrors: groupValidationErrors( | |
| 'channels', | |
| 'uses unsupported schema format', | |
| schemaValidationErrors, | |
| asyncapiYAMLorJSON, | |
| initialFormat | |
| ) | |
| }); | |
| } |
There was a problem hiding this comment.
This is only half the working code. This will now trigger good errors so you need to adjust tests accordingly
The only thing that doesn't work in this code is line 219 -> 'channels'. It is hardcoded to channels even though sometimes as you know error might be not in message under channels but also in message under components, so sometimes instead of 'channels' you must pass 'components'.
We need to figure out how to do this....so first please apply my suggestions, fix tests and what should left for us to think about is this channels vs components thingy. I think the only way to solve it will be to refactor groupValidationErrors somehow
|
@ritik307 Do you have time for further contribution? Any problems/issues? |
|
@magicmatatjahu Sorry for the late response. Yes, I do have time to contribute but not as much as I had before 😔. As of now, I will only be able to contribute on weekends. |
|
@ritik307 no worries, just keep in mind that with this one you are almost done, so do not lose the time that you've already put in this PR. It is a great addition. |
|
Sorry for the delay. I made the changes but didn't forget to push the code. I am still facing some doubts though. Kindly help me out |
|
@ritik307 if you did not push the code, I'm not sure how can I help 😄 |
|
@derberg Sorry for the miscommunication. I meant I have pushed the code can you review it.😊 |
|
Kudos, SonarCloud Quality Gate passed!
|
| }; | ||
| await checkErrorWrapper(async () => { | ||
| await parser.parse(notRegisteredFormatFile, { path: __filename }); | ||
| }, errorObject); |
There was a problem hiding this comment.
| }, errorObject); | |
| }, expectedErrorObject); |
|
@ritik307 you definitely need to run tests before you push code 😄 |
|
@ritik307 you were pretty advanced here, do not want to continue? |
|
This pull request has been automatically marked as stale because it has not had recent activity 😴 It will be closed in 120 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation. There can be many reasons why some specific pull request 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 pull request forward. Connect with us through one of many communication channels we established here. Thank you for your patience ❤️ |
|
I am closing due to lack of response. |









Description
parser.jsRelated issue(s)
Fixes #157