From 4173ad3fc24d15f56bda2cb7bdcfcbfde0849c2e Mon Sep 17 00:00:00 2001 From: soyuka Date: Mon, 23 May 2022 13:43:20 +0200 Subject: [PATCH] fix(metadata): defaults deprecation --- .../DependencyInjection/ApiPlatformExtension.php | 12 +++++++----- .../DependencyInjection/ApiPlatformExtensionTest.php | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 866a141fa2f..bc949d170b7 100644 --- a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -15,7 +15,7 @@ use ApiPlatform\Api\FilterInterface; use ApiPlatform\Api\UrlGeneratorInterface; -use ApiPlatform\Core\Annotation\ApiResource; +use ApiPlatform\Core\Annotation\ApiResource as ApiResourceAnnotation; use ApiPlatform\Core\DataPersister\DataPersisterInterface; use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; @@ -36,6 +36,7 @@ use ApiPlatform\GraphQl\Resolver\QueryCollectionResolverInterface; use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface; use ApiPlatform\GraphQl\Type\Definition\TypeInterface as GraphQlTypeInterface; +use ApiPlatform\Metadata\ApiResource; use ApiPlatform\State\ProcessorInterface; use ApiPlatform\State\ProviderInterface; use ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaRestrictionMetadataInterface; @@ -276,13 +277,14 @@ private function getPaginationDefaults(array $defaults, array $collectionPaginat private function normalizeDefaults(array $defaults, bool $compatibility = false): array { - $normalizedDefaults = ['attributes' => $defaults['attributes'] ?? []]; - unset($defaults['attributes']); + $key = $compatibility ? 'attributes' : 'extra_properties'; + $normalizedDefaults = [$key => $defaults[$key] ?? []]; + unset($defaults[$key]); $publicProperties = []; if ($compatibility) { - [$publicProperties,] = ApiResource::getConfigMetadata(); + [$publicProperties,] = ApiResourceAnnotation::getConfigMetadata(); } else { $rc = new \ReflectionClass(ApiResource::class); foreach ($rc->getConstructor()->getParameters() as $param) { @@ -298,7 +300,7 @@ private function normalizeDefaults(array $defaults, bool $compatibility = false) continue; } - $normalizedDefaults['attributes'][$option] = $value; + $normalizedDefaults[$key][$option] = $value; } return $normalizedDefaults; diff --git a/tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index d893054fa90..ad93e1fae27 100644 --- a/tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -104,7 +104,7 @@ class ApiPlatformExtensionTest extends TestCase 'enabled' => true, ], 'defaults' => [ - 'attributes' => [], + 'extra_properties' => [], 'url_generation_strategy' => UrlGeneratorInterface::ABS_URL, ], 'collection' => [ @@ -1872,11 +1872,11 @@ public function testDefaults() $config = self::DEFAULT_CONFIG; $config['api_platform']['defaults'] = [ 'something' => 'test', - 'attributes' => ['else' => 'foo'], + 'extra_properties' => ['else' => 'foo'], ]; (new ApiPlatformExtension())->load($config, $this->container); - $this->assertEquals($this->container->getParameter('api_platform.defaults'), ['attributes' => ['else' => 'foo', 'something' => 'test']]); + $this->assertEquals($this->container->getParameter('api_platform.defaults'), ['extra_properties' => ['else' => 'foo', 'something' => 'test']]); } }