From 9592c7ebfab247350c50bfc1ad08fdbf9d25f95f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ben=C4=8Do?= Date: Thu, 6 Aug 2020 10:22:59 +0200 Subject: [PATCH] Fix nullable array properties (#1697) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix nullable array properties * Fix tests & Remove weird leftover dump * Fix test Co-authored-by: Filip BenĨo --- PropertyDescriber/ArrayPropertyDescriber.php | 2 ++ Tests/Functional/Entity/User.php | 9 +++++++++ Tests/Functional/FunctionalTest.php | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php index f437ccb..7e299f6 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -19,6 +19,7 @@ use OpenApi\Annotations as OA; class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface { use ModelRegistryAwareTrait; + use NullablePropertyTrait; /** @var PropertyDescriberInterface[] */ private $propertyDescribers; @@ -36,6 +37,7 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr } $property->type = 'array'; + $this->setNullableProperty($types[0], $property); $property = Util::getChild($property, OA\Items::class); foreach ($this->propertyDescribers as $propertyDescriber) { diff --git a/Tests/Functional/Entity/User.php b/Tests/Functional/Entity/User.php index b3d688e..cfd30fb 100644 --- a/Tests/Functional/Entity/User.php +++ b/Tests/Functional/Entity/User.php @@ -80,6 +80,11 @@ class User */ private $friend; + /** + * @var User[]|null + */ + private $friends; + /** * @var string * @@ -146,6 +151,10 @@ class User { } + public function setFriends(array $friends = []) + { + } + public function setDummy(Dummy $dummy) { } diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 7ed88c1..fd5752e 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -195,6 +195,13 @@ class FunctionalTest extends WebTestCase ['$ref' => '#/components/schemas/User'], ], ], + 'friends' => [ + 'nullable' => true, + 'items' => [ + '$ref' => '#/components/schemas/User', + ], + 'type' => 'array', + ], 'dummy' => [ '$ref' => '#/components/schemas/Dummy2', ], @@ -460,7 +467,6 @@ class FunctionalTest extends WebTestCase public function testDefaultOperationId() { $operation = $this->getOperation('/api/article/{id}', 'get'); - var_dump($operation->operationId); $this->assertNull($operation->operationId); } }