-
Notifications
You must be signed in to change notification settings - Fork 217
feat(core): add asyncapi-operation-security-defined lint rule #2759
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
Open
harshit078
wants to merge
23
commits into
Redocly:main
Choose a base branch
from
harshit078:add-asyncapi-rule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7acc84a
feat: add 'asyncapi-operation-security-defined' rule
harshit078 ddcf5e1
Merge branch 'main' into add-asyncapi-rule
harshit078 e1a30b6
feat: added asyncapi-operation-security-define rule in tests
harshit078 1fa95ec
feat: added async operation function and updated rules
harshit078 14e7719
Merge branch 'main' into add-asyncapi-rule
harshit078 d6df2bf
feat: updated lint md docs and added tests
harshit078 d31dfbc
feat: added changset
harshit078 ce2789b
Merge branch 'main' into add-asyncapi-rule
harshit078 726a43e
fix: address comments by cursor
harshit078 bb01316
Merge branch 'main' into add-asyncapi-rule
harshit078 f671deb
Merge branch 'main' into add-asyncapi-rule
harshit078 573cbef
fix: removed v1 doc update for async api
harshit078 e0229df
fix: adress comments and remove shared helper
harshit078 27f2667
fix: security defined package
harshit078 0663a44
Merge branch 'main' into add-asyncapi-rule
harshit078 dd80e01
fix: address cursor comment
harshit078 cc6133e
Merge branch 'main' into add-asyncapi-rule
harshit078 4bd8b15
removed: asyncapi from v1 docs
harshit078 f2aee8b
fix: renamed v2 docs and updated to security defined
harshit078 c970602
fix: cursor comments
harshit078 4675ac4
fix: updated AsyncAPI3 docs and files
harshit078 75bf960
fix: removed v1 docs for async api
harshit078 bf96d18
fix: address cursor comments
harshit078 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@redocly/openapi-core": minor | ||
| --- | ||
|
|
||
| Added `asyncapi-operation-security-defined` rule for AsyncAPI 2.x that reports when a security scheme referenced from an operation or server `security` array is not defined in `components.securitySchemes`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # security-defined | ||
|
|
||
| Verifies that every security scheme referenced from an operation or server `security` array is defined in `components.securitySchemes`. | ||
|
|
||
| | AsyncAPI | Compatibility | | ||
| | -------- | ------------- | | ||
| | 2.6 | ✅ | | ||
| | 3.0 | ✅ | | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| ## API design principles | ||
|
|
||
| In AsyncAPI 2.x, `security` entries on operations and servers are bare security scheme names that must match a key under `components.securitySchemes`. | ||
| A typo or rename leaves the reference dangling, and the document remains structurally valid — the mismatch is only visible to clients at runtime. | ||
|
|
||
| In AsyncAPI 3.0, `security` entries are `SecurityScheme` objects, typically expressed as `$ref`s into `components.securitySchemes`. The rule reports when a security `$ref` does not point into `components.securitySchemes` or when it points at a name that is not defined there. | ||
|
|
||
| This rule catches those name mismatches at lint time. | ||
|
|
||
| ## Configuration | ||
|
|
||
| | Option | Type | Description | | ||
| | -------- | ------ | ------------------------------------------------------------------------------------------ | | ||
| | severity | string | Possible values: `off`, `warn`, `error`. Default `error` (in `recommended` configuration). | | ||
|
|
||
| An example configuration: | ||
|
|
||
| ```yaml | ||
| rules: | ||
| security-defined: error | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| Given this configuration: | ||
|
|
||
| ```yaml | ||
| rules: | ||
| security-defined: error | ||
| ``` | ||
|
|
||
| Example of an **incorrect** security definition due to a mismatch between the referenced name and `components.securitySchemes`: | ||
|
|
||
| ```yaml | ||
| asyncapi: '2.6.0' | ||
| channels: | ||
| user/signedup: | ||
| subscribe: | ||
| security: | ||
| - OAuth: [] # no matching scheme in components.securitySchemes | ||
| message: | ||
| messageId: UserSignedUp | ||
| components: | ||
| securitySchemes: | ||
| JWT: | ||
| type: http | ||
| scheme: bearer | ||
| ``` | ||
|
|
||
| Example of a **correct** AsyncAPI 2.x security definition: | ||
|
|
||
| ```yaml | ||
| asyncapi: '2.6.0' | ||
| channels: | ||
| user/signedup: | ||
| subscribe: | ||
| security: | ||
| - JWT: [] | ||
| message: | ||
| messageId: UserSignedUp | ||
| components: | ||
| securitySchemes: | ||
| JWT: | ||
| type: http | ||
| scheme: bearer | ||
| ``` | ||
|
|
||
| Example of an **incorrect** AsyncAPI 3.0 security definition where the `$ref` points at an undefined scheme: | ||
|
|
||
| ```yaml | ||
| asyncapi: '3.0.0' | ||
| operations: | ||
| sendMessage: | ||
| action: send | ||
| channel: | ||
| $ref: '#/channels/userSignedUp' | ||
| security: | ||
| - $ref: '#/components/securitySchemes/OAuth' | ||
| components: | ||
| securitySchemes: | ||
| JWT: | ||
| type: http | ||
| scheme: bearer | ||
| ``` | ||
|
|
||
| Example of a **correct** AsyncAPI 3.0 security definition: | ||
|
|
||
| ```yaml | ||
| asyncapi: '3.0.0' | ||
| operations: | ||
| sendMessage: | ||
| action: send | ||
| channel: | ||
| $ref: '#/channels/userSignedUp' | ||
| security: | ||
| - $ref: '#/components/securitySchemes/JWT' | ||
| components: | ||
| securitySchemes: | ||
| JWT: | ||
| type: http | ||
| scheme: bearer | ||
| ``` | ||
|
|
||
| ## Related rules | ||
|
|
||
| - [security-defined](../oas/security-defined.md) — equivalent rule for OpenAPI. | ||
|
|
||
| ## Resources | ||
|
|
||
| - [AsyncAPI 2.x rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/async2/security-defined.ts) | ||
| - [AsyncAPI 3.0 rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/async3/security-defined.ts) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code uses the rule name
security-defined, but the docs still sayasyncapi-operation-security-definedCan you update related changes?