Skip to content

Commit

Permalink
Add command to generate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sangnguyenplus committed Apr 12, 2024
1 parent f44d1ea commit 6bf2ed1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Commands/GenerateDocumentationCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Botble\Api\Commands;

use Botble\Setting\Facades\Setting;
use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand('cms:api:generate-docs', 'Generate API documentation from your API routes.')]
class GenerateDocumentationCommand extends Command
{
public function handle(): int
{
Setting::forceSet('api_enabled', true)->save();

$this->call('scribe:generate', [
'--force' => true,
]);

return self::SUCCESS;
}
}
7 changes: 7 additions & 0 deletions src/Providers/ApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Botble\Api\Providers;

use Botble\Api\Facades\ApiHelper;
use Botble\Api\Commands\GenerateDocumentationCommand;
use Botble\Api\Http\Middleware\ForceJsonResponseMiddleware;
use Botble\Api\Models\PersonalAccessToken;
use Botble\Base\Facades\PanelSectionManager;
Expand Down Expand Up @@ -71,6 +72,12 @@ public function boot(): void
->withRoute('api.settings')
);
});

if ($this->app->runningInConsole()) {
$this->commands([
GenerateDocumentationCommand::class,
]);
}
}

protected function getPath(string|null $path = null): string
Expand Down

0 comments on commit 6bf2ed1

Please sign in to comment.