docs icon indicating copy to clipboard operation
docs copied to clipboard

Use null instead of boolean in serialize_payload_fields to prevent fatal error

Open maks-rafalko opened this issue 6 years ago • 2 comments

https://github.com/api-platform/core/blob/5503d65e8ad6535539ac4f6b1bcc89962457bc98/src/Serializer/AbstractConstraintViolationListNormalizer.php#L35 constructor accepts either null or array, but not boolean.

When boolean is used, we get the following error:

Argument 2 passed to ApiPlatform\Core\Hydra\Serializer\ConstraintViolationListNormalizer::__construct() must be of the type array or null, boolean given, called in /app/var/cache/dev/Container1ozwx3I/srcApp_KernelDevDebugContainer.php on line 848</p>

This change is Reviewable

maks-rafalko avatar Jul 16 '19 10:07 maks-rafalko

Hm.. I should have think better.

We can't pass null as well, because of this check

https://github.com/api-platform/core/blob/5503d65e8ad6535539ac4f6b1bcc89962457bc98/src/Serializer/AbstractConstraintViolationListNormalizer.php#L69

Then, my advice is leave only case with passing array of keys like

validator:
        serialize_payload_fields: [a, b]

Boolean and null are not allowed.

Alternative - refactor constructor to accept mixed types: array and bool

maks-rafalko avatar Jul 16 '19 10:07 maks-rafalko

Wouldn't it better to normalize null values in the Configuration class?

dunglas avatar Jul 27 '19 04:07 dunglas