Completed
Pull Request — master (#591)
by Amrouche
03:11
created

SwaggerCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Command;
13
14
use ApiPlatform\Core\Swagger\ApiDocumentationBuilder;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Console command to dump Swagger API documentations.
21
 *
22
 * @author Amrouche Hamza <[email protected]>
23
 */
24
final class SwaggerCommand extends Command
25
{
26
    private $apiDocumentationBuilder;
27
28
    public function __construct(ApiDocumentationBuilder $apiDocumentationBuilder)
29
    {
30
        parent::__construct();
31
        $this->apiDocumentationBuilder = $apiDocumentationBuilder;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function configure()
38
    {
39
        $this
40
            ->setName('api:swagger:export')
41
            ->setDescription('Dump the Swagger 2.0 (OpenAPI) documentation');
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $data = $this->apiDocumentationBuilder->getApiDocumentation();
50
        $content = json_encode($data, JSON_PRETTY_PRINT);
51
        $output->writeln($content);
52
    }
53
}
54