mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Added nested JMS groups exclusion
This commit is contained in:
parent
eb08b7af27
commit
3e3ef87b79
@ -255,7 +255,7 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
||||
*/
|
||||
public function postParse(array $input, array $parameters)
|
||||
{
|
||||
return $this->doPostParse($parameters);
|
||||
return $this->doPostParse($parameters, array(), isset($input['groups']) ? $input['groups'] : array());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -265,7 +265,7 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
||||
* @param array $visited
|
||||
* @return array
|
||||
*/
|
||||
protected function doPostParse (array $parameters, array $visited = array())
|
||||
protected function doPostParse (array $parameters, array $visited = array(), array $groups = array())
|
||||
{
|
||||
foreach ($parameters as $param => $data) {
|
||||
if (isset($data['class']) && isset($data['children']) && !in_array($data['class'], $visited)) {
|
||||
@ -273,10 +273,10 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
||||
|
||||
$input = array('class' => $data['class'], 'groups' => isset($data['groups']) ? $data['groups'] : array());
|
||||
$parameters[$param]['children'] = array_merge(
|
||||
$parameters[$param]['children'], $this->doPostParse($parameters[$param]['children'], $visited)
|
||||
$parameters[$param]['children'], $this->doPostParse($parameters[$param]['children'], $visited, $groups)
|
||||
);
|
||||
$parameters[$param]['children'] = array_merge(
|
||||
$parameters[$param]['children'], $this->doParse($input['class'], $visited, $input['groups'])
|
||||
$parameters[$param]['children'], $this->doParse($input['class'], $visited, $groups)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -40,4 +40,8 @@ class JmsTest
|
||||
*/
|
||||
public $nestedArray;
|
||||
|
||||
/**
|
||||
* @JMS\Groups("hidden")
|
||||
*/
|
||||
public $hidden;
|
||||
}
|
||||
|
@ -320,6 +320,93 @@ class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testNestedGroups()
|
||||
{
|
||||
$metadataFactory = $this->getMock('Metadata\MetadataFactoryInterface');
|
||||
$docCommentExtractor = $this->getMockBuilder('Nelmio\ApiDocBundle\Util\DocCommentExtractor')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$input = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested';
|
||||
$nestedInput = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsTest';
|
||||
|
||||
$nestedPropertyMetadataHidden = new PropertyMetadata($nestedInput, 'hidden');
|
||||
$nestedPropertyMetadataHidden->type = array('name' => 'string');
|
||||
$nestedPropertyMetadataHidden->groups = array('hidden');
|
||||
|
||||
$nestedPropertyMetadataFoo = new PropertyMetadata($nestedInput, 'foo');
|
||||
$nestedPropertyMetadataFoo->type = array('name' => 'string');
|
||||
|
||||
$nestedMetadata = new ClassMetadata($nestedInput);
|
||||
$nestedMetadata->addPropertyMetadata($nestedPropertyMetadataHidden);
|
||||
$nestedMetadata->addPropertyMetadata($nestedPropertyMetadataFoo);
|
||||
|
||||
$propertyMetadataFoo = new PropertyMetadata($input, 'foo');
|
||||
$propertyMetadataFoo->type = array('name' => 'string');
|
||||
|
||||
$propertyMetadataBar = new PropertyMetadata($input, 'bar');
|
||||
$propertyMetadataBar->type = array('name' => 'string');
|
||||
$propertyMetadataBar->groups = array('Default');
|
||||
|
||||
$propertyMetadataParent = new PropertyMetadata($input, 'parent');
|
||||
$propertyMetadataParent->type = array('name' => $nestedInput);
|
||||
$propertyMetadataParent->groups = array('hidden');
|
||||
|
||||
$metadata = new ClassMetadata($input);
|
||||
$metadata->addPropertyMetadata($propertyMetadataFoo);
|
||||
$metadata->addPropertyMetadata($propertyMetadataBar);
|
||||
$metadata->addPropertyMetadata($propertyMetadataParent);
|
||||
|
||||
$metadataFactory->expects($this->any())
|
||||
->method('getMetadataForClass')
|
||||
->will($this->returnValueMap(array(
|
||||
array($input, $metadata),
|
||||
array($nestedInput, $nestedMetadata)
|
||||
)));
|
||||
|
||||
$propertyNamingStrategy = new CamelCaseNamingStrategy();
|
||||
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);
|
||||
|
||||
// No group specified.
|
||||
$output = $jmsMetadataParser->parse(
|
||||
array(
|
||||
'class' => $input,
|
||||
'groups' => array('hidden'),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'parent' => array(
|
||||
'dataType' => 'object (JmsTest)',
|
||||
'actualType' => DataTypes::MODEL,
|
||||
'subType' => $nestedInput,
|
||||
'default' => null,
|
||||
'required' => false,
|
||||
'description' => null,
|
||||
'readonly' => false,
|
||||
'sinceVersion' => null,
|
||||
'untilVersion' => null,
|
||||
'class' => $nestedInput,
|
||||
'children' => array(
|
||||
'hidden' => array(
|
||||
'dataType' => 'string',
|
||||
'actualType' => 'string',
|
||||
'subType' => null,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'description' => null,
|
||||
'readonly' => false,
|
||||
'sinceVersion' => null,
|
||||
'untilVersion' => null
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
public function testParserWithVersion()
|
||||
{
|
||||
$metadataFactory = $this->getMock('Metadata\MetadataFactoryInterface');
|
||||
|
Loading…
x
Reference in New Issue
Block a user