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(symfony): reduce json-problem dependencies #6169

Merged
merged 2 commits into from Feb 29, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -36,6 +36,7 @@
use ApiPlatform\Metadata\UriVariableTransformerInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\Metadata\Util\Inflector;
use ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer;
use ApiPlatform\State\ApiResource\Error;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\State\ProviderInterface;
Expand Down Expand Up @@ -591,6 +592,10 @@ private function registerJsonProblemConfiguration(array $errorFormats, XmlFileLo
return;
}

if (class_exists(ConstraintViolationListNormalizer::class)) {
$loader->load('legacy/problem.xml');
}

$loader->load('problem.xml');
}

Expand Down
24 changes: 24 additions & 0 deletions src/Symfony/Bundle/Resources/config/legacy/problem.xml
@@ -0,0 +1,24 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="api_platform.problem.normalizer.constraint_violation_list" class="ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer" public="false">
<argument>%api_platform.validator.serialize_payload_fields%</argument>
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />

<tag name="serializer.normalizer" priority="-780" />
</service>

<!-- deprecated -->
<service id="api_platform.problem.normalizer.error" class="ApiPlatform\Problem\Serializer\ErrorNormalizer" public="false">
<argument>%kernel.debug%</argument>
<argument type="collection"></argument>

<tag name="serializer.normalizer" priority="-810" />
</service>
</services>

</container>
15 changes: 0 additions & 15 deletions src/Symfony/Bundle/Resources/config/problem.xml
Expand Up @@ -12,27 +12,12 @@
<tag name="serializer.encoder" />
</service>

<service id="api_platform.problem.normalizer.constraint_violation_list" class="ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer" public="false">
<argument>%api_platform.validator.serialize_payload_fields%</argument>
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />

<tag name="serializer.normalizer" priority="-780" />
</service>

<service id="api_platform.problem.normalizer.validation_exception" class="ApiPlatform\Symfony\Validator\Serializer\ValidationExceptionNormalizer" public="false">
<argument type="service" id="api_platform.serializer.normalizer.item" />
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />

<tag name="serializer.normalizer" priority="-800" />
</service>

<!-- deprecated -->
<service id="api_platform.problem.normalizer.error" class="ApiPlatform\Problem\Serializer\ErrorNormalizer" public="false">
<argument>%kernel.debug%</argument>
<argument type="collection"></argument>

<tag name="serializer.normalizer" priority="-810" />
</service>
</services>

</container>
Expand Up @@ -622,16 +622,12 @@ public function testJsonProblemConfiguration(): void
$services = [
// problem.xml
'api_platform.problem.encoder',
'api_platform.problem.normalizer.constraint_violation_list',
'api_platform.problem.normalizer.error',
];

$this->assertContainerHas($services, []);

// problem.xml
$this->assertServiceHasTags('api_platform.problem.encoder', ['serializer.encoder']);
$this->assertServiceHasTags('api_platform.problem.normalizer.constraint_violation_list', ['serializer.normalizer']);
$this->assertServiceHasTags('api_platform.problem.normalizer.error', ['serializer.normalizer']);
}

public function testGraphQlConfiguration(): void
Expand Down Expand Up @@ -1292,4 +1288,26 @@ public function testGraphQlLegacyConfigurationInDebugMode(): void
(new ApiPlatformExtension())->load($config, $this->container);
$this->assertTrue($this->container->hasDefinition('api_platform.graphql.resolver.factory.item'));
}

/**
* @group legacy
*/
public function testLegacyJsonProblemConfiguration(): void
{
$config = self::DEFAULT_CONFIG;
$config['api_platform']['defaults']['extra_properties'] = ['rfc_7807_compliant_errors' => false];
(new ApiPlatformExtension())->load($config, $this->container);

$services = [
// problem.xml
'api_platform.problem.normalizer.constraint_violation_list',
'api_platform.problem.normalizer.error',
];

$this->assertContainerHas($services, []);

// problem.xml
$this->assertServiceHasTags('api_platform.problem.normalizer.constraint_violation_list', ['serializer.normalizer']);
$this->assertServiceHasTags('api_platform.problem.normalizer.error', ['serializer.normalizer']);
}
}