core
core copied to clipboard
Default configuration value is ignored if same parent block exists at resource level.
API Platform version(s) affected: 2.6.8
Description and steps to reproduce
If "defaults" section in configuration file (config/packages/api_platform.yaml) contains block with some default child parameter and value, for example:
defaults:
denormalization_context:
allow_extra_attributes: false
And Resource level configuration has denormalization_context block with different keys:
ApiResource(
denormalizationContext: [
'groups' => ['person_write'],
],
Then allow_extra_attributes gets ignored because in AnnotationResourceMetadataFactory.php:95 only existance of parent key is checked, not child values:
private function createMetadata(ApiResource $annotation, ResourceMetadata $parentResourceMetadata = null): ResourceMetadata
{
$attributes = null;
if (null !== $annotation->attributes || [] !== $this->defaults['attributes']) {
$attributes = (array) $annotation->attributes;
foreach ($this->defaults['attributes'] as $key => $value) {
if (!isset($attributes[$key])) {
$attributes[$key] = $value;
}
}
}
...
Possible Solution
Must check existence of child keys recursively before skipping default config value.