mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Jms serializer default groups should not generate new definitions when possible (#1367)
* if the group does not define per property exclusion, then remove possible obsolete property exclusions * if the group is using only the default group, then is as not defining a group * test that the user does not get a new alias just because another property pf the same object has some groups * use strict comparison
This commit is contained in:
parent
6e04137ee6
commit
09e6f30572
@ -72,6 +72,12 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
||||
$groups = $model->getGroups();
|
||||
if (isset($groups[$name]) && is_array($groups[$name])) {
|
||||
$groups = $model->getGroups()[$name];
|
||||
} elseif (is_array($groups)) {
|
||||
$groups = array_filter($groups, 'is_scalar');
|
||||
}
|
||||
|
||||
if ([GroupsExclusionStrategy::DEFAULT_GROUP] === $groups) {
|
||||
$groups = null;
|
||||
}
|
||||
|
||||
// read property options from Swagger Property annotation if it exists
|
||||
|
@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;
|
||||
|
||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSDualComplex;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\VirtualProperty;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
@ -58,4 +59,16 @@ class JMSController
|
||||
public function complexAction()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/jms_complex_dual", methods={"GET"})
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Success",
|
||||
* @Model(type=JMSDualComplex::class, groups={"Default", "complex" : {"user" : {"details"}}})
|
||||
* )
|
||||
*/
|
||||
public function complexDualAction()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
34
Tests/Functional/Entity/JMSDualComplex.php
Normal file
34
Tests/Functional/Entity/JMSDualComplex.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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;
|
||||
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||
use Swagger\Annotations as SWG;
|
||||
|
||||
class JMSDualComplex
|
||||
{
|
||||
/**
|
||||
* @Serializer\Type("integer")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @SWG\Property(ref=@Model(type=JMSComplex::class))
|
||||
*/
|
||||
private $complex;
|
||||
|
||||
/**
|
||||
* @SWG\Property(ref=@Model(type=JMSUser::class))
|
||||
*/
|
||||
private $user;
|
||||
}
|
@ -97,6 +97,24 @@ class JMSFunctionalTest extends WebTestCase
|
||||
], $this->getModel('JMSUser')->toArray());
|
||||
}
|
||||
|
||||
public function testModelComplexDualDocumentation()
|
||||
{
|
||||
$this->assertEquals([
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id' => [
|
||||
'type' => 'integer',
|
||||
],
|
||||
'complex' => [
|
||||
'$ref' => '#/definitions/JMSComplex2',
|
||||
],
|
||||
'user' => [
|
||||
'$ref' => '#/definitions/JMSUser',
|
||||
],
|
||||
],
|
||||
], $this->getModel('JMSDualComplex')->toArray());
|
||||
}
|
||||
|
||||
public function testModelComplexDocumentation()
|
||||
{
|
||||
$this->assertEquals([
|
||||
|
Loading…
x
Reference in New Issue
Block a user