Fix exception when attempting to read swagger annotation for virtual property (#1136)

* Fix exception when attempting to read swagger annotation for virtual property

* drop jms 1.0, add stopwatch for dependency
This commit is contained in:
Kori 2017-12-09 21:31:56 +08:00 committed by Guilhem N
parent 01f691c456
commit 29ec20bda1
5 changed files with 72 additions and 2 deletions

View File

@ -101,7 +101,8 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
}
// read property options from Swagger Property annotation if it exists
$this->swaggerPropertyAnnotationReader->updateWithSwaggerPropertyAnnotation($item->reflection, $property);
if($item->reflection !== null)
$this->swaggerPropertyAnnotationReader->updateWithSwaggerPropertyAnnotation($item->reflection, $property);
}
}

View File

@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\VirtualProperty;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Swagger\Annotations as SWG;
@ -29,4 +30,17 @@ class JMSController
public function userAction()
{
}
/**
* @Route("/api/yaml", methods={"GET"})
* @SWG\Response(
* response=200,
* description="Success",
* @Model(type=VirtualProperty::class)
* )
*/
public function yamlAction()
{
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;
use JMS\Serializer\Annotation as Serializer;
/**
* Class VirtualProperty
* @package Nelmio\ApiDocBundle\Tests\Functional\Entity
*
* @Serializer\ExclusionPolicy("all")
* @Serializer\VirtualProperty(
* "email",
* exp="object.user.email",
* options={@Serializer\Type("string")}
* )
*/
class VirtualProperty
{
/**
* @var int
* @Serializer\Type("integer")
* @Serializer\Expose
*/
private $id;
/**
* @var User
*/
private $user;
public function __construct()
{
$this->user = new User();
$this->user->setEmail("dummy@test.com");
}
}

View File

@ -49,6 +49,21 @@ class JMSFunctionalTest extends WebTestCase
], $this->getModel('JMSUser')->toArray());
}
public function testYamlConfig()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
],
'email' => [
'type' => 'string'
],
],
], $this->getModel('VirtualProperty')->toArray());
}
protected static function createKernel(array $options = array())
{
return new TestKernel(true);

View File

@ -38,12 +38,13 @@
"symfony/cache": "^3.1|^4.0",
"symfony/phpunit-bridge": "^3.3",
"sensio/framework-extra-bundle": "^3.0",
"symfony/stopwatch": "^2.8|^3.0|^4.0",
"doctrine/annotations": "^1.2",
"phpdocumentor/reflection-docblock": "^3.1",
"api-platform/core": "^2.0.3",
"friendsofsymfony/rest-bundle": "^2.0",
"jms/serializer-bundle": "^1.0|^2.0"
"jms/serializer-bundle": "^2.0"
},
"suggest": {
"phpdocumentor/reflection-docblock": "For parsing php docs.",