Skip to content

Optional attributes field #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/FreeElephants/JsonApi/DTO/AbstractResourceObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');
Expand Down