|
1
|
|
|
<?php |
|
2
|
|
|
namespace SoliDry; |
|
3
|
|
|
|
|
4
|
|
|
use SoliDry\Controllers\BaseCommand; |
|
5
|
|
|
|
|
6
|
|
|
class ApiGenerator extends BaseCommand |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* The name and signature of the console command. |
|
10
|
|
|
* |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $signature = 'api:generate {inputFile? : The file (in yaml format) based on which code-base will be generated.} |
|
14
|
|
|
{--migrations : Whether to generate migrations for RDBMS} |
|
15
|
|
|
{--regenerate : Whether to regenerate code by overriding previously created files} |
|
16
|
|
|
{--merge= : Type of merge: "last" to merge last generated changes with current document, "number" of steps to get back in history e.g.: --merge=9 will get code-generator 9 steps backward to merge, "timestamp" generator gets to the concrete files by time in history} |
|
17
|
|
|
{--rollback= : Rollbacks the state to "last" or "number" as described in merge command, without preserving any further changes. With this option there is no need to define inputFile} |
|
18
|
|
|
{--no-history : Set this option if you don`t want to save history, which is saved by default} |
|
19
|
|
|
{--no-docs : To avoid generating OAS documentation for API, which is generated by default} |
|
20
|
|
|
{--tests : To generate functional/integration tests for current API}'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The console command description. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $description = 'PHP-code generator (based on OAS) for Laravel framework, with complete support of JSON-API data format |
|
28
|
|
|
------------------------------------------- |
|
29
|
|
|
By passing an input file to api:generate command you can easily generate code-base for a project, |
|
30
|
|
|
whether it will be monolithic one, or some sort of micro-services, light inner APIs, SPAs etc |
|
31
|
|
|
See more on https://github.com/RJAPI/api-generator'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Laravel handler for console commands |
|
35
|
|
|
*/ |
|
36
|
|
|
public function handle() |
|
37
|
|
|
{ |
|
38
|
|
|
try { |
|
39
|
|
|
$inputFiles = $this->argument('inputFile') ?? $this->getRollbackInputFile(); |
|
40
|
|
|
$this->actionIndex($inputFiles); |
|
41
|
|
|
} catch (\Exception $e) { |
|
42
|
|
|
$this->info($e->getMessage()); |
|
43
|
|
|
$this->error($e->getTraceAsString()); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
} |