Skip to content

Commit bc8d57b

Browse files
authored
fix(symfony): reduce json-problem dependencies (#6169)
* fix(symfony): unload deprecated json problem services
1 parent 4d9d17a commit bc8d57b

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use ApiPlatform\Metadata\UriVariableTransformerInterface;
3737
use ApiPlatform\Metadata\UrlGeneratorInterface;
3838
use ApiPlatform\Metadata\Util\Inflector;
39+
use ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer;
3940
use ApiPlatform\State\ApiResource\Error;
4041
use ApiPlatform\State\ProcessorInterface;
4142
use ApiPlatform\State\ProviderInterface;
@@ -591,6 +592,10 @@ private function registerJsonProblemConfiguration(array $errorFormats, XmlFileLo
591592
return;
592593
}
593594

595+
if (class_exists(ConstraintViolationListNormalizer::class)) {
596+
$loader->load('legacy/problem.xml');
597+
}
598+
594599
$loader->load('problem.xml');
595600
}
596601

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
<service id="api_platform.problem.normalizer.constraint_violation_list" class="ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer" public="false">
9+
<argument>%api_platform.validator.serialize_payload_fields%</argument>
10+
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
11+
12+
<tag name="serializer.normalizer" priority="-780" />
13+
</service>
14+
15+
<!-- deprecated -->
16+
<service id="api_platform.problem.normalizer.error" class="ApiPlatform\Problem\Serializer\ErrorNormalizer" public="false">
17+
<argument>%kernel.debug%</argument>
18+
<argument type="collection"></argument>
19+
20+
<tag name="serializer.normalizer" priority="-810" />
21+
</service>
22+
</services>
23+
24+
</container>

src/Symfony/Bundle/Resources/config/problem.xml

-15
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,12 @@
1212
<tag name="serializer.encoder" />
1313
</service>
1414

15-
<service id="api_platform.problem.normalizer.constraint_violation_list" class="ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer" public="false">
16-
<argument>%api_platform.validator.serialize_payload_fields%</argument>
17-
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
18-
19-
<tag name="serializer.normalizer" priority="-780" />
20-
</service>
21-
2215
<service id="api_platform.problem.normalizer.validation_exception" class="ApiPlatform\Symfony\Validator\Serializer\ValidationExceptionNormalizer" public="false">
2316
<argument type="service" id="api_platform.serializer.normalizer.item" />
2417
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
2518

2619
<tag name="serializer.normalizer" priority="-800" />
2720
</service>
28-
29-
<!-- deprecated -->
30-
<service id="api_platform.problem.normalizer.error" class="ApiPlatform\Problem\Serializer\ErrorNormalizer" public="false">
31-
<argument>%kernel.debug%</argument>
32-
<argument type="collection"></argument>
33-
34-
<tag name="serializer.normalizer" priority="-810" />
35-
</service>
3621
</services>
3722

3823
</container>

tests/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -622,16 +622,12 @@ public function testJsonProblemConfiguration(): void
622622
$services = [
623623
// problem.xml
624624
'api_platform.problem.encoder',
625-
'api_platform.problem.normalizer.constraint_violation_list',
626-
'api_platform.problem.normalizer.error',
627625
];
628626

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

631629
// problem.xml
632630
$this->assertServiceHasTags('api_platform.problem.encoder', ['serializer.encoder']);
633-
$this->assertServiceHasTags('api_platform.problem.normalizer.constraint_violation_list', ['serializer.normalizer']);
634-
$this->assertServiceHasTags('api_platform.problem.normalizer.error', ['serializer.normalizer']);
635631
}
636632

637633
public function testGraphQlConfiguration(): void
@@ -1292,4 +1288,26 @@ public function testGraphQlLegacyConfigurationInDebugMode(): void
12921288
(new ApiPlatformExtension())->load($config, $this->container);
12931289
$this->assertTrue($this->container->hasDefinition('api_platform.graphql.resolver.factory.item'));
12941290
}
1291+
1292+
/**
1293+
* @group legacy
1294+
*/
1295+
public function testLegacyJsonProblemConfiguration(): void
1296+
{
1297+
$config = self::DEFAULT_CONFIG;
1298+
$config['api_platform']['defaults']['extra_properties'] = ['rfc_7807_compliant_errors' => false];
1299+
(new ApiPlatformExtension())->load($config, $this->container);
1300+
1301+
$services = [
1302+
// problem.xml
1303+
'api_platform.problem.normalizer.constraint_violation_list',
1304+
'api_platform.problem.normalizer.error',
1305+
];
1306+
1307+
$this->assertContainerHas($services, []);
1308+
1309+
// problem.xml
1310+
$this->assertServiceHasTags('api_platform.problem.normalizer.constraint_violation_list', ['serializer.normalizer']);
1311+
$this->assertServiceHasTags('api_platform.problem.normalizer.error', ['serializer.normalizer']);
1312+
}
12951313
}

0 commit comments

Comments
 (0)