Skip to content

fix(symfony): internal resources should not inherit global defaults #7073

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

Merged
7 changes: 7 additions & 0 deletions src/Metadata/Resource/Factory/OperationDefaultsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Error;
use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
Expand All @@ -32,6 +33,7 @@
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Util\CamelCaseToSnakeCaseNameConverter;
use ApiPlatform\State\CreateProvider;
use ApiPlatform\Validator\Exception\ValidationException;
use Psr\Log\LoggerInterface;

trait OperationDefaultsTrait
Expand All @@ -42,6 +44,11 @@ trait OperationDefaultsTrait

private function addGlobalDefaults(ApiResource|Operation $operation): ApiResource|Operation
{
// Do not add global defaults for internal resources:
if (\in_array($operation->getClass(), [Error::class, ValidationException::class], true)) {
return $operation;
}

$extraProperties = $this->defaults['extra_properties'] ?? [];

foreach ($this->defaults as $key => $value) {
Expand Down
Loading