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(rulesets): add rules for validation uniqueness of tag names #2104

Merged
merged 6 commits into from May 30, 2022

Conversation

magicmatatjahu
Copy link
Contributor

@magicmatatjahu magicmatatjahu commented Mar 22, 2022

Fixes #2103

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

Additional context

Part of #2100

Add rule for validation uniqueness of tag names:

Bad Example

tags:
  - name: "Badger"
  - name: "Badger"

Good Example

tags:
  - name: "Aardvark"
  - name: "Badger"

@magicmatatjahu magicmatatjahu added enhancement New feature or request AsyncAPI Issues related to the AsyncAPI ruleset labels Mar 22, 2022
@magicmatatjahu magicmatatjahu marked this pull request as ready for review March 22, 2022 12:37
}, [] as string[]);
}

export default createRulesetFunction<Array<{ name: string }>, null>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting - so as far as I can tell, this function is equally applicable / useful in the openapi context (and this same rule, with different given, would be valuable in the openapi context). @magicmatatjahu @P0lip what do you think re sharing common functions across default rulesets? I know that we have @stoplight/spectral-functions, but the functions in there are very generic, while tags uniqueness is a bit more specific but generic across openapi and asyncapi 🤔.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, it's something that could be potentially shared.
We could create a directory under rulesets package for shared utils.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created shared folder in the rulesets packages with uniquenessTags rule. I also create openapi-tags-uniqueness rule with this same behaviour as for AsyncAPI. If you would like to introduce that rule in separate PR, please let me know, I will remove that.

Copy link
Member

@P0lip P0lip left a comment

Choose a reason for hiding this comment

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

Looking good overall.

docs/reference/openapi-rules.md Outdated Show resolved Hide resolved
docs/reference/asyncapi-rules.md Outdated Show resolved Hide resolved
packages/rulesets/src/oas/index.ts Outdated Show resolved Hide resolved
packages/rulesets/src/asyncapi/index.ts Outdated Show resolved Hide resolved
packages/rulesets/src/shared/functions/uniquenessTags.ts Outdated Show resolved Hide resolved
@magicmatatjahu magicmatatjahu force-pushed the validate-tags-uniqueness branch 2 times, most recently from 42598f5 to f070f4e Compare May 19, 2022 10:57
@magicmatatjahu
Copy link
Contributor Author

@P0lip Sorry for such a delay! All suggestions have been applied. Let me know if everything is ok and if it is ok, you can merge when you want :) Unfortunately I had to do a mixed reset + force push (it was the easiest way for me) because the commit linting was showing me errors when I merged from the Github UI develop branch to my PR.

P0lip
P0lip previously approved these changes May 30, 2022
Copy link
Member

@P0lip P0lip left a comment

Choose a reason for hiding this comment

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

Looking good 🚀

@P0lip P0lip merged commit 4447d81 into stoplightio:develop May 30, 2022
@magicmatatjahu magicmatatjahu deleted the validate-tags-uniqueness branch May 30, 2022 12:25
stoplight-bot pushed a commit that referenced this pull request May 31, 2022
# [@stoplight/spectral-rulesets-v1.9.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-rulesets-v1.8.0...@stoplight/spectral-rulesets-v1.9.0) (2022-05-31)

### Features

* **rulesets:** add rules for validation of server variables and channel parameters ([#2101](#2101)) ([9acc633](9acc633))
* **rulesets:** add rules for validation uniqueness of tag names ([#2104](#2104)) ([4447d81](4447d81))
* **rulesets:** check uniqueness of AsyncAPI operations ([#2121](#2121)) ([8b3cce4](8b3cce4))
@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version @stoplight/spectral-rulesets-v1.9.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AsyncAPI Issues related to the AsyncAPI ruleset enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rule to check uniqueness of tags.*.name
4 participants