mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Merge branch '1.0.x'
This commit is contained in:
commit
e2e647bb03
@ -31,6 +31,11 @@ class ApiDoc
|
|||||||
*/
|
*/
|
||||||
private $description = null;
|
private $description = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $documentation = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Boolean
|
* @var Boolean
|
||||||
*/
|
*/
|
||||||
@ -92,6 +97,22 @@ class ApiDoc
|
|||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getDocumentation()
|
||||||
|
{
|
||||||
|
return $this->documentation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $documentation
|
||||||
|
*/
|
||||||
|
public function setDocumentation($documentation)
|
||||||
|
{
|
||||||
|
$this->documentation = $documentation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
|
@ -193,6 +193,8 @@ class ApiDocExtractor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$annotation->setDocumentation($this->getDocCommentText($method));
|
||||||
|
|
||||||
$paramDocs = array();
|
$paramDocs = array();
|
||||||
foreach (explode("\n", $docblock) as $line) {
|
foreach (explode("\n", $docblock) as $line) {
|
||||||
if (preg_match('{^@param (.+)}', trim($line), $matches)) {
|
if (preg_match('{^@param (.+)}', trim($line), $matches)) {
|
||||||
@ -220,4 +222,19 @@ class ApiDocExtractor
|
|||||||
|
|
||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getDocCommentText(\Reflector $reflected)
|
||||||
|
{
|
||||||
|
$comment = $reflected->getDocComment();
|
||||||
|
|
||||||
|
// Remove PHPDoc
|
||||||
|
$comment = preg_replace('/^\s+\* @[\w0-9]+.*/msi', '', $comment);
|
||||||
|
|
||||||
|
// let's clean the doc block
|
||||||
|
$comment = str_replace('/**', '', $comment);
|
||||||
|
$comment = str_replace('*/', '', $comment);
|
||||||
|
$comment = preg_replace('/^\s*\* ?/m', '', $comment);
|
||||||
|
|
||||||
|
return trim($comment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,10 @@ abstract class AbstractFormatter implements FormatterInterface
|
|||||||
$data['description'] = $description;
|
$data['description'] = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($documentation = $apiDoc->getDocumentation()) {
|
||||||
|
$data['documentation'] = $documentation;
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,13 @@ class MarkdownFormatter extends AbstractFormatter
|
|||||||
|
|
||||||
$markdown .= "\n\n";
|
$markdown .= "\n\n";
|
||||||
|
|
||||||
|
if (isset($data['documentation']) && !empty($data['documentation'])) {
|
||||||
|
if (isset($data['description']) && 0 === strcmp($data['description'], $data['documentation'])) {
|
||||||
|
$markdown .= $data['documentation'];
|
||||||
|
$markdown .= "\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($data['requirements']) && !empty($data['requirements'])) {
|
if (isset($data['requirements']) && !empty($data['requirements'])) {
|
||||||
$markdown .= "#### Requirements ####\n\n";
|
$markdown .= "#### Requirements ####\n\n";
|
||||||
|
|
||||||
|
@ -62,6 +62,10 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
|||||||
class YourController extends Controller
|
class YourController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* This the documentation description of your method, it will appear
|
||||||
|
* on a specific pane. It will read all the text until the first
|
||||||
|
* annotation.
|
||||||
|
*
|
||||||
* @ApiDoc(
|
* @ApiDoc(
|
||||||
* resource=true,
|
* resource=true,
|
||||||
* description="This is a description of your API method",
|
* description="This is a description of your API method",
|
||||||
|
@ -23,6 +23,11 @@
|
|||||||
|
|
||||||
<div class="panes">
|
<div class="panes">
|
||||||
<div class="pane content selected">
|
<div class="pane content selected">
|
||||||
|
{% if data.documentation is defined and data.documentation is not empty %}
|
||||||
|
<h4>Documentation</h4>
|
||||||
|
<p>{{ data.documentation|markdown }}</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if data.requirements is defined and data.requirements is not empty %}
|
{% if data.requirements is defined and data.requirements is not empty %}
|
||||||
<h4>Requirements</h4>
|
<h4>Requirements</h4>
|
||||||
<table class="fullwidth">
|
<table class="fullwidth">
|
||||||
|
@ -50,6 +50,7 @@ class AppKernel extends Kernel
|
|||||||
new \Symfony\Bundle\TwigBundle\TwigBundle(),
|
new \Symfony\Bundle\TwigBundle\TwigBundle(),
|
||||||
new \Nelmio\ApiDocBundle\NelmioApiDocBundle(),
|
new \Nelmio\ApiDocBundle\NelmioApiDocBundle(),
|
||||||
new \Nelmio\ApiDocBundle\Tests\Fixtures\NelmioApiDocTestBundle(),
|
new \Nelmio\ApiDocBundle\Tests\Fixtures\NelmioApiDocTestBundle(),
|
||||||
|
new \Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,6 +186,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
'page' => array('type' => 'int', 'description' => '', 'value' => ''),
|
'page' => array('type' => 'int', 'description' => '', 'value' => ''),
|
||||||
),
|
),
|
||||||
'description' => 'This method is useful to test if the getDocComment works. And, it supports multilines until the first \'@\' char.',
|
'description' => 'This method is useful to test if the getDocComment works. And, it supports multilines until the first \'@\' char.',
|
||||||
|
'documentation' => "This method is useful to test if the getDocComment works.\nAnd, it supports multilines until the first '@' char."
|
||||||
),
|
),
|
||||||
4 =>
|
4 =>
|
||||||
array(
|
array(
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"symfony/framework-bundle": "2.1.*",
|
"symfony/framework-bundle": "2.1.*",
|
||||||
"symfony/twig-bundle": "2.1.*",
|
"symfony/twig-bundle": "2.1.*",
|
||||||
"symfony/form": "2.1.*"
|
"symfony/form": "2.1.*",
|
||||||
|
"knplabs/knp-markdown-bundle": "dev-master"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/css-selector": "2.1.*",
|
"symfony/css-selector": "2.1.*",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user