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

SwaggerCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
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
        $this->apiDocumentationBuilder = $apiDocumentationBuilder;
31
32
        parent::__construct();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function configure()
39
    {
40
        $this
41
            ->setName('api:swagger:export')
42
            ->setDescription('Dump the Swagger 2.0 (OpenAPI) documentation');
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        $data = $this->apiDocumentationBuilder->getApiDocumentation();
51
        $content = json_encode($data, JSON_PRETTY_PRINT);
52
        $output->writeln($content);
53
    }
54
}
55