1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the KleijnWeb\SwaggerBundle package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
namespace KleijnWeb\SwaggerBundle\Dev\Command; |
9
|
|
|
|
10
|
|
|
use KleijnWeb\SwaggerBundle\Dev\DocumentFixer\Fixer; |
11
|
|
|
use KleijnWeb\SwaggerBundle\Document\DocumentRepository; |
12
|
|
|
use Symfony\Component\Console\Command\Command; |
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author John Kleijn <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class AmendSwaggerDocumentCommand extends Command |
22
|
|
|
{ |
23
|
|
|
const NAME = 'swagger:document:amend'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var DocumentRepository |
27
|
|
|
*/ |
28
|
|
|
private $documentRepository; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Fixer |
32
|
|
|
*/ |
33
|
|
|
private $fixer; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param DocumentRepository $documentRepository |
37
|
|
|
* @param Fixer $fixer |
38
|
|
|
*/ |
39
|
|
|
public function __construct(DocumentRepository $documentRepository, Fixer $fixer) |
40
|
|
|
{ |
41
|
|
|
parent::__construct(self::NAME); |
42
|
|
|
|
43
|
|
|
$this |
44
|
|
|
->setDescription('Make your Swagger definition reflect your apps in- and output') |
45
|
|
|
->setHelp( |
46
|
|
|
"Will update your definition with predefined SwaggerBundle responses," |
47
|
|
|
. " as well as update it to reflect any changes in your DTOs, should they exist.\n\n" |
48
|
|
|
. "This is a development tool and will only work with require-dev dependencies included" |
49
|
|
|
) |
50
|
|
|
->addArgument('file', InputArgument::REQUIRED, 'File path to the Swagger document') |
51
|
|
|
->addOption( |
52
|
|
|
'out', |
53
|
|
|
'o', |
54
|
|
|
InputOption::VALUE_REQUIRED, |
55
|
|
|
'Write the resulting document to this location (will overwrite existing by default' |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->documentRepository = $documentRepository; |
59
|
|
|
$this->fixer = $fixer; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
65
|
|
|
* |
66
|
|
|
* @param InputInterface $input |
67
|
|
|
* @param OutputInterface $output |
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
72
|
|
|
{ |
73
|
|
|
$document = $this->documentRepository->get($input->getArgument('file')); |
74
|
|
|
$this->fixer->fix($document); |
75
|
|
|
$document->write($input->getOption('out')); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|