Completed
Pull Request — master (#591)
by Amrouche
08:01 queued 04:36
created

SwaggerCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 3
c 3
b 1
f 1
lcom 1
cbo 3
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A __construct() 0 6 1
A execute() 0 6 1
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
    protected $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