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

feat: integrate v2 ParserJS in validate command #376

Merged
merged 5 commits into from
Jan 31, 2023

Conversation

magicmatatjahu
Copy link
Member

@magicmatatjahu magicmatatjahu commented Oct 18, 2022

  • Integrate new ParserJS (with Spectral) in the validate command
  • Integrate new way of validation in other commands - user can see validation diagnostics in generate models and diff commands and determine if command should fail or should perform logic if diagnostics severity is allowed.
  • Write tests

Example input:

asyncapi validate ./test/specification.yaml --diagnostics-format stylish

Example output:

image

Related issue(s)
Part of asyncapi/parser-js#481

@magicmatatjahu magicmatatjahu added the enhancement New feature or request label Oct 18, 2022
@magicmatatjahu magicmatatjahu marked this pull request as ready for review October 18, 2022 11:06
@sonarcloud
Copy link

sonarcloud bot commented Oct 18, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Souvikns
Souvikns previously approved these changes Oct 19, 2022
Copy link
Member

@Souvikns Souvikns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome, one thing to add, when we run the validate command and there is a governance issue it says File ./test/specification.yml and/or referenced documents have governance issues. but the file is valid, shouldn't it say that the file is valid but have governance issue.

@magicmatatjahu
Copy link
Member Author

magicmatatjahu commented Oct 19, 2022

@Souvikns So you wanna see something like:

File ./test/specification.yml is valid but have (and/or referenced documents) governance issues.

?

@Souvikns
Copy link
Member

I use cli to quickly check if the spec I am writing is valid, and yeah this would help

@magicmatatjahu
Copy link
Member Author

@Souvikns Ok, good :) I will change that but before let's see what think about that @derberg

@magicmatatjahu
Copy link
Member Author

@derberg ping 😄

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just left 2 comments
other review will do tomorrow

Comment on lines +7 to +8
import { html, json, junit, stylish, teamcity, text, pretty } from '@stoplight/spectral-cli/dist/formatters';
import { OutputFormat } from '@stoplight/spectral-cli/dist/services/config';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is pretty risky to import these helpers from dist of the CLI.....breaking changes may hurt us later

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will give you errors during the CLI build that these exports don't exist in the path. There is no other way, and creating these functions from scratch or copying them to our codebase is pointless. There is no good solution here and this is the least invasive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we should at least make sure that in package.json we do not allow ^ for spectral-cli dependency

package.json Outdated
@@ -12,11 +12,12 @@
"@asyncapi/diff": "^0.4.0",
"@asyncapi/generator": "^1.9.12",
"@asyncapi/modelina": "^0.59.8",
"@asyncapi/parser": "^1.17.0",
"@asyncapi/parser": "^2.0.0-next-major.6",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here we have the same problem we have with other PR from Jonas. This will be overwritten with next parser release back to 1.18

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left just few comments

if (!parsedAsyncAPI.hasServers()) {return '';}
const servers = parsedAsyncAPI.servers();
return Object.keys(servers).map(server => servers[String(server)].protocol()).join(',');
const listAllProtocolsForFile = (document) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good candidate for Parser API 😉

return this.getFilePath() || this.getFileURL();
}

toDetails() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one sounds weird, do not play well with what it returns

@@ -6,7 +6,7 @@ describe('diff', () => {
test
.stderr()
.stdout()
.command(['diff', './test/specification.yml', './test/specification.yml', '--format=json'])
.command(['diff', './test/specification.yml', './test/specification.yml', '--format=json', '--no-log-diagnostics'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I run diff successfully I do not want to see diagnostics by default. When I run diff I'm interested with diff, unless files that I run through diff have errors and diff cannot run because of it

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since asyncapi/.github#204 the bump.yml workflow is not going to be replicated in repositories that do not have get-global-node-release-workflows. This means that you can now easily update it in parser repository, in the master branch to make sure regular releases will not revert the version update that you did here. So in parser bump workflow you need to add cli to list of ignored repos

@sonarcloud
Copy link

sonarcloud bot commented Jan 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@magicmatatjahu
Copy link
Member Author

@derberg Ok, suggestions applied! Could you check again?

@derberg
Copy link
Member

derberg commented Jan 30, 2023

@magicmatatjahu can you address code smells?

@magicmatatjahu
Copy link
Member Author

magicmatatjahu commented Jan 30, 2023

@derberg You can check that we cannot address such an issues, because Modelina doesn't support in input parsed AsyncAPI document (but only in types) - in the logic we check that. However, that code is in HEAD on master https://github.com/asyncapi/cli/blob/master/src/commands/generate/models.ts#L164 so that code isn't added by my PR.

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magicmatatjahu right, thanks for point that out

@magicmatatjahu
Copy link
Member Author

magicmatatjahu commented Jan 30, 2023

@jonaslagoni Do you wanna check. I changed some code in models generation?

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magicmatatjahu not necessary, but now that I am here LGTM 👍

@magicmatatjahu
Copy link
Member Author

@derberg asyncapi/parser-js#701 and asyncapi/parser-js#702 Could you check? Thanks!

@derberg derberg changed the title feat: integrate v2 ParserJS feat: integrate v2 ParserJS in validate command Jan 31, 2023
@derberg
Copy link
Member

derberg commented Jan 31, 2023

/rtm

@asyncapi-bot asyncapi-bot merged commit fe5bf85 into asyncapi:master Jan 31, 2023
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 0.30.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@magicmatatjahu magicmatatjahu deleted the integrate-spectral branch January 31, 2023 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants