Skip to content
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

fix merging of api resource data fails or has existing data go missing #16146

Open
wants to merge 1 commit into
base: 1.13
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public function merge(array $oldMetadata, array $newMetadata): array

foreach ($newMetadata as $key => $value) {
if ('properties' === $key) {
if ($value === null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe adjusting \Sylius\Bundle\ApiBundle\ApiPlatform\Metadata\MergingXmlExtractor::buildResource properties is better?

continue;
}

foreach ($value as $keyProperty => $property) {
$oldMetadata[$key][$keyProperty] = $property;
}
Expand All @@ -47,7 +51,9 @@ public function merge(array $oldMetadata, array $newMetadata): array
continue;
}

$oldMetadata[$key] = $value;
if ($value !== null || !isset($oldMetadata[$key])) {
$oldMetadata[$key] = $value;
}
}

return $oldMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ protected function extractPath(string $path): void
$resourceMetadata,
);
$this->properties[$resourceClass] = array_merge(
$this->properties[$resourceClass],
$resourceMetadata['properties'],
$this->properties[$resourceClass] ?? [],
$resourceMetadata['properties'] ?? [],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null cannot be merged with []
Maybe adjusting \Sylius\Bundle\ApiBundle\ApiPlatform\Metadata\MergingXmlExtractor::buildResource properties to not default to null is better?

);

continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ function it_merges_subresource_operations(): void
]);
}

function it_keeps_existing_subresource_operations_when_the_new_one_doesnt_have_them(): void
{
$this->merge([
'subresourceOperations' => [
'get' => ['foo' => 'bar'],
],
], [
'subresourceOperations' => null,
])->shouldReturn([
'subresourceOperations' => [
'get' => ['foo' => 'bar'],
],
]);
}

function it_merges_complex_metadata(): void
{
$this->merge([
Expand Down