mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Merge pull request #630 from munkie/dump-command-views
Add view option to api:doc:dump command
This commit is contained in:
commit
5de5d530dd
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Command;
|
namespace Nelmio\ApiDocBundle\Command;
|
||||||
|
|
||||||
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
@ -33,6 +34,7 @@ class DumpCommand extends ContainerAwareCommand
|
|||||||
'Output format like: ' . implode(', ', $this->availableFormats),
|
'Output format like: ' . implode(', ', $this->availableFormats),
|
||||||
$this->availableFormats[0]
|
$this->availableFormats[0]
|
||||||
)
|
)
|
||||||
|
->addOption('view', '', InputOption::VALUE_OPTIONAL, '', ApiDoc::DEFAULT_VIEW)
|
||||||
->addOption('no-sandbox', '', InputOption::VALUE_NONE)
|
->addOption('no-sandbox', '', InputOption::VALUE_NONE)
|
||||||
->setName('api:doc:dump')
|
->setName('api:doc:dump')
|
||||||
;
|
;
|
||||||
@ -41,6 +43,8 @@ class DumpCommand extends ContainerAwareCommand
|
|||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$format = $input->getOption('format');
|
$format = $input->getOption('format');
|
||||||
|
$view = $input->getOption('view');
|
||||||
|
|
||||||
$routeCollection = $this->getContainer()->get('router')->getRouteCollection();
|
$routeCollection = $this->getContainer()->get('router')->getRouteCollection();
|
||||||
|
|
||||||
if (!$input->hasOption('format') || in_array($format, array('json'))) {
|
if (!$input->hasOption('format') || in_array($format, array('json'))) {
|
||||||
@ -62,7 +66,7 @@ class DumpCommand extends ContainerAwareCommand
|
|||||||
$this->getContainer()->set('request', new Request(), 'request');
|
$this->getContainer()->set('request', new Request(), 'request');
|
||||||
}
|
}
|
||||||
|
|
||||||
$extractedDoc = $this->getContainer()->get('nelmio_api_doc.extractor.api_doc_extractor')->all();
|
$extractedDoc = $this->getContainer()->get('nelmio_api_doc.extractor.api_doc_extractor')->all($view);
|
||||||
$formattedDoc = $formatter->format($extractedDoc);
|
$formattedDoc = $formatter->format($extractedDoc);
|
||||||
|
|
||||||
if ('json' === $format) {
|
if ('json' === $format) {
|
||||||
|
99
Tests/Command/DumpCommandTest.php
Normal file
99
Tests/Command/DumpCommandTest.php
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NelmioApiDocBundle\Tests\Command;
|
||||||
|
|
||||||
|
use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
|
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||||
|
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||||
|
|
||||||
|
class DumpCommandTest extends WebTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider viewProvider
|
||||||
|
*
|
||||||
|
* @param string $view Command view option value
|
||||||
|
* @param array $expectedMethodsCount Expected resource methods count
|
||||||
|
* @param array $expectedMethodValues Expected resource method values
|
||||||
|
*/
|
||||||
|
public function testDumpWithViewOption($view, array $expectedMethodsCount, array $expectedMethodValues)
|
||||||
|
{
|
||||||
|
$this->getContainer();
|
||||||
|
|
||||||
|
$application = new Application(static::$kernel);
|
||||||
|
$application->setCatchExceptions(false);
|
||||||
|
$application->setAutoExit(false);
|
||||||
|
|
||||||
|
$tester = new ApplicationTester($application);
|
||||||
|
|
||||||
|
$input = array(
|
||||||
|
'command' => 'api:doc:dump',
|
||||||
|
'--view' => $view,
|
||||||
|
'--format' => 'json',
|
||||||
|
);
|
||||||
|
$tester->run($input);
|
||||||
|
|
||||||
|
$display = $tester->getDisplay();
|
||||||
|
|
||||||
|
$this->assertJson($display);
|
||||||
|
|
||||||
|
$json = json_decode($display);
|
||||||
|
|
||||||
|
$accessor = PropertyAccess::createPropertyAccessor();
|
||||||
|
|
||||||
|
foreach ($expectedMethodsCount as $propertyPath => $expectedCount) {
|
||||||
|
$this->assertCount($expectedCount, $accessor->getValue($json, $propertyPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($expectedMethodValues as $propertyPath => $expectedValue) {
|
||||||
|
$this->assertEquals($expectedValue, $accessor->getValue($json, $propertyPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function viewProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'test' => array(
|
||||||
|
'test',
|
||||||
|
array(
|
||||||
|
'/api/resources' => 1,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'/api/resources[0].method' => 'GET',
|
||||||
|
'/api/resources[0].uri' => '/api/resources.{_format}',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'premium' => array(
|
||||||
|
'premium',
|
||||||
|
array(
|
||||||
|
'/api/resources' => 2,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'/api/resources[0].method' => 'GET',
|
||||||
|
'/api/resources[0].uri' => '/api/resources.{_format}',
|
||||||
|
'/api/resources[1].method' => 'POST',
|
||||||
|
'/api/resources[1].uri' => '/api/resources.{_format}',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'default' => array(
|
||||||
|
'default',
|
||||||
|
array(
|
||||||
|
'/api/resources' => 4,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'/api/resources[0].method' => 'GET',
|
||||||
|
'/api/resources[0].uri' => '/api/resources.{_format}',
|
||||||
|
'/api/resources[1].method' => 'POST',
|
||||||
|
'/api/resources[1].uri' => '/api/resources.{_format}',
|
||||||
|
'/api/resources[2].method' => 'GET',
|
||||||
|
'/api/resources[2].uri' => '/api/resources/{id}.{_format}',
|
||||||
|
'/api/resources[3].method' => 'DELETE',
|
||||||
|
'/api/resources[3].uri' => '/api/resources/{id}.{_format}',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,7 @@
|
|||||||
"symfony/validator": "~2.1",
|
"symfony/validator": "~2.1",
|
||||||
"symfony/yaml": "~2.1",
|
"symfony/yaml": "~2.1",
|
||||||
"symfony/form": "~2.1",
|
"symfony/form": "~2.1",
|
||||||
|
"symfony/finder": "~2.1",
|
||||||
"symfony/serializer": "~2.7@dev",
|
"symfony/serializer": "~2.7@dev",
|
||||||
"friendsofsymfony/rest-bundle": "~1.0",
|
"friendsofsymfony/rest-bundle": "~1.0",
|
||||||
"jms/serializer-bundle": ">=0.11",
|
"jms/serializer-bundle": ">=0.11",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user