diff --git a/tools/spectral/ipa/__tests__/IPA108DeleteMethod404Response.test.js b/tools/spectral/ipa/__tests__/IPA108DeleteMethod404Response.test.js deleted file mode 100644 index 5f01135ab2..0000000000 --- a/tools/spectral/ipa/__tests__/IPA108DeleteMethod404Response.test.js +++ /dev/null @@ -1,138 +0,0 @@ -import testRule from './__helpers__/testRule'; -import { DiagnosticSeverity } from '@stoplight/types'; - -testRule('xgen-IPA-108-delete-include-404-response', [ - { - name: 'valid DELETE with 404', - document: { - paths: { - '/resource/{id}': { - delete: { - responses: { - 204: {}, - 404: { - description: 'Resource not found', - }, - }, - }, - }, - }, - }, - errors: [], - }, - { - name: 'invalid DELETE with no responses', - document: { - paths: { - '/resource/{id}': { - delete: {}, - }, - }, - }, - errors: [ - { - code: 'xgen-IPA-108-delete-include-404-response', - message: 'DELETE method should include 404 status code for not found resources.', - path: ['paths', '/resource/{id}', 'delete'], - severity: DiagnosticSeverity.Error, - }, - ], - }, - { - name: 'invalid empty responses', - document: { - paths: { - '/resource/{id}': { - delete: { - responses: {}, - }, - }, - }, - }, - errors: [ - { - code: 'xgen-IPA-108-delete-include-404-response', - message: 'DELETE method should include 404 status code for not found resources.', - path: ['paths', '/resource/{id}', 'delete'], - severity: DiagnosticSeverity.Error, - }, - ], - }, - { - name: 'invalid DELETE missing 404', - document: { - paths: { - '/resource/{id}': { - delete: { - responses: { - 204: {}, - }, - }, - }, - }, - }, - errors: [ - { - code: 'xgen-IPA-108-delete-include-404-response', - message: 'DELETE method should include 404 status code for not found resources.', - path: ['paths', '/resource/{id}', 'delete'], - severity: DiagnosticSeverity.Error, - }, - ], - }, - { - name: 'valid with exception', - document: { - paths: { - '/resource/{id}': { - delete: { - 'x-xgen-IPA-exception': { - 'xgen-IPA-108-delete-include-404-response': 'Idempotent delete', - }, - responses: { - 204: {}, - }, - }, - }, - }, - }, - errors: [], - }, - { - name: 'skipped for collection endpoint (no path parameter)', - document: { - paths: { - '/resources': { - delete: { - responses: { - 204: {}, - }, - }, - }, - }, - }, - errors: [], - }, - { - name: 'applied for single resource endpoint (with path parameter)', - document: { - paths: { - '/resources/{resourceId}': { - delete: { - responses: { - 204: {}, - }, - }, - }, - }, - }, - errors: [ - { - code: 'xgen-IPA-108-delete-include-404-response', - message: 'DELETE method should include 404 status code for not found resources.', - path: ['paths', '/resources/{resourceId}', 'delete'], - severity: DiagnosticSeverity.Error, - }, - ], - }, -]); diff --git a/tools/spectral/ipa/rulesets/IPA-108.yaml b/tools/spectral/ipa/rulesets/IPA-108.yaml index ec2b2b7935..dd5f5ba49b 100644 --- a/tools/spectral/ipa/rulesets/IPA-108.yaml +++ b/tools/spectral/ipa/rulesets/IPA-108.yaml @@ -36,22 +36,6 @@ rules: then: function: IPA108DeleteMethod204Response - xgen-IPA-108-delete-include-404-response: - description: | - DELETE method must include 404 response and return it when resource not found. - - ##### Implementation details - Rule checks for the following conditions: - - Applies to all DELETE methods for single resource endpoints (with path parameters) - - Verifies that the method includes a 404 response code - - Fails if the 404 status code is missing from the responses - - Skips validation for collection endpoints (without path parameters) - message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-include-404-response' - severity: error - given: $.paths[*].delete - then: - function: IPA108DeleteMethod404Response - xgen-IPA-108-delete-request-no-body: description: | DELETE method must not have request body. @@ -72,4 +56,3 @@ functions: - IPA108DeleteMethodResponseShouldNotHaveSchema - IPA108DeleteMethod204Response - IPA108DeleteMethodNoRequestBody - - IPA108DeleteMethod404Response diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 3d4a49e599..75a3bf4435 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -376,18 +376,6 @@ Rule checks for the following conditions: - Fails if the 204 status code is missing or if other 2xx responses exist - Skips validation for collection endpoints (without path parameters) -#### xgen-IPA-108-delete-include-404-response - - ![error](https://img.shields.io/badge/error-red) -DELETE method must include 404 response and return it when resource not found. - -##### Implementation details -Rule checks for the following conditions: - - Applies to all DELETE methods for single resource endpoints (with path parameters) - - Verifies that the method includes a 404 response code - - Fails if the 404 status code is missing from the responses - - Skips validation for collection endpoints (without path parameters) - #### xgen-IPA-108-delete-request-no-body ![error](https://img.shields.io/badge/error-red) diff --git a/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethod404Response.js b/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethod404Response.js deleted file mode 100644 index 0bf4a3f934..0000000000 --- a/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethod404Response.js +++ /dev/null @@ -1,33 +0,0 @@ -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; -import { isSingleResourceIdentifier } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; - -const RULE_NAME = 'xgen-IPA-108-delete-include-404-response'; -const ERROR_MESSAGE = 'DELETE method should include 404 status code for not found resources.'; - -/** - * Delete method should include 404 status code for not found resources - * - * @param {object} input - The delete operation object - * @param {object} _ - Unused - * @param {object} context - The context object containing the path - */ -export default (input, _, { path }) => { - // Check if the path is for a single resource (e.g., has path parameter) - // Extract the path from context.path which is an array - const pathString = path[1]; // Assuming path is ['paths', '/resource/{id}', 'delete'] - if (!isSingleResourceIdentifier(pathString)) { - return; - } - - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - - const responses = input.responses; - if (!responses || !responses['404']) { - return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); - } - return collectAdoption(path, RULE_NAME); -};