diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index e63daf8..5876601 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -366,7 +366,7 @@ class ApiDoc $data['statusCodes'] = $statusCodes; } - if($section = $this->section) { + if ($section = $this->section) { $data['section'] = $section; } diff --git a/Formatter/AbstractFormatter.php b/Formatter/AbstractFormatter.php index f2535d8..7935c0c 100644 --- a/Formatter/AbstractFormatter.php +++ b/Formatter/AbstractFormatter.php @@ -134,7 +134,7 @@ abstract class AbstractFormatter implements FormatterInterface foreach ($array as $section => $resources) { foreach ($resources as $path => $annotations) { foreach ($annotations as $annotation) { - if($section) { + if ($section) { $processedCollection[$section][$path][] = $this->processAnnotation($annotation); } else { $processedCollection['_others'][$path][] = $this->processAnnotation($annotation); @@ -143,7 +143,8 @@ abstract class AbstractFormatter implements FormatterInterface } } - ksort($processedCollection); + ksort($processedCollection); + return $processedCollection; } } diff --git a/Formatter/MarkdownFormatter.php b/Formatter/MarkdownFormatter.php index 8e3dd76..ec51769 100644 --- a/Formatter/MarkdownFormatter.php +++ b/Formatter/MarkdownFormatter.php @@ -111,21 +111,31 @@ class MarkdownFormatter extends AbstractFormatter protected function render(array $collection) { $markdown = ''; - foreach ($collection as $resource => $arrayOfData) { - $markdown .= $this->renderResourceSection($resource, $arrayOfData); + foreach ($collection as $section => $resources) { + $markdown .= $this->renderResourceSection($section, $resources); $markdown .= "\n"; } return trim($markdown); } - private function renderResourceSection($resource, array $arrayOfData) + private function renderResourceSection($section, array $resources) { - $markdown = sprintf("# %s #\n\n", $resource); + if ('_others' !== $section) { + $markdown = sprintf("# %s #\n\n", $section); + } - foreach ($arrayOfData as $data) { - $markdown .= $this->renderOne($data); - $markdown .= "\n"; + foreach ($resources as $resource => $methods) { + if ('_others' === $section && 'others' !== $resource) { + $markdown = sprintf("## %s ##\n\n", $resource); + } elseif ('others' !== $resource) { + $markdown = sprintf("## %s ##\n\n", $resource); + } + + foreach ($methods as $method) { + $markdown .= $this->renderOne($method); + $markdown .= "\n"; + } } return $markdown; diff --git a/Resources/views/resources.html.twig b/Resources/views/resources.html.twig index eae4c49..9315f37 100644 --- a/Resources/views/resources.html.twig +++ b/Resources/views/resources.html.twig @@ -29,6 +29,6 @@ {% endfor %} {% if section != '_others' %} - {% endif %} + {% endif %} {% endfor %} {% endblock content %} diff --git a/Tests/Formatter/MarkdownFormatterTest.php b/Tests/Formatter/MarkdownFormatterTest.php index f972363..bfd9638 100644 --- a/Tests/Formatter/MarkdownFormatterTest.php +++ b/Tests/Formatter/MarkdownFormatterTest.php @@ -26,7 +26,7 @@ class MarkdownFormatterTest extends WebTestCase $result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->format($data); $expected = <<