-
Notifications
You must be signed in to change notification settings - Fork 14
CLOUDP 328955: OperationID Validation functions for Get and List methods #814
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c4c8daf
CLOUDP-328955: Attempt to test hack version of new rule w/ ember-infl…
dad86b1
CLOUDP-328955: Switched from ember-inflector to inflection
f1fba85
CLOUDP-328955: Initial get/list configuration
5949469
CLOUDP-328955: Update error message and methodName function option
9b07f1e
CLOUDP-328955: Update docs
f9f86ab
CLOUDP-328955: Added tests and updated docs for ipa104 opId validation
7385b31
CLOUDP-328955: Fixed tests and docs for ipa104 opId validation
d2d16d5
CLOUDP-328955: Update tests and docs
c1efd5b
CLOUDP-328955: Removed unused schema
50b5b4e
Merge branch 'main' into CLOUDP-328955
4e790b4
Removed rogue print statement oops
7924099
Merge branch 'main' into CLOUDP-328955
02d7e53
Merge branch 'main' into CLOUDP-328955
2af9621
Shortened error messages
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
70 changes: 70 additions & 0 deletions
70
tools/spectral/ipa/__tests__/IPA104ValidOperationID.test.js
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,70 @@ | ||
| import testRule from './__helpers__/testRule'; | ||
|
|
||
| // TODO: add tests for xgen-custom-method extension - CLOUDP-306294 | ||
| // TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722 | ||
|
|
||
| testRule('xgen-IPA-104-valid-operation-id', [ | ||
| { | ||
| name: 'valid methods', | ||
| document: { | ||
| paths: { | ||
| '/groups/{groupId}/cluster/{clusterName}': { | ||
| get: { | ||
| operationId: 'getGroupCluster', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| // This test will be enable when the xgen-IPA-104-valid-operation-id is set to warning severity - CLOUDP-329722 | ||
| /* { | ||
| name: 'invalid methods', | ||
| document: { | ||
| paths: { | ||
| '/api/atlas/v2/groups/{groupId}/accessList/{entryValue}/status': { | ||
| get: { | ||
| operationId: 'getProjectIpAccessListStatus', | ||
| }, | ||
| }, | ||
| '/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/limits/{limitName}': { | ||
| get: { | ||
| operationId: 'returnFederatedDatabaseQueryLimit', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-104-valid-operation-id', | ||
| message: | ||
| 'Invalid OperationID. The Operation ID must start with the verb “get” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form.', | ||
| path: ['paths', '/api/atlas/v2/groups/{groupId}/accessList/{entryValue}/status', 'get'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-104-valid-operation-id', | ||
| message: | ||
| 'Invalid OperationID. The Operation ID must start with the verb “get” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form.', | ||
| path: ['paths', '/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/limits/{limitName}', 'get'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, */ | ||
| { | ||
| name: 'invalid methods with exceptions', | ||
| document: { | ||
| paths: { | ||
| '/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': { | ||
| get: { | ||
| operationId: 'getRollingIndex', | ||
| 'x-xgen-IPA-exception': { | ||
| 'xgen-IPA-104-valid-operation-id': 'Reason', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| ]); |
70 changes: 70 additions & 0 deletions
70
tools/spectral/ipa/__tests__/IPA105ValidOperationID.test.js
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,70 @@ | ||
| import testRule from './__helpers__/testRule'; | ||
|
|
||
| // TODO: add tests for xgen-custom-method extension - CLOUDP-306294 | ||
| // TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722 | ||
|
|
||
| testRule('xgen-IPA-105-valid-operation-id', [ | ||
| { | ||
| name: 'valid methods', | ||
| document: { | ||
| paths: { | ||
| '/groups/{groupId}/clusters': { | ||
| get: { | ||
| operationId: 'listGroupClusters', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| // This test will be enable when the xgen-IPA-105-valid-operation-id is set to warning severity - CLOUDP-329722 | ||
| /* { | ||
| name: 'invalid methods', | ||
| document: { | ||
| paths: { | ||
| '/api/atlas/v2/orgs/{orgId}/teams/{teamId}/users': { | ||
| get: { | ||
| operationId: 'listTeamUsers', | ||
| }, | ||
| }, | ||
| '/api/atlas/v2/orgs/{orgId}/events': { | ||
| get: { | ||
| operationId: 'listOrganizationEvents', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-105-valid-operation-id', | ||
| message: | ||
| 'Invalid OperationID. The Operation ID must start with the verb “list” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form, where the last noun is in plural form.', | ||
| path: ['paths', '/api/atlas/v2/groups/{groupId}/databaseUsers/{username}/certs', 'get'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-105-valid-operation-id', | ||
| message: | ||
| 'Invalid OperationID. The Operation ID must start with the verb “list” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form, where the last noun is in plural form.', | ||
| path: ['paths', '/api/atlas/v2/orgs/{orgId}/events', 'get'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, */ | ||
| { | ||
| name: 'invalid methods with exceptions', | ||
| document: { | ||
| paths: { | ||
| '/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/outageSimulation': { | ||
| get: { | ||
| operationId: 'getOutageSimulation', | ||
| 'x-xgen-IPA-exception': { | ||
| 'xgen-IPA-105-valid-operation-id': 'Reason', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| ]); |
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
46 changes: 46 additions & 0 deletions
46
tools/spectral/ipa/rulesets/functions/IPA104ValidOperationID.js
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,46 @@ | ||
| import { generateOperationID } from './utils/operationIdGeneration.js'; | ||
| import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; | ||
| import { hasException } from './utils/exceptions.js'; | ||
| import { | ||
| isSingleResourceIdentifier, | ||
| isResourceCollectionIdentifier, | ||
| isSingletonResource, | ||
| getResourcePathItems, | ||
| isCustomMethodIdentifier, | ||
| } from './utils/resourceEvaluation.js'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-104-valid-operation-id'; | ||
| const ERROR_MESSAGE = | ||
| 'Invalid OperationID. The Operation ID must start with the verb “get” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form.'; | ||
|
|
||
| export default (input, { methodName }, { path, documentInventory }) => { | ||
| const resourcePath = path[1]; | ||
| const oas = documentInventory.resolved; | ||
| const resourcePaths = getResourcePathItems(resourcePath, oas.paths); | ||
|
|
||
| if ( | ||
| isCustomMethodIdentifier(resourcePath) || | ||
| (!isSingleResourceIdentifier(resourcePath) && | ||
| !(isResourceCollectionIdentifier(resourcePath) && isSingletonResource(resourcePaths))) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| if (hasException(input, RULE_NAME)) { | ||
| collectException(input, RULE_NAME, path); | ||
| return; | ||
| } | ||
|
|
||
| const expectedOperationId = generateOperationID(methodName, resourcePath); | ||
| if (expectedOperationId !== input.operationId) { | ||
| const errors = [ | ||
| { | ||
| path, | ||
| message: `${ERROR_MESSAGE} Found ${input.operationId}, expected ${expectedOperationId}.`, | ||
| }, | ||
| ]; | ||
| return collectAndReturnViolation(path, RULE_NAME, errors); | ||
| } | ||
|
|
||
| return collectAdoption(path, RULE_NAME); | ||
| }; | ||
44 changes: 44 additions & 0 deletions
44
tools/spectral/ipa/rulesets/functions/IPA105ValidOperationID.js
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,44 @@ | ||
| import { hasException } from './utils/exceptions.js'; | ||
| import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; | ||
| import { | ||
| getResourcePathItems, | ||
| isCustomMethodIdentifier, | ||
| isResourceCollectionIdentifier, | ||
| isSingletonResource, | ||
| } from './utils/resourceEvaluation.js'; | ||
| import { generateOperationID } from './utils/operationIdGeneration.js'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-105-valid-operation-id'; | ||
| const ERROR_MESSAGE = | ||
| 'Invalid OperationID. The Operation ID must start with the verb “list” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form, where the last noun is in plural form.'; | ||
|
|
||
| export default (input, { methodName }, { path, documentInventory }) => { | ||
| const resourcePath = path[1]; | ||
| const oas = documentInventory.resolved; | ||
|
|
||
| if ( | ||
| isCustomMethodIdentifier(resourcePath) || | ||
| !isResourceCollectionIdentifier(resourcePath) || | ||
| isSingletonResource(getResourcePathItems(resourcePath, oas.paths)) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| if (hasException(input, RULE_NAME)) { | ||
| collectException(input, RULE_NAME, path); | ||
| return; | ||
| } | ||
|
|
||
| const expectedOperationId = generateOperationID(methodName, resourcePath); | ||
| if (expectedOperationId !== input.operationId) { | ||
| const errors = [ | ||
| { | ||
| path, | ||
| message: `${ERROR_MESSAGE} Found ${input.operationId}, expected ${expectedOperationId}.`, | ||
| }, | ||
| ]; | ||
| return collectAndReturnViolation(path, RULE_NAME, errors); | ||
| } | ||
|
|
||
| return collectAdoption(path, RULE_NAME); | ||
| }; |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.