mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Parse JSM\Inline, fixes #372
This commit is contained in:
parent
ae877d74a0
commit
b66e5c4449
@ -131,21 +131,23 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$params[$name] = array(
|
if (!$dataType['inline']) {
|
||||||
'dataType' => $dataType['normalized'],
|
$params[$name] = array(
|
||||||
'actualType' => $dataType['actualType'],
|
'dataType' => $dataType['normalized'],
|
||||||
'subType' => $dataType['class'],
|
'actualType' => $dataType['actualType'],
|
||||||
'required' => false,
|
'subType' => $dataType['class'],
|
||||||
'default' => isset($defaultProperties[$item->name]) ? $defaultProperties[$item->name] : null,
|
'required' => false,
|
||||||
//TODO: can't think of a good way to specify this one, JMS doesn't have a setting for this
|
'default' => isset($defaultProperties[$item->name]) ? $defaultProperties[$item->name] : null,
|
||||||
'description' => $this->getDescription($item),
|
//TODO: can't think of a good way to specify this one, JMS doesn't have a setting for this
|
||||||
'readonly' => $item->readOnly,
|
'description' => $this->getDescription($item),
|
||||||
'sinceVersion' => $item->sinceVersion,
|
'readonly' => $item->readOnly,
|
||||||
'untilVersion' => $item->untilVersion,
|
'sinceVersion' => $item->sinceVersion,
|
||||||
);
|
'untilVersion' => $item->untilVersion,
|
||||||
|
);
|
||||||
|
|
||||||
if (!is_null($dataType['class']) && false === $dataType['primitive']) {
|
if (!is_null($dataType['class']) && false === $dataType['primitive']) {
|
||||||
$params[$name]['class'] = $dataType['class'];
|
$params[$name]['class'] = $dataType['class'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if class already parsed, continue, to avoid infinite recursion
|
// if class already parsed, continue, to avoid infinite recursion
|
||||||
@ -155,8 +157,14 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
|||||||
|
|
||||||
// check for nested classes with JMS metadata
|
// check for nested classes with JMS metadata
|
||||||
if ($dataType['class'] && false === $dataType['primitive'] && null !== $this->factory->getMetadataForClass($dataType['class'])) {
|
if ($dataType['class'] && false === $dataType['primitive'] && null !== $this->factory->getMetadataForClass($dataType['class'])) {
|
||||||
$visited[] = $dataType['class'];
|
$visited[] = $dataType['class'];
|
||||||
$params[$name]['children'] = $this->doParse($dataType['class'], $visited, $groups);
|
$children = $this->doParse($dataType['class'], $visited, $groups);
|
||||||
|
|
||||||
|
if ($dataType['inline']) {
|
||||||
|
$params = array_merge($params, $children);
|
||||||
|
} else {
|
||||||
|
$params[$name]['children'] = $children;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,6 +189,7 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
|||||||
'actualType' => DataTypes::COLLECTION,
|
'actualType' => DataTypes::COLLECTION,
|
||||||
'class' => $this->typeMap[$nestedType],
|
'class' => $this->typeMap[$nestedType],
|
||||||
'primitive' => true,
|
'primitive' => true,
|
||||||
|
'inline' => false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,6 +200,7 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
|||||||
'actualType' => DataTypes::COLLECTION,
|
'actualType' => DataTypes::COLLECTION,
|
||||||
'class' => $nestedType,
|
'class' => $nestedType,
|
||||||
'primitive' => false,
|
'primitive' => false,
|
||||||
|
'inline' => false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,6 +213,7 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
|||||||
'actualType' => $this->typeMap[$type],
|
'actualType' => $this->typeMap[$type],
|
||||||
'class' => null,
|
'class' => null,
|
||||||
'primitive' => true,
|
'primitive' => true,
|
||||||
|
'inline' => false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +224,7 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
|||||||
'class' => $type,
|
'class' => $type,
|
||||||
'actualType' => DataTypes::MODEL,
|
'actualType' => DataTypes::MODEL,
|
||||||
'primitive' => false,
|
'primitive' => false,
|
||||||
|
'inline' => false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +236,7 @@ class JmsMetadataParser implements ParserInterface, PostParserInterface
|
|||||||
'class' => $type,
|
'class' => $type,
|
||||||
'actualType' => DataTypes::MODEL,
|
'actualType' => DataTypes::MODEL,
|
||||||
'primitive' => false,
|
'primitive' => false,
|
||||||
|
'inline' => $item->inline,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
Tests/Fixtures/Model/JmsInline.php
Normal file
18
Tests/Fixtures/Model/JmsInline.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Model;
|
||||||
|
|
||||||
|
use JMS\Serializer\Annotation as JMS;
|
||||||
|
|
||||||
|
class JmsInline
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @JMS\Type("string");
|
||||||
|
*/
|
||||||
|
public $foo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @JMS\Inline
|
||||||
|
*/
|
||||||
|
public $inline;
|
||||||
|
}
|
@ -402,6 +402,89 @@ class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testParserWithInline()
|
||||||
|
{
|
||||||
|
$metadataFactory = $this->getMock('Metadata\MetadataFactoryInterface');
|
||||||
|
$docCommentExtractor = $this->getMockBuilder('Nelmio\ApiDocBundle\Util\DocCommentExtractor')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$propertyMetadataFoo = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsInline', 'foo');
|
||||||
|
$propertyMetadataFoo->type = array('name' => 'string');
|
||||||
|
|
||||||
|
$propertyMetadataInline = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsInline', 'inline');
|
||||||
|
$propertyMetadataInline->type = array('name' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsTest');
|
||||||
|
$propertyMetadataInline->inline = true;
|
||||||
|
|
||||||
|
$input = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsInline';
|
||||||
|
|
||||||
|
$metadata = new ClassMetadata($input);
|
||||||
|
$metadata->addPropertyMetadata($propertyMetadataFoo);
|
||||||
|
$metadata->addPropertyMetadata($propertyMetadataInline);
|
||||||
|
|
||||||
|
$propertyMetadataBar = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsTest', 'bar');
|
||||||
|
$propertyMetadataBar->type = array('name' => 'string');
|
||||||
|
|
||||||
|
$subInput = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsTest';
|
||||||
|
|
||||||
|
$subMetadata = new ClassMetadata($subInput);
|
||||||
|
$subMetadata->addPropertyMetadata($propertyMetadataBar);
|
||||||
|
|
||||||
|
$metadataFactory->expects($this->at(0))
|
||||||
|
->method('getMetadataForClass')
|
||||||
|
->with($input)
|
||||||
|
->will($this->returnValue($metadata));
|
||||||
|
|
||||||
|
$metadataFactory->expects($this->at(1))
|
||||||
|
->method('getMetadataForClass')
|
||||||
|
->with($subInput)
|
||||||
|
->will($this->returnValue($subMetadata));
|
||||||
|
|
||||||
|
$metadataFactory->expects($this->at(2))
|
||||||
|
->method('getMetadataForClass')
|
||||||
|
->with($subInput)
|
||||||
|
->will($this->returnValue($subMetadata));
|
||||||
|
|
||||||
|
$propertyNamingStrategy = new CamelCaseNamingStrategy();
|
||||||
|
|
||||||
|
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);
|
||||||
|
|
||||||
|
$output = $jmsMetadataParser->parse(
|
||||||
|
array(
|
||||||
|
'class' => $input,
|
||||||
|
'groups' => array(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(
|
||||||
|
'foo' => array(
|
||||||
|
'dataType' => 'string',
|
||||||
|
'actualType' => DataTypes::STRING,
|
||||||
|
'subType' => null,
|
||||||
|
'default' => null,
|
||||||
|
'required' => false,
|
||||||
|
'description' => null,
|
||||||
|
'readonly' => false,
|
||||||
|
'sinceVersion' => null,
|
||||||
|
'untilVersion' => null,
|
||||||
|
),
|
||||||
|
'bar' => array(
|
||||||
|
'dataType' => 'string',
|
||||||
|
'actualType' => DataTypes::STRING,
|
||||||
|
'subType' => null,
|
||||||
|
'default' => null,
|
||||||
|
'required' => false,
|
||||||
|
'description' => null,
|
||||||
|
'readonly' => false,
|
||||||
|
'sinceVersion' => null,
|
||||||
|
'untilVersion' => null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
$output
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function dataTestParserWithNestedType()
|
public function dataTestParserWithNestedType()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user