Merge branch 'master' of https://github.com/nelmio/NelmioApiDocBundle into feature-cache

This commit is contained in:
Florent DUBOST 2013-03-27 15:46:28 +01:00
commit 5ec931185f
6 changed files with 52 additions and 12 deletions

View File

@ -70,11 +70,21 @@ class ApiDocExtractor
* You can extend this method if you don't want all the routes
* to be included.
*
* @return array of Route
* @return \Traversable Iterator for a RouteCollection
*/
public function getRoutes()
{
return $this->router->getRouteCollection()->all();
return $this->router->getRouteCollection()->getIterator();
}
/**
* Extracts annotations from all known routes
*
* @return array
*/
public function all()
{
return $this->extractAnnotations($this->getRoutes());
}
/**
@ -82,14 +92,16 @@ class ApiDocExtractor
* - annotation
* - resource
*
* @param \Traversable $routes The routes for which the annotations should be extracted
*
* @return array
*/
public function all()
public function extractAnnotations(\Traversable $routes)
{
$array = array();
$resources = array();
foreach ($this->getRoutes() as $route) {
foreach ($routes as $route) {
if ($method = $this->getReflectionMethod($route->getDefault('_controller'))) {
if ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS)) {
if ($annotation->isResource()) {

View File

@ -15,6 +15,7 @@ use Metadata\MetadataFactoryInterface;
use Nelmio\ApiDocBundle\Util\DocCommentExtractor;
use JMS\Serializer\Metadata\PropertyMetadata;
use JMS\Serializer\Metadata\VirtualPropertyMetadata;
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
/**
* Uses the JMS metadata factory to extract input/output model information
@ -27,6 +28,11 @@ class JmsMetadataParser implements ParserInterface
*/
private $factory;
/**
* @var PropertyNamingStrategyInterface
*/
private $namingStrategy;
/**
* @var \Nelmio\ApiDocBundle\Util\DocCommentExtractor
*/
@ -35,9 +41,13 @@ class JmsMetadataParser implements ParserInterface
/**
* Constructor, requires JMS Metadata factory
*/
public function __construct(MetadataFactoryInterface $factory, DocCommentExtractor $commentExtractor)
{
public function __construct(
MetadataFactoryInterface $factory,
PropertyNamingStrategyInterface $namingStrategy,
DocCommentExtractor $commentExtractor
) {
$this->factory = $factory;
$this->namingStrategy = $namingStrategy;
$this->commentExtractor = $commentExtractor;
}
@ -85,7 +95,7 @@ class JmsMetadataParser implements ParserInterface
// iterate over property metadata
foreach ($meta->propertyMetadata as $item) {
if (!is_null($item->type)) {
$name = isset($item->serializedName) ? $item->serializedName : $item->name;
$name = $this->namingStrategy->translateName($item);
$dataType = $this->processDataType($item);

View File

@ -10,6 +10,7 @@
<services>
<service id="nelmio_api_doc.parser.jms_metadata_parser" class="%nelmio_api_doc.parser.jms_metadata_parser.class%">
<argument type="service" id="jms_serializer.metadata_factory" />
<argument type="service" id="jms_serializer.naming_strategy" />
<argument type="service" id="nelmio_api_doc.doc_comment_extractor" />
<tag name="nelmio_api_doc.extractor.parser" />
</service>

View File

@ -250,13 +250,13 @@ nested[parent][nested]:
* required: false
* description: No description.
nested[parent][nestedArray][]:
nested[parent][nested_array][]:
* type: array of objects (JmsNested)
* required: false
* description: No description.
nestedArray[]:
nested_array[]:
* type: array of objects (JmsNested)
* required: false

View File

@ -345,7 +345,7 @@ With multiple lines.',
'description' => 'No description.',
'readonly' => false,
),
'nestedArray' =>
'nested_array' =>
array (
'dataType' => 'array of objects (JmsNested)',
'required' => false,
@ -356,7 +356,7 @@ With multiple lines.',
),
),
),
'nestedArray' =>
'nested_array' =>
array (
'dataType' => 'array of objects (JmsNested)',
'required' => false,

View File

@ -44,6 +44,23 @@ class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
$metadata->addPropertyMetadata($propertyMetadataBar);
$metadata->addPropertyMetadata($propertyMetadataBaz);
$propertyNamingStrategy = $this->getMock('JMS\Serializer\Naming\PropertyNamingStrategyInterface');
$propertyNamingStrategy
->expects($this->at(0))
->method('translateName')
->will($this->returnValue('foo'));
$propertyNamingStrategy
->expects($this->at(1))
->method('translateName')
->will($this->returnValue('bar'));
$propertyNamingStrategy
->expects($this->at(2))
->method('translateName')
->will($this->returnValue('baz'));
$input = new JmsNested();
$metadataFactory->expects($this->once())
@ -51,7 +68,7 @@ class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
->with($input)
->will($this->returnValue($metadata));
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $docCommentExtractor);
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);
$output = $jmsMetadataParser->parse($input);