Merge pull request #1830 from nelmio/ADDPROP

Fix additionalProperties support
This commit is contained in:
Guilhem Niot 2021-08-03 09:35:12 +02:00 committed by GitHub
commit be014ff11b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -346,10 +346,17 @@ final class Util
{
$done = [];
$defaults = \get_class_vars(\get_class($annotation));
foreach ($annotation::$_nested as $className => $propertyName) {
if (\is_string($propertyName)) {
if (array_key_exists($propertyName, $properties)) {
self::mergeChild($annotation, $className, $properties[$propertyName], $overwrite);
if (!is_bool($properties[$propertyName])) {
self::mergeChild($annotation, $className, $properties[$propertyName], $overwrite);
} elseif ($overwrite || $annotation->{$propertyName} === $defaults[$propertyName]) {
// Support for boolean values (for instance for additionalProperties)
$annotation->{$propertyName} = $properties[$propertyName];
}
$done[] = $propertyName;
}
} elseif (\array_key_exists($propertyName[0], $properties)) {
@ -360,8 +367,6 @@ final class Util
}
}
$defaults = \get_class_vars(\get_class($annotation));
foreach ($annotation::$_types as $propertyName => $type) {
if (array_key_exists($propertyName, $properties)) {
self::mergeTyped($annotation, $propertyName, $type, $properties, $defaults, $overwrite);

View File

@ -543,4 +543,11 @@ class FunctionalTest extends WebTestCase
$this->getModel('SymfonyDiscriminatorOne');
$this->getModel('SymfonyDiscriminatorTwo');
}
public function testNoAdditionalPropertiesSupport()
{
$model = $this->getModel('AddProp');
$this->assertFalse($model->additionalProperties);
}
}

View File

@ -198,6 +198,10 @@ class TestKernel extends Kernel
['type' => 'object'],
],
],
'AddProp' => [
'type' => 'object',
'additionalProperties' => false,
],
],
'parameters' => [
'test' => [