Add payload to ConstraintViolationListNormalizer#1364
Add payload to ConstraintViolationListNormalizer#1364dunglas merged 2 commits intoapi-platform:masterfrom pierre-H:patch-2
Conversation
Run php-cs-fixer: https://travis-ci.org/api-platform/core/jobs/274610519#L1072-L1158 |
dunglas
left a comment
There was a problem hiding this comment.
Can you also add some tests and an option to disable this behavior please?
| 'message' => $violation->getMessage() | ||
| ]; | ||
|
|
||
| if (! empty($violation->getConstraint()->payload)) { |
There was a problem hiding this comment.
I suggest to store $violation->getConstraint()->payload in a variable to prevent an extra function call. Btw you can remove the call to empty, it is useless.
|
@dunglas I added the option and some tests but I am not that tests are complete for ApiPlatformExtensionTest . |
| */ | ||
| private $serializePayload; | ||
|
|
||
| public function __construct(UrlGeneratorInterface $urlGenerator, bool $serializePayload) |
There was a problem hiding this comment.
serializePayload needs a default value
meyerbaptiste
left a comment
There was a problem hiding this comment.
Can you please run PHP-CS-Fixer @pierre-H?
|
PHP-CS-Fixer and tests are ok |
| @trigger_error('Using a boolean for the Operation Type is deprecrated since API Platform 2.1 and will not be possible anymore in API Platform 3', E_USER_DEPRECATED); | ||
|
|
||
| $operationType = $operationType === true ? OperationType::COLLECTION : OperationType::ITEM; | ||
| $operationType = true === $operationType ? OperationType::COLLECTION : OperationType::ITEM; |
There was a problem hiding this comment.
true === is useless here!
There was a problem hiding this comment.
though this is my bad haha, how did this end up in the code :P.
There was a problem hiding this comment.
It looks like PHP-CS-Fixer has a new rule about Yoda style 😛
There was a problem hiding this comment.
We should probably apply it on lower branches.
There was a problem hiding this comment.
Yes it was PHP-CS-Fixer
| ->end() | ||
| ->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end() | ||
| ->scalarNode('path_segment_name_generator')->defaultValue('api_platform.path_segment_name_generator.underscore')->info('Specify a path name generator to use.')->end() | ||
| ->booleanNode('serialize_payload_constraint')->defaultFalse()->info('Enable the serialization of the payload field when a validation error is thrown.')->end() |
There was a problem hiding this comment.
What do you think of something like:
validator:
serialize_payload: trueSome people are thinking about new options regarding the validator, this way we'll be feature-proof?
There was a problem hiding this comment.
Ok, I will change that tomorrow
|
Isn't better to define in the configuration which fields we want to serialize ? For example : validator:
serialize_payload_fields:
severity
anotherFieldThis way we can use payload field with sensitive and public data? |
|
@pierre-H good idea! and to serialize all fields. |
|
@dunglas done |
|
Should I do something more ? |
|
Thanks @pierre-H |
|
With pleasure ! |
* Add payload constraint option For api-platform/core#1364 * Add ability to define payload fields * Minor Markdown and wording fixes * Update TOC
* Add payload constraint option For api-platform/core#1364 * Add ability to define payload fields * Minor Markdown and wording fixes * Update TOC
* Add payload constraint option For api-platform/core#1364 * Add ability to define payload fields * Minor Markdown and wording fixes * Update TOC
Add payload to ConstraintViolationListNormalizer
see the ticket for more information