mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
jms 2.0 groups tested
This commit is contained in:
parent
e738102514
commit
0fb5d7afa2
@ -23,7 +23,6 @@ use Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
@ -68,6 +68,8 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
||||
$annotationsReader = new AnnotationsReader($this->doctrineReader, $this->modelRegistry);
|
||||
$annotationsReader->updateDefinition(new \ReflectionClass($className), $schema);
|
||||
|
||||
$isJmsV1 = null !== $this->namingStrategy;
|
||||
|
||||
$properties = $schema->getProperties();
|
||||
foreach ($metadata->propertyMetadata as $item) {
|
||||
// filter groups
|
||||
@ -84,8 +86,10 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
||||
} elseif (!isset($groups[$item->name]) && !empty($this->previousGroups[$model->getHash()])) {
|
||||
$groups = false === $this->propertyTypeUsesGroups($item->type)
|
||||
? null
|
||||
: ($this->namingStrategy ? [GroupsExclusionStrategy::DEFAULT_GROUP] : $this->previousGroups[$model->getHash()]);
|
||||
} elseif (is_array($groups)) {
|
||||
: ($isJmsV1 ? [GroupsExclusionStrategy::DEFAULT_GROUP] : $this->previousGroups[$model->getHash()]);
|
||||
}
|
||||
|
||||
if (is_array($groups)) {
|
||||
$groups = array_filter($groups, 'is_scalar');
|
||||
}
|
||||
|
||||
@ -93,10 +97,10 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
||||
$groups = null;
|
||||
}
|
||||
|
||||
$name = $this->namingStrategy ? $this->namingStrategy->translateName($item) : $item->serializedName;
|
||||
$name = true === $isJmsV1 ? $this->namingStrategy->translateName($item) : $item->serializedName;
|
||||
// read property options from Swagger Property annotation if it exists
|
||||
try {
|
||||
if (property_exists($item, 'reflection') && null !== $item->reflection) {
|
||||
if (true === $isJmsV1 && property_exists($item, 'reflection') && null !== $item->reflection) {
|
||||
$reflection = $item->reflection;
|
||||
} elseif ($item instanceof VirtualProperty) {
|
||||
$reflection = new \ReflectionProperty($item->class, $item->name);
|
||||
|
@ -17,6 +17,7 @@ use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSDualComplex;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSNamingStrategyConstraints;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChat;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChatRoomUser;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChatUser;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSPicture;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\VirtualProperty;
|
||||
@ -123,4 +124,16 @@ class JMSController
|
||||
public function minUserAction()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/jms_mini_user_nested", methods={"GET"})
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Success",
|
||||
* @Model(type=JMSChatRoomUser::class, groups={"mini", "friend": {"living":{"Default"}}})
|
||||
* )
|
||||
*/
|
||||
public function minUserNestedAction()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
42
Tests/Functional/Entity/NestedGroup/JMSChatFriend.php
Normal file
42
Tests/Functional/Entity/NestedGroup/JMSChatFriend.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the NelmioApiDocBundle package.
|
||||
*
|
||||
* (c) Nelmio
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup;
|
||||
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* User.
|
||||
*
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
class JMSChatFriend
|
||||
{
|
||||
/**
|
||||
* @Serializer\Type("Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChatRoom")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Groups({"mini"})
|
||||
*/
|
||||
private $room;
|
||||
|
||||
/**
|
||||
* @Serializer\Type("Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChatLivingRoom")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Groups({"Default"})
|
||||
*/
|
||||
private $living;
|
||||
|
||||
/**
|
||||
* @Serializer\Type("Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChatRoom")
|
||||
* @Serializer\Expose
|
||||
*/
|
||||
private $dining;
|
||||
}
|
28
Tests/Functional/Entity/NestedGroup/JMSChatLivingRoom.php
Normal file
28
Tests/Functional/Entity/NestedGroup/JMSChatLivingRoom.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the NelmioApiDocBundle package.
|
||||
*
|
||||
* (c) Nelmio
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup;
|
||||
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* User.
|
||||
*
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
class JMSChatLivingRoom
|
||||
{
|
||||
/**
|
||||
* @Serializer\Type("integer")
|
||||
* @Serializer\Expose
|
||||
*/
|
||||
private $id;
|
||||
}
|
42
Tests/Functional/Entity/NestedGroup/JMSChatRoom.php
Normal file
42
Tests/Functional/Entity/NestedGroup/JMSChatRoom.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the NelmioApiDocBundle package.
|
||||
*
|
||||
* (c) Nelmio
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup;
|
||||
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* User.
|
||||
*
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
class JMSChatRoom
|
||||
{
|
||||
/**
|
||||
* @Serializer\Type("integer")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Groups({"Default"})
|
||||
*/
|
||||
private $id1;
|
||||
|
||||
/**
|
||||
* @Serializer\Type("integer")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Groups({"mini"})
|
||||
*/
|
||||
private $id2;
|
||||
|
||||
/**
|
||||
* @Serializer\Type("integer")
|
||||
* @Serializer\Expose
|
||||
*/
|
||||
private $id3;
|
||||
}
|
35
Tests/Functional/Entity/NestedGroup/JMSChatRoomUser.php
Normal file
35
Tests/Functional/Entity/NestedGroup/JMSChatRoomUser.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the NelmioApiDocBundle package.
|
||||
*
|
||||
* (c) Nelmio
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup;
|
||||
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* User.
|
||||
*
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
class JMSChatRoomUser
|
||||
{
|
||||
/**
|
||||
* @Serializer\Type("integer")
|
||||
* @Serializer\Expose
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @Serializer\Type("Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChatFriend")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Groups({"mini"})
|
||||
*/
|
||||
private $friend;
|
||||
}
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Functional;
|
||||
|
||||
use JMS\Serializer\Visitor\SerializationVisitorInterface;
|
||||
|
||||
class JMSFunctionalTest extends WebTestCase
|
||||
{
|
||||
public function testModelPictureDocumentation()
|
||||
@ -192,6 +194,59 @@ class JMSFunctionalTest extends WebTestCase
|
||||
], $this->getModel('JMSDualComplex')->toArray());
|
||||
}
|
||||
|
||||
public function testNestedGroupsV1()
|
||||
{
|
||||
if (interface_exists(SerializationVisitorInterface::class)){
|
||||
$this->markTestSkipped('This applies only for jms/serializer v1.x');
|
||||
}
|
||||
|
||||
$this->assertEquals([
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'living' => ['$ref' => '#/definitions/JMSChatLivingRoom'],
|
||||
'dining' => ['$ref' => '#/definitions/JMSChatRoom'],
|
||||
],
|
||||
], $this->getModel('JMSChatFriend')->toArray());
|
||||
|
||||
$this->assertEquals([
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id1' => ['type' => 'integer'],
|
||||
'id2' => ['type' => 'integer'],
|
||||
'id3' => ['type' => 'integer'],
|
||||
],
|
||||
], $this->getModel('JMSChatRoom')->toArray());
|
||||
}
|
||||
|
||||
public function testNestedGroupsV2()
|
||||
{
|
||||
if (!interface_exists(SerializationVisitorInterface::class)){
|
||||
$this->markTestSkipped('This applies only for jms/serializer v2.x');
|
||||
}
|
||||
|
||||
$this->assertEquals([
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'living' => ['$ref' => '#/definitions/JMSChatLivingRoom'],
|
||||
'dining' => ['$ref' => '#/definitions/JMSChatRoom'],
|
||||
],
|
||||
], $this->getModel('JMSChatFriend')->toArray());
|
||||
|
||||
$this->assertEquals([
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id2' => ['type' => 'integer'],
|
||||
],
|
||||
], $this->getModel('JMSChatRoom')->toArray());
|
||||
|
||||
$this->assertEquals([
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id' => ['type' => 'integer'],
|
||||
],
|
||||
], $this->getModel('JMSChatLivingRoom')->toArray());
|
||||
}
|
||||
|
||||
public function testModelComplexDocumentation()
|
||||
{
|
||||
$this->assertEquals([
|
||||
|
Loading…
x
Reference in New Issue
Block a user