|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Command; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Import classes |
|
7
|
|
|
*/ |
|
8
|
|
|
use App\ContainerAwareTrait; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Import functions |
|
15
|
|
|
*/ |
|
16
|
|
|
use function json_encode; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Import constants |
|
20
|
|
|
*/ |
|
21
|
|
|
use const JSON_PRETTY_PRINT; |
|
22
|
|
|
use const JSON_UNESCAPED_SLASHES; |
|
23
|
|
|
use const JSON_UNESCAPED_UNICODE; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* GenerateOpenApiDocumentationCommand |
|
27
|
|
|
*/ |
|
28
|
|
|
final class GenerateOpenApiDocumentationCommand extends Command |
|
29
|
|
|
{ |
|
30
|
|
|
use ContainerAwareTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function configure() : void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->setName('app:openapi:generate-documentation'); |
|
38
|
|
|
$this->setDescription('Generates OpenApi documentation'); |
|
39
|
|
|
|
|
40
|
|
|
$this->addOption('pretty', null, null, 'Use whitespace in returned data to format it'); |
|
41
|
|
|
$this->addOption('unescaped-slashes', null, null, 'Do not escape /'); |
|
42
|
|
|
$this->addOption('unescaped-unicode', null, null, 'Encode multi-byte Unicode characters literally'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritDoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) : int |
|
49
|
|
|
{ |
|
50
|
|
|
$mode = 0; |
|
51
|
|
|
|
|
52
|
|
|
if ($input->getOption('pretty')) { |
|
53
|
|
|
$mode |= JSON_PRETTY_PRINT; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if ($input->getOption('unescaped-slashes')) { |
|
57
|
|
|
$mode |= JSON_UNESCAPED_SLASHES; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if ($input->getOption('unescaped-unicode')) { |
|
61
|
|
|
$mode |= JSON_UNESCAPED_UNICODE; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$openapi = $this->container->get('openapi'); |
|
65
|
|
|
|
|
66
|
|
|
$output->writeln(json_encode($openapi->toArray(), $mode)); |
|
67
|
|
|
|
|
68
|
|
|
return 0; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|