Skip to content

Commit 89be753

Browse files
committed
fix(ipa): handle delete request bodies in IPA-117
1 parent 405245d commit 89be753

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

tools/spectral/ipa/__tests__/IPA117RequestResponseBodiesMustBeWellDefined.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,65 @@ testRule('xgen-IPA-117-request-response-bodies-must-be-well-defined', [
150150
},
151151
errors: [],
152152
},
153+
{
154+
name: 'delete request body with schema does not crash',
155+
document: {
156+
paths: {
157+
'/resource/{id}': {
158+
delete: {
159+
requestBody: {
160+
content: {
161+
'application/vnd.atlas.2024-08-05+json': {
162+
schema: {
163+
type: 'object',
164+
},
165+
},
166+
},
167+
},
168+
responses: {
169+
204: {
170+
content: {
171+
'application/vnd.atlas.2024-08-05+json': {},
172+
},
173+
},
174+
},
175+
},
176+
},
177+
},
178+
},
179+
errors: [],
180+
},
181+
{
182+
name: 'delete request body without schema is still validated',
183+
document: {
184+
paths: {
185+
'/resource/{id}': {
186+
delete: {
187+
requestBody: {
188+
content: {
189+
'application/vnd.atlas.2024-08-05+json': {},
190+
},
191+
},
192+
responses: {
193+
204: {
194+
content: {
195+
'application/vnd.atlas.2024-08-05+json': {},
196+
},
197+
},
198+
},
199+
},
200+
},
201+
},
202+
},
203+
errors: [
204+
{
205+
code: 'xgen-IPA-117-request-response-bodies-must-be-well-defined',
206+
message: 'Request and response bodies must have a schema.',
207+
path: ['paths', '/resource/{id}', 'delete', 'requestBody', 'content', 'application/vnd.atlas.2024-08-05+json'],
208+
severity: DiagnosticSeverity.Warning,
209+
},
210+
],
211+
},
153212
{
154213
name: 'invalid requests and responses',
155214
document: {

tools/spectral/ipa/rulesets/functions/IPA117RequestResponseBodiesMustBeWellDefined.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default (input, opts, { path, documentInventory, rule }) => {
3131
// Custom POST method 2xx responses
3232
if (
3333
httpResponseCode === '202' ||
34-
(httpMethod === 'delete' && httpResponseCode.startsWith('2')) ||
34+
(httpMethod === 'delete' && httpResponseCode?.startsWith('2')) ||
3535
(operationIsCustomMethod && httpMethod === 'post' && httpResponseCode?.startsWith('2'))
3636
) {
3737
return;

0 commit comments

Comments
 (0)