diff --git a/OpenApiPhp/Util.php b/OpenApiPhp/Util.php index 6cf7a48..ba97ede 100644 --- a/OpenApiPhp/Util.php +++ b/OpenApiPhp/Util.php @@ -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); diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 9570edf..8b2b372 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -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); + } } diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index f89f6f0..9e3a79f 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -198,6 +198,10 @@ class TestKernel extends Kernel ['type' => 'object'], ], ], + 'AddProp' => [ + 'type' => 'object', + 'additionalProperties' => false, + ], ], 'parameters' => [ 'test' => [