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
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 0 additions & 11 deletions src/Metadata/Resource/Factory/OperationDefaultsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
10 changes: 1 addition & 9 deletions src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/Resources/config/jsonld.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

<service id="api_platform.jsonld.encoder" class="ApiPlatform\Serializer\JsonEncoder" public="false">
<argument>jsonld</argument>
<argument type="service" id="serializer.json.encoder" on-invalid="null" />

<tag name="serializer.encoder" />
</service>
Expand Down
48 changes: 48 additions & 0 deletions tests/Fixtures/TestBundle/ApiResource/PasswordResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
}
}