-
Notifications
You must be signed in to change notification settings - Fork 14
CLOUDP-287247: IPA-109: Validate custom method must use colon (:) followed by the custom verb #328
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 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
48b0633
CLOUDP-287247: IPA-109: Validate custom method must use colon (:) fol…
yelizhenden-mdb a8ec29f
prettier fix
yelizhenden-mdb 9a7fc40
fix
yelizhenden-mdb 0867e2d
address the comments
yelizhenden-mdb 297c81e
address the comments
yelizhenden-mdb 619c8c6
address the comments
yelizhenden-mdb 8c01429
Revert pathUtils.js
yelizhenden-mdb edbcd5d
address the comments
yelizhenden-mdb b57466a
address the comments
yelizhenden-mdb 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
84 changes: 84 additions & 0 deletions
84
tools/spectral/ipa/__tests__/eachCustomMethodMustUseCamelCase.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,84 @@ | ||
| import testRule from './__helpers__/testRule'; | ||
| import { DiagnosticSeverity } from '@stoplight/types'; | ||
|
|
||
| testRule('xgen-IPA-109-custom-method-must-use-camel-case', [ | ||
| { | ||
| name: 'valid methods', | ||
| document: { | ||
| paths: { | ||
| '/a/{exampleId}:methodName': {}, | ||
| '/a:methodName': {}, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| { | ||
| name: 'invalid methods with exception', | ||
| document: { | ||
| paths: { | ||
| '/b/{exampleId}:MethodName': { | ||
| 'x-xgen-IPA-exception': { | ||
| 'xgen-IPA-109-custom-method-must-use-camel-case': {}, | ||
| }, | ||
| }, | ||
| '/b:MethodName': { | ||
| 'x-xgen-IPA-exception': { | ||
| 'xgen-IPA-109-custom-method-must-use-camel-case': {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| { | ||
| name: 'invalid methods', | ||
| document: { | ||
| paths: { | ||
| '/a/{exampleId}:MethodName': {}, | ||
| '/a:MethodName': {}, | ||
| '/a/{exampleId}:method_name': {}, | ||
| '/a:method_name': {}, | ||
| '/a/{exampleId}:': {}, | ||
| '/a:': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-109-custom-method-must-use-camel-case', | ||
| message: 'The custom method name must use camelCase format. Method name: MethodName. http://go/ipa/109', | ||
| path: ['paths', '/a/{exampleId}:MethodName'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-109-custom-method-must-use-camel-case', | ||
| message: 'The custom method name must use camelCase format. Method name: MethodName. http://go/ipa/109', | ||
| path: ['paths', '/a:MethodName'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-109-custom-method-must-use-camel-case', | ||
| message: 'The custom method name must use camelCase format. Method name: method_name. http://go/ipa/109', | ||
| path: ['paths', '/a/{exampleId}:method_name'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-109-custom-method-must-use-camel-case', | ||
| message: 'The custom method name must use camelCase format. Method name: method_name. http://go/ipa/109', | ||
| path: ['paths', '/a:method_name'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-109-custom-method-must-use-camel-case', | ||
| message: 'Custom method name cannot be empty or blank. http://go/ipa/109', | ||
| path: ['paths', '/a/{exampleId}:'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-109-custom-method-must-use-camel-case', | ||
| message: 'Custom method name cannot be empty or blank. http://go/ipa/109', | ||
| path: ['paths', '/a:'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| ]); |
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
26 changes: 26 additions & 0 deletions
26
tools/spectral/ipa/rulesets/functions/eachCustomMethodMustUseCamelCase.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,26 @@ | ||
| import { getCustomMethodName, isCustomMethod } from './utils/resourceEvaluation.js'; | ||
| import { hasException } from './utils/exceptions.js'; | ||
| import { casing } from '@stoplight/spectral-functions'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-109-custom-method-must-use-camel-case'; | ||
| const ERROR_MESSAGE = 'The custom method name must use camelCase format.'; | ||
|
|
||
| export default (input, opts, { path }) => { | ||
| // Extract the path key (e.g., '/a/{exampleId}:method') from the JSONPath. | ||
| let pathKey = path[1]; | ||
|
|
||
| if (!isCustomMethod(pathKey)) return; | ||
|
|
||
| if (hasException(input, RULE_NAME)) { | ||
| return; | ||
| } | ||
|
|
||
| let methodName = getCustomMethodName(pathKey); | ||
| if (methodName.length === 0 || methodName.trim().length === 0) { | ||
| return [{ message: 'Custom method name cannot be empty or blank.' }]; | ||
| } | ||
|
|
||
| if (casing(methodName, { type: 'camel', disallowDigits: true })) { | ||
| return [{ message: `${ERROR_MESSAGE} Method name: ${methodName}.` }]; | ||
| } | ||
| }; | ||
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.