From 02bb330be7605d0070708d537daa8b36fad70798 Mon Sep 17 00:00:00 2001 From: "n.gnato" Date: Thu, 26 Jun 2025 16:06:26 +0300 Subject: [PATCH 1/2] Check input attributes value --- src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php b/src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php index 5f69241..a28f36c 100644 --- a/src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php +++ b/src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php @@ -20,7 +20,7 @@ public function __construct(array $data) $concreteClass = new \ReflectionClass($this); - if (property_exists($this, 'attributes')) { + if (property_exists($this, 'attributes') && array_key_exists('attributes', $data)) { $attributesPropertyType = $concreteClass->getProperty('attributes')->getType(); if($attributesPropertyType instanceof \ReflectionUnionType) { From 17c0234d625b86b6e6d031dfabe0b1dcb90ca94e Mon Sep 17 00:00:00 2001 From: "n.gnato" Date: Thu, 26 Jun 2025 16:10:00 +0300 Subject: [PATCH 2/2] Prepare v0.0.7 --- CHANGELOG.md | 8 +++++++- src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c617c2..314f44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.7] - 2025-06-26 + +### Fixed +- `attributes` and `relationships` fields optional in resource object, according to jsonapi v1.1#7.2. + ## [0.0.6] - 2025-04-05 ### Fixed @@ -37,7 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Extract all DTO types from FreeElephants/json-api-php-toolkit to this project -[Unreleased]: https://github.com/FreeElephants/json-api-dto/compare/0.0.6...HEAD +[Unreleased]: https://github.com/FreeElephants/json-api-dto/compare/0.0.7...HEAD +[0.0.7]: https://github.com/FreeElephants/json-api-dto/releases/tag/0.0.7 [0.0.6]: https://github.com/FreeElephants/json-api-dto/releases/tag/0.0.6 [0.0.5]: https://github.com/FreeElephants/json-api-dto/releases/tag/0.0.5 [0.0.4]: https://github.com/FreeElephants/json-api-dto/releases/tag/0.0.4 diff --git a/src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php b/src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php index a28f36c..fd1b61d 100644 --- a/src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php +++ b/src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php @@ -31,7 +31,7 @@ public function __construct(array $data) $this->attributes = new $attributesClass($data['attributes']); } - if (property_exists($this, 'relationships')) { + if (property_exists($this, 'relationships') && array_key_exists('relationships', $data)) { $relationshipsData = $data['relationships']; $concreteClass = new \ReflectionClass($this); $relationshipsProperty = $concreteClass->getProperty('relationships');