diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba86fef062c..b62f13076f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -397,9 +397,15 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Check + - name: Setup MongoDB run: | - sudo systemctl start mongod.service + sudo apt update + sudo apt install -y wget gnupg + wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list + sudo apt update + sudo apt install -y mongodb-org + sudo systemctl start mongod - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 068dea539ff..9e771c7f130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v3.0.6 + +### Bug fixes + +* [d4173e7db](https://github.com/api-platform/core/commit/d4173e7dbca8e72af484c38fa0dc46a81b238fc6) fix(metadata): do not override name fixes #5235 (#5237) + ## v3.0.5 ### Bug fixes @@ -97,6 +103,7 @@ Breaking changes: * Identifiers: using an object as identifier is supported only when this object is `Stringable` * Serializer: `skip_null_values` now defaults to `true` * Metadata: `Patch` is added to the automatic CRUD +* Symfony: generated route names and operation names changed, route naming can be changed directly within metadata ## v2.7.5 diff --git a/src/Metadata/Resource/Factory/OperationDefaultsTrait.php b/src/Metadata/Resource/Factory/OperationDefaultsTrait.php index 93e6c83857c..d320bd41577 100644 --- a/src/Metadata/Resource/Factory/OperationDefaultsTrait.php +++ b/src/Metadata/Resource/Factory/OperationDefaultsTrait.php @@ -187,17 +187,6 @@ private function getOperationWithDefaults(ApiResource $resource, Operation $oper $operation = $operation->withName($operation->getRouteName()); } - // Check for name conflict - if ($operation->getName() && null !== ($operations = $resource->getOperations())) { - if (!$operations->has($operation->getName())) { - return [$operation->getName(), $operation]; - } - - $this->logger->warning(sprintf('The operation "%s" already exists on the resource "%s", pick a different name or leave it empty. In the meantime we will generate a unique name.', $operation->getName(), $resource->getClass())); - /** @var HttpOperation $operation */ - $operation = $operation->withName(''); - } - $operationName = $operation->getName() ?? sprintf( '_api_%s_%s%s', $operation->getUriTemplate() ?: $operation->getShortName(), diff --git a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 40d550e7d7f..c846e0ef9d9 100644 --- a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -39,7 +39,6 @@ use phpDocumentor\Reflection\DocBlockFactoryInterface; use PHPStan\PhpDocParser\Parser\PhpDocParser; use Ramsey\Uuid\Uuid; -use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -535,14 +534,7 @@ private function registerGraphQlConfiguration(ContainerBuilder $container, array private function registerCacheConfiguration(ContainerBuilder $container): void { - if ($container->hasParameter('kernel.debug') && $container->getParameter('kernel.debug')) { - $container->register('api_platform.cache.metadata.property', ArrayAdapter::class)->addTag('cache.pool'); - $container->register('api_platform.cache.metadata.resource', ArrayAdapter::class)->addTag('cache.pool'); - $container->register('api_platform.cache.metadata.resource_collection', ArrayAdapter::class)->addTag('cache.pool'); - $container->register('api_platform.cache.route_name_resolver', ArrayAdapter::class)->addTag('cache.pool'); - $container->register('api_platform.cache.identifiers_extractor', ArrayAdapter::class); - $container->register('api_platform.elasticsearch.cache.metadata.document', ArrayAdapter::class); - } else { + if (!$container->hasParameter('kernel.debug') || !$container->getParameter('kernel.debug')) { $container->removeDefinition('api_platform.cache_warmer.cache_pool_clearer'); } } diff --git a/src/Symfony/Bundle/Resources/config/jsonld.xml b/src/Symfony/Bundle/Resources/config/jsonld.xml index e3c67090e6f..36f32ec8766 100644 --- a/src/Symfony/Bundle/Resources/config/jsonld.xml +++ b/src/Symfony/Bundle/Resources/config/jsonld.xml @@ -45,6 +45,7 @@ jsonld + diff --git a/tests/Fixtures/TestBundle/ApiResource/PasswordResource.php b/tests/Fixtures/TestBundle/ApiResource/PasswordResource.php new file mode 100644 index 00000000000..458ccc3977d --- /dev/null +++ b/tests/Fixtures/TestBundle/ApiResource/PasswordResource.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\Post; + +#[ + ApiResource( + shortName: 'PasswordResource', + operations: [ + new Post( + uriTemplate: '/password/reset', + name: 'password_reset', + ), + new Post( + uriTemplate: '/password/set', + name: 'password_set', + ), + new Get( + uriTemplate: '/password/reset/{token}', + name: 'password_reset_token', + ), + ], + routePrefix: '/users' + ) +] +/** + * Test for issue #5235. + */ +class PasswordResource +{ + #[ApiProperty(identifier: true)] + public ?string $token = null; +} diff --git a/tests/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactoryTest.php b/tests/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactoryTest.php index 6510080c88d..67aa6bbe198 100644 --- a/tests/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactoryTest.php +++ b/tests/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactoryTest.php @@ -27,6 +27,7 @@ use ApiPlatform\Metadata\Put; use ApiPlatform\Metadata\Resource\Factory\AttributesResourceMetadataCollectionFactory; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\PasswordResource; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\AttributeDefaultOperations; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\AttributeOnlyOperation; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\AttributeResource; @@ -226,4 +227,18 @@ class: AttributeOnlyOperation::class, ), ]), $attributeResourceMetadataCollectionFactory->create(AttributeOnlyOperation::class)); } + + /** + * Tests issue #5235. + */ + public function testNameDeclarationShouldNotBeRemoved(): void + { + $attributeResourceMetadataCollectionFactory = new AttributesResourceMetadataCollectionFactory(); + + $metadataCollection = $attributeResourceMetadataCollectionFactory->create(PasswordResource::class); + $operations = $metadataCollection[0]->getOperations(); + $this->assertTrue($operations->has('password_set')); + $this->assertTrue($operations->has('password_reset_token')); + $this->assertTrue($operations->has('password_reset')); + } }