-
Notifications
You must be signed in to change notification settings - Fork 46
Description
When sending an empty relationships object ({}), the API responds with an error saying "The member relationships must be an object."
According to the JSON:API specification, this should be valid — an empty object for relationships is allowed when there are simply no relationships to define.
The issue appears to originate from the following check in RelationshipsValidator.php:
if (!is_object($relationships)) {
return $errors->push(
$this->translator->memberNotObject('/data', 'relationships')
);
}Even though {} is an object in JSON, by the time the validation runs, $relationships may already have been converted to an array, triggering this error.
✅ Expected Behavior
The validator should accept an empty object {} as a valid relationships value and not return an error.
🛠 Suggested Fix
Ensure that $relationships remains an object or adjust the validation logic to correctly handle empty objects.
For example, confirm the type before validation or modify the check to allow empty arrays/objects when appropriate.
if (!is_object($relationships) && !empty($relationships)) {
// only push error if it's not an object AND not empty
return $errors->push(
$this->translator->memberNotObject('/data', 'relationships')
);
}Request example:
{
"data": {
"type": "xxxx",
"id": "5",
"attributes": {
"deleted_at": null
},
"relationships": {}
}
}Response:
{
"jsonapi": {
"version": "1.0"
},
"errors": [
{
"detail": "The member relationships must be an object.",
"source": {
"pointer": "/data/relationships"
},
"status": "400",
"title": "Non-Compliant JSON:API Document"
}
]
}