Fix nullable array properties (#1697)

* Fix nullable array properties

* Fix tests & Remove weird leftover dump

* Fix test

Co-authored-by: Filip Benčo <filip.benco@websupport.sk>
This commit is contained in:
Filip Benčo 2020-08-06 10:22:59 +02:00 committed by GitHub
parent 34598be7ee
commit 9592c7ebfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -19,6 +19,7 @@ use OpenApi\Annotations as OA;
class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface
{ {
use ModelRegistryAwareTrait; use ModelRegistryAwareTrait;
use NullablePropertyTrait;
/** @var PropertyDescriberInterface[] */ /** @var PropertyDescriberInterface[] */
private $propertyDescribers; private $propertyDescribers;
@ -36,6 +37,7 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr
} }
$property->type = 'array'; $property->type = 'array';
$this->setNullableProperty($types[0], $property);
$property = Util::getChild($property, OA\Items::class); $property = Util::getChild($property, OA\Items::class);
foreach ($this->propertyDescribers as $propertyDescriber) { foreach ($this->propertyDescribers as $propertyDescriber) {

View File

@ -80,6 +80,11 @@ class User
*/ */
private $friend; private $friend;
/**
* @var User[]|null
*/
private $friends;
/** /**
* @var string * @var string
* *
@ -146,6 +151,10 @@ class User
{ {
} }
public function setFriends(array $friends = [])
{
}
public function setDummy(Dummy $dummy) public function setDummy(Dummy $dummy)
{ {
} }

View File

@ -195,6 +195,13 @@ class FunctionalTest extends WebTestCase
['$ref' => '#/components/schemas/User'], ['$ref' => '#/components/schemas/User'],
], ],
], ],
'friends' => [
'nullable' => true,
'items' => [
'$ref' => '#/components/schemas/User',
],
'type' => 'array',
],
'dummy' => [ 'dummy' => [
'$ref' => '#/components/schemas/Dummy2', '$ref' => '#/components/schemas/Dummy2',
], ],
@ -460,7 +467,6 @@ class FunctionalTest extends WebTestCase
public function testDefaultOperationId() public function testDefaultOperationId()
{ {
$operation = $this->getOperation('/api/article/{id}', 'get'); $operation = $this->getOperation('/api/article/{id}', 'get');
var_dump($operation->operationId);
$this->assertNull($operation->operationId); $this->assertNull($operation->operationId);
} }
} }