Skip to content

Commit f389004

Browse files
Merge branch '2.5' into patch/dto-output-class-same-as-original
2 parents 3b36fd9 + 3a14131 commit f389004

File tree

7 files changed

+37
-22
lines changed

7 files changed

+37
-22
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ jobs:
20082008
fail-fast: false
20092009
timeout-minutes: 20
20102010
env:
2011-
SYMFONY_DEPRECATIONS_HELPER: max[total]=5 # 5 deprecation notices from FOSUserBundle
2011+
SYMFONY_DEPRECATIONS_HELPER: max[total]=5
20122012
steps:
20132013
- name: Checkout
20142014
uses: actions/checkout@v1

CHANGELOG.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
# Changelog
22

33
## 2.5.x-dev
4+
45
* JSON Schema: Missing LD context from Data Transformers #3479
56

67
## 2.5.5
78

8-
* GraphQL: Do not allow empty cursor values on `before` or `after`
9-
* Filter: Improve the RangeFilter query in case the values are equals using the between operator
10-
* Pagination: Fix bug with large values,
9+
* Filter: Improve the RangeFilter query in case the values are equals using the between operator #3488
10+
* Pagination: Fix bug with large values #3451
1111
* Doctrine: use the correct type within `setParameter` of the SearchFilter #3331
12-
* Allow \Traversable resources #3463
12+
* Allow `\Traversable` resources #3463
1313
* Hydra: `hydra:writable` => `hydra:writeable` #3481
1414
* Hydra: Show `hydra:next` only when it's available #3457
15-
* DX: Improve contributing by adding a stub package for ext-mongodb #3431
16-
* Swagger: Missing default context argument #3443
17-
* Swagger: Fix API docs path in swagger ui #3475
15+
* Swagger UI: Missing default context argument #3443
16+
* Swagger UI: Fix API docs path in swagger ui #3475
1817
* OpenAPI: Export with unescaped slashes #3368
1918
* OpenAPI: OAuth flows fix #3333
2019
* JSON Schema: Fix metadata options #3425
2120
* JSON Schema: Allow decoration #3417
2221
* JSON Schema: Add DateInterval type #3351
2322
* JSON Schema: Correct schema generation for many types #3402
24-
* Validation: Use our `ValidationException` instead of symfony's #3414
23+
* Validation: Use API Platform's `ValidationException` instead of Symfony's #3414
24+
* Validation: Fix a bug preventing to serialize validator's payload #3375
2525
* Subresources: Improve queries when there's only one level #3396
2626
* HTTP: Location header is only set on POST with a 201 or between 300 and 400 #3497
27+
* GraphQL: Do not allow empty cursor values on `before` or `after` #3360
2728

2829
## 2.5.4
2930

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"doctrine/mongodb-odm-bundle": "^4.0",
4343
"doctrine/orm": "^2.6.4",
4444
"elasticsearch/elasticsearch": "^6.0",
45-
"friendsofsymfony/user-bundle": "^2.2@dev",
45+
"friendsofsymfony/user-bundle": "2.2.x-dev#157b53bd7d6c347148a90e723981a43f9c897bf5",
4646
"guzzlehttp/guzzle": "^6.0",
4747
"jangregor/phpstan-prophecy": "^0.6",
4848
"justinrainbow/json-schema": "^5.2.1",
@@ -97,7 +97,6 @@
9797
"suggest": {
9898
"doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.",
9999
"elasticsearch/elasticsearch": "To support Elasticsearch.",
100-
"friendsofsymfony/user-bundle": "To use the FOSUserBundle bridge.",
101100
"guzzlehttp/guzzle": "To use the HTTP cache invalidation system.",
102101
"phpdocumentor/reflection-docblock": "To support extracting metadata from PHPDoc.",
103102
"psr/cache-implementation": "To use metadata caching.",

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function getConfigTreeBuilder()
9494
->arrayNode('validator')
9595
->addDefaultsIfNotSet()
9696
->children()
97-
->variableNode('serialize_payload_fields')->defaultValue([])->info('Enable the serialization of payload fields when a validation error is thrown.')->end()
97+
->variableNode('serialize_payload_fields')->defaultValue([])->info('Set to null to serialize all payload fields when a validation error is thrown, or set the fields you want to include explicitly.')->end()
9898
->end()
9999
->end()
100100
->arrayNode('eager_loading')

src/Serializer/AbstractConstraintViolationListNormalizer.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class AbstractConstraintViolationListNormalizer implements NormalizerIn
3535
public function __construct(array $serializePayloadFields = null, NameConverterInterface $nameConverter = null)
3636
{
3737
$this->nameConverter = $nameConverter;
38-
$this->serializePayloadFields = $serializePayloadFields;
38+
$this->serializePayloadFields = null === $serializePayloadFields ? null : array_flip($serializePayloadFields);
3939
}
4040

4141
/**
@@ -66,10 +66,14 @@ protected function getMessagesAndViolations(ConstraintViolationListInterface $co
6666
];
6767

6868
$constraint = $violation->getConstraint();
69-
if ($this->serializePayloadFields && $constraint && $constraint->payload) {
69+
if (
70+
[] !== $this->serializePayloadFields &&
71+
$constraint &&
72+
$constraint->payload &&
7073
// If some fields are whitelisted, only them are added
71-
$payloadFields = null === $this->serializePayloadFields ? $constraint->payload : array_intersect_key($constraint->payload, array_flip($this->serializePayloadFields));
72-
$payloadFields && $violationData['payload'] = $payloadFields;
74+
$payloadFields = null === $this->serializePayloadFields ? $constraint->payload : array_intersect_key($constraint->payload, $this->serializePayloadFields)
75+
) {
76+
$violationData['payload'] = $payloadFields;
7377
}
7478

7579
$violations[] = $violationData;

tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public function invalidHttpStatusCodeValueProvider()
289289
public function testExceptionToStatusConfigWithInvalidHttpStatusCodeValue($invalidHttpStatusCodeValue)
290290
{
291291
$this->expectException(InvalidTypeException::class);
292-
$this->expectExceptionMessageRegExp('/Invalid type for path "api_platform\\.exception_to_status\\.Exception". Expected int, but got .+\\./');
292+
$this->expectExceptionMessageRegExp('/Invalid type for path "api_platform\\.exception_to_status\\.Exception". Expected "?int"?, but got .+\\./');
293293

294294
$this->processor->processConfiguration($this->configuration, [
295295
'api_platform' => [

tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public function testSupportNormalization()
4040
$this->assertTrue($normalizer->hasCacheableSupportsMethod());
4141
}
4242

43-
public function testNormalize()
43+
/**
44+
* @dataProvider payloadFieldsProvider
45+
*/
46+
public function testNormalize(?array $fields, array $result)
4447
{
4548
$urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class);
4649
$nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
@@ -50,7 +53,7 @@ public function testNormalize()
5053
return '_'.$args[0];
5154
});
5255

53-
$normalizer = new ConstraintViolationListNormalizer($urlGeneratorProphecy->reveal(), ['severity', 'anotherField1'], $nameConverterProphecy->reveal());
56+
$normalizer = new ConstraintViolationListNormalizer($urlGeneratorProphecy->reveal(), $fields, $nameConverterProphecy->reveal());
5457

5558
// Note : we use NotNull constraint and not Constraint class because Constraint is abstract
5659
$constraint = new NotNull();
@@ -70,16 +73,24 @@ public function testNormalize()
7073
[
7174
'propertyPath' => '_d',
7275
'message' => 'a',
73-
'payload' => [
74-
'severity' => 'warning',
75-
],
7676
],
7777
[
7878
'propertyPath' => '_4',
7979
'message' => '1',
8080
],
8181
],
8282
];
83+
if ([] !== $result) {
84+
$expected['violations'][0]['payload'] = $result;
85+
}
86+
8387
$this->assertEquals($expected, $normalizer->normalize($list));
8488
}
89+
90+
public function payloadFieldsProvider(): iterable
91+
{
92+
yield [['severity', 'anotherField1'], ['severity' => 'warning']];
93+
yield [null, ['severity' => 'warning', 'anotherField2' => 'aValue']];
94+
yield [[], []];
95+
}
8596
}

0 commit comments

Comments
 (0)