From 7b624434171316b3efdc1a6642a16ce296fed3e5 Mon Sep 17 00:00:00 2001 From: anawaz Date: Mon, 19 Mar 2018 13:24:55 +0100 Subject: [PATCH] Updated SwaggerDocblockConvertCommand command in UPGRADE-3.0.md - Allowed null input in `escapeQuotes(string $str)` - description of an API can be null - Added command option `views` to input comma separated list of views - the API can have view(s) other than `default` --- UPGRADE-3.0.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index 0c182a6..38481c7 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -20,6 +20,7 @@ namespace AppBundle\Command; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -35,13 +36,20 @@ class SwaggerDocblockConvertCommand extends ContainerAwareCommand $this ->setDescription('') ->setName('api:doc:convert') + ->addOption('views', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of views to convert the documentation for', 'default') ; } protected function execute(InputInterface $input, OutputInterface $output) { + $views = explode(',', $input->getOption('views')); + $extractor = $this->getContainer()->get('nelmio_api_doc.extractor.api_doc_extractor'); - $apiDocs = $extractor->extractAnnotations($extractor->getRoutes()); + + $apiDocs = []; + foreach ($views as $view) { + $apiDocs = array_merge($apiDocs, $extractor->extractAnnotations($extractor->getRoutes(), $view)); + } foreach ($apiDocs as $annotation) { /** @var ApiDoc $apiDoc */ @@ -175,8 +183,11 @@ class SwaggerDocblockConvertCommand extends ContainerAwareCommand ]; } - private function escapeQuotes(string $str): string + private function escapeQuotes(string $str = null): string { + if ($str === null) { + return ''; + } $lines = []; foreach (explode("\n", $str) as $line) { $lines[] = trim($line, ' *');