-
Notifications
You must be signed in to change notification settings - Fork 14
CLOUDP 328959: OperationID Validation functions for Create, Delete, and Update methods #805
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 16 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
cbaf505
CLOUDP-328955: Switched from ember-inflector to inflection
eba0010
CLOUDP-328959: Added helper method for stripping custom method names
06d1ca1
CLOUDP-328959: Implemented basic Operation ID Validation for create o…
f6ff5dd
CLOUDP-328959: Implemented basic Operation ID Validation for delete o…
53692d8
CLOUDP-328959: Implemented basic Operation ID Validation for update o…
98cc8a1
Update tools/spectral/ipa/rulesets/functions/IPA108ValidOperationID.js
sphterry 6360e10
CLOUDP-328959: Fixed error handling pattern
f47ef0a
CLOUDP-328959: Added more verbose error messages
5e7a26e
CLOUDP-328959: Added exception handling and removed used variables
1b8e593
Merge branch 'main' into CLOUDP-328959
ff9eb08
CLOUDP-328959: 'prettier' new line
d17c7b6
CLOUDP-328959: Fixed exceptions and imports
60197ca
CLOUDP-328959: Added opID validation yaml for IPA106 and fixed lint e…
769a4a0
CLOUDP-328959: Added opID validation yaml for IPA107 and fixed lint e…
11f4aab
CLOUDP-328959: Added opID validation yaml for IPA108 and fixed lint e…
ae54d57
CLOUDP-328959: Updated docs
ff7df80
CLOUDP-328959: Added tests for validating IPA106 valid operationIds
277cb19
CLOUDP-328959: Added tests for validating IPA108 valid operationIds
bb78336
CLOUDP-328959: comment out unlaunched test
fcef3e4
CLOUDP-328959: Added tests for validating IPA107 valid operationIds
50fa6db
CLOUDP-328959: Added early returns and removed reference to custom me…
5262142
CLOUDP-328959: Edits
1eee9f3
Merge branch 'main' into CLOUDP-328959
ecb2e28
CLOUDP-328959: prettier
3f4fc95
CLOUDP-328959: doc update
29c55c4
CLOUDP-328959: Added methodName to functionOptions
6a9a67d
CLOUDP-328959: Update docs, remove unused schema, add customMethod check
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
38 changes: 38 additions & 0 deletions
38
tools/spectral/ipa/rulesets/functions/IPA106ValidOperationID.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,38 @@ | ||
| import { hasException } from './utils/exceptions.js'; | ||
| import { collectAdoption, collectException, collectAndReturnViolation } from './utils/collectionUtils.js'; | ||
| import { isCustomMethodIdentifier, getCustomMethodName, stripCustomMethodName } from './utils/resourceEvaluation.js'; | ||
| import { generateOperationID } from './utils/operationIdGeneration.js'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-106-valid-operation-id'; | ||
| const ERROR_MESSAGE = | ||
| 'Invalid OperationID. The Operation ID must start with the verb “create” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form.'; | ||
|
|
||
| export default (input, _, { path }) => { | ||
| let resourcePath = path[1]; | ||
| let methodName = 'create'; | ||
yelizhenden-mdb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (hasException(input, RULE_NAME)) { | ||
| collectException(input, RULE_NAME, path); | ||
| return; | ||
| } | ||
|
|
||
| // TODO detect custom method extension - CLOUDP-306294 | ||
|
|
||
| if (isCustomMethodIdentifier(resourcePath)) { | ||
sphterry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| methodName = getCustomMethodName(resourcePath); | ||
| resourcePath = stripCustomMethodName(resourcePath); | ||
| } | ||
|
|
||
| const expectedOperationID = generateOperationID(methodName, resourcePath); | ||
| if (expectedOperationID !== input.operationId) { | ||
| const errors = [ | ||
| { | ||
| path, | ||
| message: `${ERROR_MESSAGE} Found ${input.operationId}, expected ${expectedOperationID}.`, | ||
sphterry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ]; | ||
| return collectAndReturnViolation(path, RULE_NAME, errors); | ||
| } | ||
|
|
||
| collectAdoption(path, RULE_NAME); | ||
| }; | ||
38 changes: 38 additions & 0 deletions
38
tools/spectral/ipa/rulesets/functions/IPA107ValidOperationID.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,38 @@ | ||
| import { hasException } from './utils/exceptions.js'; | ||
| import { collectAdoption, collectException, collectAndReturnViolation } from './utils/collectionUtils.js'; | ||
| import { isCustomMethodIdentifier, getCustomMethodName, stripCustomMethodName } from './utils/resourceEvaluation.js'; | ||
| import { generateOperationID } from './utils/operationIdGeneration.js'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-107-valid-operation-id'; | ||
| const ERROR_MESSAGE = | ||
| 'Invalid OperationID. The Operation ID must start with the verb “update” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. For singleton resources - the last noun may be in plural form.'; | ||
|
|
||
| export default (input, _, { path }) => { | ||
| let resourcePath = path[1]; | ||
| let methodName = 'update'; | ||
|
|
||
| if (hasException(input, RULE_NAME)) { | ||
| collectException(input, RULE_NAME, path); | ||
| return; | ||
| } | ||
|
|
||
| // TODO detect custom method extension - CLOUDP-306294 | ||
|
|
||
| if (isCustomMethodIdentifier(resourcePath)) { | ||
| methodName = getCustomMethodName(resourcePath); | ||
| resourcePath = stripCustomMethodName(resourcePath); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
| collectAdoption(path, RULE_NAME); | ||
| }; |
38 changes: 38 additions & 0 deletions
38
tools/spectral/ipa/rulesets/functions/IPA108ValidOperationID.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,38 @@ | ||
| import { hasException } from './utils/exceptions.js'; | ||
| import { collectAdoption, collectException, collectAndReturnViolation } from './utils/collectionUtils.js'; | ||
| import { isCustomMethodIdentifier, getCustomMethodName, stripCustomMethodName } from './utils/resourceEvaluation.js'; | ||
| import { generateOperationID } from './utils/operationIdGeneration.js'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-108-valid-operation-id'; | ||
| const ERROR_MESSAGE = | ||
| 'Invalid OperationID. The Operation ID must start with the verb “delete” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form.'; | ||
|
|
||
| export default (input, _, { path }) => { | ||
| let resourcePath = path[1]; | ||
| let methodName = 'delete'; | ||
|
|
||
| if (hasException(input, RULE_NAME)) { | ||
| collectException(input, RULE_NAME, path); | ||
| return; | ||
| } | ||
|
|
||
| // TODO detect custom method extension - CLOUDP-306294 | ||
|
|
||
| if (isCustomMethodIdentifier(resourcePath)) { | ||
| methodName = getCustomMethodName(resourcePath); | ||
| resourcePath = stripCustomMethodName(resourcePath); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
| 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
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.