Skip to content

Commit

Permalink
change command apiato:docs to apiato:apidoc and add apiato:swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoudz committed Apr 30, 2020
1 parent 0157d63 commit b94608b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
Expand Up @@ -22,7 +22,7 @@
|
*/

'swagger-converter' => '$(npm bin)/apidoc-swagger',
'swagger-converter' => 'node_modules/.bin/apidoc-swagger',

/*
|--------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions app/Containers/Documentation/Tasks/GenerateAPIDocsTask.php
Expand Up @@ -31,7 +31,7 @@ public function run($type, $console)

$command = [
$this->getExecutable(),
# executable parameters
// executable parameters
"-c",
$this->getJsonFilePath($type) . ' ' . $this->getEndpointFiles($type),
"-i",
Expand All @@ -46,12 +46,13 @@ public function run($type, $console)
$process->run();

if (!$process->isSuccessful()) {
$console->error('Error Output: ' . $process->getOutput());
throw new ProcessFailedException($process);
}

// echo the output
$console->info('[' . $type . '] ' . implode (' ', $command));
$console->info('Result: ' . $process->getOutput());
$console->info('Output: ' . $process->getOutput());

// return the past to that generated documentation
return $this->getFullApiUrl($type);
Expand Down
31 changes: 21 additions & 10 deletions app/Containers/Documentation/Tasks/GenerateSwaggerTask.php
Expand Up @@ -27,30 +27,41 @@ class GenerateSwaggerTask extends Task
*/
public function run($type, $console)
{
$path = $this->getDocumentationPath($type);

$exe = $this->getSwaggerConverter();

$app_path = './app';
// little hack to move the apidoc.json file to the /app directory in order to be seen by apidoc-swagger
// since the command doesn't support passing custom path.
$app_path = 'app';
$apidoc_json = '/apidoc.json';
copy($this->getJsonFilePath($type).$apidoc_json, $app_path.$apidoc_json);
copy($this->getJsonFilePath($type) . $apidoc_json, $app_path . $apidoc_json);

$command = $exe . ' ' . "-v -f '.*\.php$' -i {$app_path} -o {$path}/swagger";
$command = [
$this->getSwaggerConverter(),
// executable parameters
"-v",
"",
"-f",
"'.*\.php$'",
"-i",
$app_path,
"-o",
"{$this->getDocumentationPath($type)}/swagger"
];

$process = new Process($command);

// execute the command
$process->run();

unlink($app_path.$apidoc_json);
// delete the apidoc.json file after executing the command since it's no longer needed.
unlink($app_path . $apidoc_json);

if (!$process->isSuccessful()) {
$console->error('Error Output: ' . $process->getOutput());
throw new ProcessFailedException($process);
}

// echo the output
$console->info('[' . $type . '] ' . $command);
$console->info('Result: ' . $process->getOutput());
$console->info('[' . $type . '] ' . implode (' ', $command));
$console->info('Output: ' . $process->getOutput());

// return the past to that generated documentation
return $this->getFullApiUrl($type).'/swagger/swagger.json';
Expand Down
Expand Up @@ -19,14 +19,14 @@ class GenerateApiDocsCommand extends ConsoleCommand
*
* @var string
*/
protected $signature = "apiato:docs";
protected $signature = "apiato:apidoc";

/**
* The console command description.
*
* @var string
*/
protected $description = "Generate API Documentations (using API-Doc-JS)";
protected $description = "Generate API Documentations with (API-Doc-JS)";

/**
* Create a new command instance.
Expand Down
Expand Up @@ -7,7 +7,7 @@
use App\Ship\Transporters\DataTransporter;

/**
* Class GenerateApiDocsCommand
* Class GenerateSwaggerCommand
*
* @author Mahmoud Zalt <mahmoud@zalt.me>
*/
Expand All @@ -26,7 +26,7 @@ class GenerateSwaggerCommand extends ConsoleCommand
*
* @var string
*/
protected $description = "Generate Swagger/OpenAPI JSON schema from apiDoc";
protected $description = "Generate API Documentations with (Swagger from API-Doc-JS)";

/**
* Create a new command instance.
Expand Down

0 comments on commit b94608b

Please sign in to comment.