-
Couldn't load subscription status.
- Fork 14
CLOUDP-304929: xgen-IPA-102-collection-identifier-camelCase #499
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
60308e4
CLOUDP-304929: camel case
wtrocki a9152e2
fix: reuse method
wtrocki d4ce211
fix: remove function
wtrocki 7751d68
fix: review comments
wtrocki f36dce5
fix: example description
wtrocki c4f3b26
Apply suggestions from Lovisa code review
wtrocki 7459c18
fix: extra unit tests and dedicated handling for slashes in input
wtrocki 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
257 changes: 257 additions & 0 deletions
257
tools/spectral/ipa/__tests__/collectionIdentifierCamelCase.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,257 @@ | ||
| import testRule from './__helpers__/testRule'; | ||
| import { DiagnosticSeverity } from '@stoplight/types'; | ||
|
|
||
| testRule('xgen-IPA-102-collection-identifier-camelCase', [ | ||
| { | ||
| name: 'valid camelCase identifiers', | ||
| document: { | ||
| paths: { | ||
| '/api/v2/atlas/test': {}, | ||
| '/users': {}, | ||
| '/resourceGroups': {}, | ||
| '/userProfiles': {}, | ||
| '/api/v1/test': {}, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| { | ||
| name: 'valid camelCase with path parameters', | ||
| document: { | ||
| paths: { | ||
| '/resourceGroups/{groupId}': {}, | ||
| '/users/{userId}/userProfiles': {}, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| { | ||
| name: 'valid paths with custom methods (only checking identifier part)', | ||
| document: { | ||
| paths: { | ||
| '/resources:any_Custom_Method': {}, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| { | ||
| name: 'invalid PascalCase instead of camelCase', | ||
| document: { | ||
| paths: { | ||
| '/Resources': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'Resources' in path '/Resources' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/Resources'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'invalid with snake_case instead of camelCase', | ||
| document: { | ||
| paths: { | ||
| '/resource_groups': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'resource_groups' in path '/resource_groups' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/resource_groups'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'invalid with kebab-case instead of camelCase', | ||
| document: { | ||
| paths: { | ||
| '/resource-groups': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'resource-groups' in path '/resource-groups' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/resource-groups'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'invalid resource path with invalid casing but valid custom method', | ||
| document: { | ||
| paths: { | ||
| '/Resources:createResource': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'Resources' in path '/Resources:createResource' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/Resources:createResource'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'invalid with consecutive uppercase letters', | ||
| document: { | ||
| paths: { | ||
| '/resourcesAPI': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'resourcesAPI' in path '/resourcesAPI' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/resourcesAPI'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'valid with path-level exception', | ||
| document: { | ||
| paths: { | ||
| '/resource_groups': { | ||
| 'x-xgen-IPA-exception': { | ||
| 'xgen-IPA-102-collection-identifier-camelCase': 'Legacy API path that cannot be changed', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| { | ||
| name: 'reports violations for paths with double slashes', | ||
| document: { | ||
| paths: { | ||
| '/api//users': {}, | ||
| '/resources///{resourceId}': {}, | ||
| '//doubleSlashAtStart': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path '/api//users' contains double slashes (//) which is not allowed. http://go/ipa/102", | ||
| path: ['paths', '/api//users'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path '/resources///{resourceId}' contains double slashes (//) which is not allowed. http://go/ipa/102", | ||
| path: ['paths', '/resources///{resourceId}'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path '//doubleSlashAtStart' contains double slashes (//) which is not allowed. http://go/ipa/102", | ||
| path: ['paths', '//doubleSlashAtStart'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'handles paths with trailing slashes', | ||
| document: { | ||
| paths: { | ||
| '/api/users/': {}, | ||
| '/resources/{resourceId}/': {}, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| { | ||
| name: 'detects multiple failures across a single path', | ||
| document: { | ||
| paths: { | ||
| '/API/Resource_groups/{userId}/User-profiles': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'API' in path '/API/Resource_groups/{userId}/User-profiles' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/API/Resource_groups/{userId}/User-profiles'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'Resource_groups' in path '/API/Resource_groups/{userId}/User-profiles' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/API/Resource_groups/{userId}/User-profiles'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'User-profiles' in path '/API/Resource_groups/{userId}/User-profiles' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/API/Resource_groups/{userId}/User-profiles'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'handles mixed valid and invalid segments with custom methods', | ||
| document: { | ||
| paths: { | ||
| '/api/Valid/Invalid_resource/{id}:validCustomMethod': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'Valid' in path '/api/Valid/Invalid_resource/{id}:validCustomMethod' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/api/Valid/Invalid_resource/{id}:validCustomMethod'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'Invalid_resource' in path '/api/Valid/Invalid_resource/{id}:validCustomMethod' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/api/Valid/Invalid_resource/{id}:validCustomMethod'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'handles double slashes with invalid segments - both issues reported', | ||
| document: { | ||
| paths: { | ||
| '/api//Invalid_segment//resources': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path '/api//Invalid_segment//resources' contains double slashes (//) which is not allowed. http://go/ipa/102", | ||
| path: ['paths', '/api//Invalid_segment//resources'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'Invalid_segment' in path '/api//Invalid_segment//resources' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/api//Invalid_segment//resources'], | ||
| 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
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.
Q: If the path is for example
/resource_groups/{id}/resource_keys, will there be two errors, one forresource_groupsand one forresource_keys?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.
Single violation with 2 errors.
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.
Cool, could you add a test case for it?
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.
Extended multiple test cases.