Added multilines support for description

This commit is contained in:
William DURAND 2012-04-19 17:17:36 +02:00
parent 33ff68b2e0
commit 8c0aa1d274
5 changed files with 13 additions and 5 deletions

View File

@ -180,9 +180,13 @@ class ApiDocExtractor
protected function getData(ApiDoc $annotation, Route $route, \ReflectionMethod $method) protected function getData(ApiDoc $annotation, Route $route, \ReflectionMethod $method)
{ {
if (null === $annotation->getDescription()) { if (null === $annotation->getDescription()) {
$comments = explode("\n", $this->getDocComment($method)); $comments = explode("\n @", $this->getDocComment($method));
// just set the first line // just set the first line
$annotation->setDescription($comments[0]); $comment = trim($comments[0]);
$comment = preg_replace("#[\n]+#", ' ', $comment);
$comment = preg_replace('#[ ]+#', ' ', $comment);
$annotation->setDescription($comment);
} }
return array('annotation' => $annotation, 'route' => $route); return array('annotation' => $annotation, 'route' => $route);

View File

@ -139,6 +139,9 @@ class ApiDocExtractorTest extends WebTestCase
$data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::myCommentedAction', 'test_route_5'); $data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::myCommentedAction', 'test_route_5');
$this->assertNotNull($data); $this->assertNotNull($data);
$this->assertEquals('This method is useful to test if the getDocComment works.', $data['annotation']->getDescription()); $this->assertEquals(
"This method is useful to test if the getDocComment works. And, it supports multilines until the first '@' char.",
$data['annotation']->getDescription()
);
} }
} }

View File

@ -54,6 +54,7 @@ class TestController
/** /**
* This method is useful to test if the getDocComment works. * This method is useful to test if the getDocComment works.
* And, it supports multilines until the first '@' char.
* *
* @ApiDoc() * @ApiDoc()
*/ */

View File

@ -109,7 +109,7 @@ _Action without HTTP verb_
### `ANY` /my-commented ### ### `ANY` /my-commented ###
_This method is useful to test if the getDocComment works._ _This method is useful to test if the getDocComment works. And, it supports multilines until the first '@' char._
MARKDOWN; MARKDOWN;
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);

View File

@ -152,7 +152,7 @@ class SimpleFormatterTest extends WebTestCase
'requirements' => 'requirements' =>
array( array(
), ),
'description' => 'This method is useful to test if the getDocComment works.', 'description' => 'This method is useful to test if the getDocComment works. And, it supports multilines until the first \'@\' char.',
), ),
), ),
); );