From ee00f02a488986b7c3f3166a0c84fd9a32c7f095 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Mon, 7 Jun 2021 18:20:25 +0200 Subject: [PATCH] Fix additionalProperties support --- OpenApiPhp/Util.php | 11 ++++++++--- Tests/Functional/FunctionalTest.php | 7 +++++++ Tests/Functional/TestKernel.php | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) 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 64a194b..98ba009 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -526,4 +526,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' => [