Skip to content

Commit 836c4ae

Browse files
committed
Allow empty DELETE for normal requests
1 parent f3c435b commit 836c4ae

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Listener/JsonApiListener.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,23 +1211,24 @@ protected function _getIncludeList(array $associations, bool $last = true): arra
12111211
protected function _checkRequestData(): void
12121212
{
12131213
$requestMethod = $this->_controller()->getRequest()->getMethod();
1214+
$isRelationshipAction = $this->_checkIsRelationshipsRequest();
12141215

1215-
if ($requestMethod !== 'POST' && $requestMethod !== 'PATCH' && $requestMethod !== 'DELETE') {
1216+
if (($requestMethod !== 'POST' && $requestMethod !== 'PATCH' && $requestMethod !== 'DELETE') ||
1217+
($requestMethod === 'DELETE' && !$isRelationshipAction)) {
12161218
return;
12171219
}
12181220

12191221
$requestData = $this->_controller()->getRequest()->getData();
12201222

12211223
if (empty($requestData)) {
12221224
throw new BadRequestException(
1223-
'Missing request data required for POST and PATCH methods. ' .
1224-
'Make sure that you are sending a request body and that it is valid JSON.'
1225+
'Missing request data required for POST and PATCH methods, as well as DELETE methods to relationship endpoints. ' .
1226+
'Make sure that you are sending a request body and that it is valid JSON.'
12251227
);
12261228
}
12271229

12281230
$validator = new DocumentValidator($requestData, $this->getConfig());
12291231

1230-
$isRelationshipAction = $this->_checkIsRelationshipsRequest();
12311232
if ($isRelationshipAction) {
12321233
$relationshipValidator = new DocumentRelationshipValidator($requestData, $this->getConfig());
12331234
$relationshipValidator->validateUpdateDocument();

0 commit comments

Comments
 (0)