Skip to content

Add payload to ConstraintViolationListNormalizer#1364

Merged
dunglas merged 2 commits intoapi-platform:masterfrom
pierre-H:patch-2
Sep 18, 2017
Merged

Add payload to ConstraintViolationListNormalizer#1364
dunglas merged 2 commits intoapi-platform:masterfrom
pierre-H:patch-2

Conversation

@pierre-H
Copy link
Contributor

@pierre-H pierre-H commented Sep 12, 2017

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1357
License MIT
Doc PR api-platform/docs#263

see the ticket for more information

@pierre-H pierre-H changed the title Add payload infos to ConstraintViolationListNormalizer Add payload to ConstraintViolationListNormalizer Sep 12, 2017
@meyerbaptiste
Copy link
Member

I don't know why test don't pass

Run php-cs-fixer: https://travis-ci.org/api-platform/core/jobs/274610519#L1072-L1158

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add some tests and an option to disable this behavior please?

'message' => $violation->getMessage()
];

if (! empty($violation->getConstraint()->payload)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ! Thanks

@pierre-H
Copy link
Contributor Author

@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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializePayload needs a default value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soyuka Done

Copy link
Member

@meyerbaptiste meyerbaptiste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please run PHP-CS-Fixer @pierre-H?

@pierre-H
Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true === is useless here!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though this is my bad haha, how did this end up in the code :P.

Copy link
Member

@meyerbaptiste meyerbaptiste Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like PHP-CS-Fixer has a new rule about Yoda style 😛

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably apply it on lower branches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of something like:

validator:
    serialize_payload: true

Some people are thinking about new options regarding the validator, this way we'll be feature-proof?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will change that tomorrow

@pierre-H
Copy link
Contributor Author

Isn't better to define in the configuration which fields we want to serialize ?

For example :

validator:
    serialize_payload_fields:
        severity
        anotherField

This way we can use payload field with sensitive and public data?

@dunglas
Copy link
Member

dunglas commented Sep 15, 2017

@pierre-H good idea! and

serialize_payload_fields: true

to serialize all fields.

@soyuka
Copy link
Member

soyuka commented Sep 15, 2017

As I've applied the cs fixes to 2.1, @dunglas may you merge 2.1 on to master. Then @pierre-H can git rebase origin/master so that the patch is cleaner :).

Thanks!

@pierre-H
Copy link
Contributor Author

@dunglas done

@pierre-H
Copy link
Contributor Author

Should I do something more ?

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me!

@dunglas dunglas merged commit 751893a into api-platform:master Sep 18, 2017
@dunglas
Copy link
Member

dunglas commented Sep 18, 2017

Thanks @pierre-H

@pierre-H
Copy link
Contributor Author

With pleasure !
Thank you for your great work !

dunglas pushed a commit to api-platform/docs that referenced this pull request Sep 18, 2017
* Add payload constraint option

For api-platform/core#1364

* Add ability to define payload fields

* Minor Markdown and wording fixes

* Update TOC
jonag pushed a commit to jonag/docs that referenced this pull request Sep 22, 2017
* Add payload constraint option

For api-platform/core#1364

* Add ability to define payload fields

* Minor Markdown and wording fixes

* Update TOC
@pierre-H pierre-H deleted the patch-2 branch September 27, 2017 08:48
sh41 pushed a commit to sh41/docs that referenced this pull request Sep 30, 2017
* Add payload constraint option

For api-platform/core#1364

* Add ability to define payload fields

* Minor Markdown and wording fixes

* Update TOC
hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
Add payload to ConstraintViolationListNormalizer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants