Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ private function handleNotFound(?ResourceMetadata $parentPropertyMetadata, strin

private function createMetadata(ApiResource $annotation, ResourceMetadata $parentResourceMetadata = null): ResourceMetadata
{
$attributes = (null === $annotation->attributes && [] === $this->defaults['attributes']) ? null : (array) $annotation->attributes + $this->defaults['attributes'];
$attributes = null;
if (null !== $annotation->attributes || [] !== $this->defaults['attributes']) {
$attributes = (array) $annotation->attributes;
foreach ($this->defaults['attributes'] as $key => $value) {
if (!isset($attributes[$key])) {
$attributes[$key] = $value;
}
}
}

if (!$parentResourceMetadata) {
return new ResourceMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ public function create(string $resourceClass): ResourceMetadata
$resource['itemOperations'] = $resource['itemOperations'] ?? $this->defaults['item_operations'] ?? null;
$resource['collectionOperations'] = $resource['collectionOperations'] ?? $this->defaults['collection_operations'] ?? null;
$resource['graphql'] = $resource['graphql'] ?? $this->defaults['graphql'] ?? null;
$resource['attributes'] = (null === $resource['attributes'] && [] === $this->defaults['attributes']) ? null : (array) $resource['attributes'] + $this->defaults['attributes'];

if (null !== $resource['attributes'] || [] !== $this->defaults['attributes']) {
$resource['attributes'] = (array) $resource['attributes'];
foreach ($this->defaults['attributes'] as $key => $value) {
if (!isset($resource['attributes'][$key])) {
$resource['attributes'][$key] = $value;
}
}
}

return $this->update($parentResourceMetadata ?: new ResourceMetadata(), $resource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function testCreateWithDefaults()
'attributes' => [
'pagination_client_enabled' => true,
'pagination_maximum_items_per_page' => 10,
'stateless' => null,
],
]);
$reader = $this->prophesize(Reader::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public function testItFallbacksToDefaultConfiguration()
'subresourceOperations' => null,
'itemOperations' => ['get', 'delete'],
'attributes' => [
'pagination_items_per_page' => null,
'pagination_maximum_items_per_page' => 10,
'stateless' => false,
],
Expand Down