-
Couldn't load subscription status.
- Fork 14
CLOUDP-271997- IPA-108 delete should return 204 response #487
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
14 commits
Select commit
Hold shift + click to select a range
a5d9157
CLOUDP-271997: IPA 108 - delete method schema
wtrocki 4c12229
Apply suggestions from code review
wtrocki c0502df
Apply suggestions from code review
wtrocki 07d6d7a
fix: format source code
wtrocki 3432d84
fix: adoption for 204 only
wtrocki ad75fa4
fix: formalize format
wtrocki a61e37f
fix: change output format for method
wtrocki ce8c140
fix: follow specification for rule creation
wtrocki 9ec710f
CLOUDP-271997- IPA-108 delete should not return 204 response
wtrocki 225ff8b
fix: rebase on top of previous changeset
wtrocki f9c7030
fix: format
wtrocki 6d4693a
Update tools/spectral/ipa/rulesets/functions/deleteMethod204Response.js
wtrocki de7921b
Merge branch 'main' into CLOUDP-271997-204
wtrocki 173edc0
fix: regen ipas
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
104 changes: 104 additions & 0 deletions
104
tools/spectral/ipa/__tests__/deleteMethod204Response.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,104 @@ | ||
| import testRule from './__helpers__/testRule'; | ||
| import { DiagnosticSeverity } from '@stoplight/types'; | ||
|
|
||
| testRule('xgen-IPA-108-delete-method-return-204-response', [ | ||
| { | ||
| name: 'valid DELETE with 204', | ||
| document: { | ||
| paths: { | ||
| '/resource/{id}': { | ||
| delete: { | ||
| responses: { | ||
| 204: { | ||
| description: 'Resource deleted', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [], | ||
| }, | ||
| { | ||
| name: 'invalid DELETE with no responses', | ||
| document: { | ||
| paths: { | ||
| '/resource/{id}': { | ||
| delete: { | ||
| responses: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-108-delete-method-return-204-response', | ||
| message: 'DELETE method should return 204 No Content status code. http://go/ipa/108', | ||
| path: ['paths', '/resource/{id}', 'delete'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'invalid DELETE with no responses', | ||
| document: { | ||
| paths: { | ||
| '/resource/{id}': { | ||
| delete: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-108-delete-method-return-204-response', | ||
| message: 'DELETE method should return 204 No Content status code. http://go/ipa/108', | ||
| path: ['paths', '/resource/{id}', 'delete'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'invalid DELETE missing 204', | ||
| document: { | ||
| paths: { | ||
| '/resource/{id}': { | ||
| delete: { | ||
| responses: { | ||
| 200: { | ||
| description: 'Resource deleted', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-108-delete-method-return-204-response', | ||
| message: 'DELETE method should return 204 No Content status code. http://go/ipa/108', | ||
| path: ['paths', '/resource/{id}', 'delete'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'valid with exception', | ||
| document: { | ||
| paths: { | ||
| '/resource/{id}': { | ||
| delete: { | ||
| 'x-xgen-IPA-exception': { | ||
| 'xgen-IPA-108-delete-method-return-204-response': 'Legacy API', | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| description: 'Resource deleted', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| 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
25 changes: 25 additions & 0 deletions
25
tools/spectral/ipa/rulesets/functions/deleteMethod204Response.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,25 @@ | ||
| import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; | ||
| import { hasException } from './utils/exceptions.js'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-108-delete-method-return-204-response'; | ||
| const ERROR_MESSAGE = 'DELETE method should return 204 No Content status code.'; | ||
|
|
||
| /** | ||
| * Delete method should return 204 No Content status code | ||
| * | ||
| * @param {object} input - The delete operation object | ||
| * @param {object} _ - Unused | ||
| * @param {object} context - The context object containing the path | ||
| */ | ||
| export default (input, _, { path }) => { | ||
| const responses = input.responses; | ||
| if (hasException(input, RULE_NAME)) { | ||
| collectException(input, RULE_NAME, path); | ||
| return; | ||
| } | ||
|
|
||
| if (!responses || !responses['204']) { | ||
| return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); | ||
| } | ||
| return collectAdoption(path, RULE_NAME); | ||
| }; |
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.