From 8a7e83c844555fbb57fabc063361dfa593d2b1ae Mon Sep 17 00:00:00 2001 From: Andrei Matei Date: Wed, 24 Jun 2026 16:28:17 +0100 Subject: [PATCH] fix(ipa): handle delete request bodies in IPA-117 --- ...estResponseBodiesMustBeWellDefined.test.js | 59 +++++++++++++++++++ ...7RequestResponseBodiesMustBeWellDefined.js | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/tools/spectral/ipa/__tests__/IPA117RequestResponseBodiesMustBeWellDefined.test.js b/tools/spectral/ipa/__tests__/IPA117RequestResponseBodiesMustBeWellDefined.test.js index 8a6e53afe2..fcb2059e9f 100644 --- a/tools/spectral/ipa/__tests__/IPA117RequestResponseBodiesMustBeWellDefined.test.js +++ b/tools/spectral/ipa/__tests__/IPA117RequestResponseBodiesMustBeWellDefined.test.js @@ -150,6 +150,65 @@ testRule('xgen-IPA-117-request-response-bodies-must-be-well-defined', [ }, errors: [], }, + { + name: 'delete request body with schema does not crash', + document: { + paths: { + '/resource/{id}': { + delete: { + requestBody: { + content: { + 'application/vnd.atlas.2024-08-05+json': { + schema: { + type: 'object', + }, + }, + }, + }, + responses: { + 204: { + content: { + 'application/vnd.atlas.2024-08-05+json': {}, + }, + }, + }, + }, + }, + }, + }, + errors: [], + }, + { + name: 'delete request body without schema is still validated', + document: { + paths: { + '/resource/{id}': { + delete: { + requestBody: { + content: { + 'application/vnd.atlas.2024-08-05+json': {}, + }, + }, + responses: { + 204: { + content: { + 'application/vnd.atlas.2024-08-05+json': {}, + }, + }, + }, + }, + }, + }, + }, + errors: [ + { + code: 'xgen-IPA-117-request-response-bodies-must-be-well-defined', + message: 'Request and response bodies must have a schema.', + path: ['paths', '/resource/{id}', 'delete', 'requestBody', 'content', 'application/vnd.atlas.2024-08-05+json'], + severity: DiagnosticSeverity.Error, + }, + ], + }, { name: 'invalid requests and responses', document: { diff --git a/tools/spectral/ipa/rulesets/functions/IPA117RequestResponseBodiesMustBeWellDefined.js b/tools/spectral/ipa/rulesets/functions/IPA117RequestResponseBodiesMustBeWellDefined.js index ec8321314a..880425413d 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA117RequestResponseBodiesMustBeWellDefined.js +++ b/tools/spectral/ipa/rulesets/functions/IPA117RequestResponseBodiesMustBeWellDefined.js @@ -31,7 +31,7 @@ export default (input, opts, { path, documentInventory, rule }) => { // Custom POST method 2xx responses if ( httpResponseCode === '202' || - (httpMethod === 'delete' && httpResponseCode.startsWith('2')) || + (httpMethod === 'delete' && httpResponseCode?.startsWith('2')) || (operationIsCustomMethod && httpMethod === 'post' && httpResponseCode?.startsWith('2')) ) { return;