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: add Spectral rules to validate required operation channe and channel servers field #913

Merged

Conversation

smoya
Copy link
Member

@smoya smoya commented Nov 28, 2023

Description

Part of asyncapi/spec#991

Despite the name of the branch, this PR adds two new Spectral rules (packed all together to minimize review efforts and to release asap).

This PR adds the last two new Spectral rules related with asyncapi/spec#991.

  1. Checks that the channel field of a required operation (under root) points to a required (under root) channel and not to an optional (under components) channel, no matter if from the same document or from an external.
  2. Checks that the servers field of a required channel (under root) points to a subset of required (under root) servers.

Related issue(s)
asyncapi/spec#991

src/ruleset/v3/ruleset.ts Outdated Show resolved Hide resolved
field: 'channel.$ref',
function: pattern,
functionOptions: {
match: '#\\/channels\\/', // If doesn't match, rule fails.
Copy link
Member Author

Choose a reason for hiding this comment

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

@fmvilas @jonaslagoni I simplified this by using this pattern function Spectral gives us. It allows to match by a regex applied to a field, in this case channel.$ref.
In consequence, I removed the function I created in favor of this.

Copy link
Member

Choose a reason for hiding this comment

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

Much better 👍

fmvilas
fmvilas previously approved these changes Nov 28, 2023
@smoya smoya changed the title feat: add Spectral rule to validate required operation channel field feat: add two Spectral rule to validate required operation channe and channel servers field Nov 28, 2023
Copy link
Member

@fmvilas fmvilas left a comment

Choose a reason for hiding this comment

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

I'm sorry but I can't approve until I see "Spectral rules master" added as a skill in your LinkedIn.

Captura de pantalla 2023-11-28 a las 13 23 03

Copy link
Member

@fmvilas fmvilas left a comment

Choose a reason for hiding this comment

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

😄

@smoya
Copy link
Member Author

smoya commented Nov 28, 2023

I'm sorry but I can't approve until I see "Spectral rules master" added as a skill in your LinkedIn.

Oops, something might went wrong. Can you please check again?

Google Chrome_bGpBgjna

@smoya
Copy link
Member Author

smoya commented Nov 28, 2023

@jonaslagoni @fmvilas FYI I've added to this PR also another rule that checks that the servers field of a required channel (under root) points to a subset of required (under root) servers.

Copy link
Member

@fmvilas fmvilas left a comment

Choose a reason for hiding this comment

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

Just this typo.

* Channel Object rules
*/
'asyncapi3-required-channel-servers-unambiguity': {
description: 'The "servers" field of a channel under the root "channels" object must always reference to a subset of the servers under the root "servers" object.',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: 'The "servers" field of a channel under the root "channels" object must always reference to a subset of the servers under the root "servers" object.',
description: 'The "servers" field of a channel under the root "channels" object must always reference a subset of the servers under the root "servers" object.',

Copy link
Member Author

@smoya smoya Nov 28, 2023

Choose a reason for hiding this comment

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

fixed (didnt apply the suggestion because changes in the expected error msg in tests were needed)

Copy link

sonarcloud bot commented Nov 28, 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 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@smoya smoya requested a review from fmvilas November 28, 2023 12:50
@smoya smoya changed the title feat: add two Spectral rule to validate required operation channe and channel servers field feat: add Spectral rules to validate required operation channe and channel servers field Nov 28, 2023
@smoya
Copy link
Member Author

smoya commented Nov 28, 2023

/rtm

@asyncapi-bot asyncapi-bot merged commit e6cbd74 into asyncapi:next-major-spec Nov 28, 2023
14 checks passed
@smoya smoya deleted the feat/v3OperationChannelRule branch November 28, 2023 13:08
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 3.0.0-next-major-spec.14 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants