66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* CLI script to generate OpenAPI spec from routes
|
||
|
|
*
|
||
|
|
* Usage:
|
||
|
|
* php bin/generate-openapi.php
|
||
|
|
* php bin/generate-openapi.php --output public/docs/openapi.json
|
||
|
|
*
|
||
|
|
* Note: This script requires database connection to register routes.
|
||
|
|
* For auto-generation without DB, use OPENAPI_AUTO_GENERATE=true in .env
|
||
|
|
*/
|
||
|
|
|
||
|
|
require __DIR__ . '/../vendor/autoload.php';
|
||
|
|
|
||
|
|
use App\Bootstrap\AppBootstrap;
|
||
|
|
use App\Config\AppConfig;
|
||
|
|
use App\Modules\Auth\AuthRoutes;
|
||
|
|
use App\Modules\Health\HealthRoutes;
|
||
|
|
use App\Modules\Retribusi\Dashboard\DashboardRoutes;
|
||
|
|
use App\Modules\Retribusi\Realtime\RealtimeRoutes;
|
||
|
|
use App\Modules\Retribusi\RetribusiRoutes;
|
||
|
|
use App\Modules\Retribusi\Summary\SummaryRoutes;
|
||
|
|
use App\Support\OpenAPIGenerator;
|
||
|
|
|
||
|
|
// Load environment variables
|
||
|
|
AppConfig::loadEnv(__DIR__ . '/..');
|
||
|
|
|
||
|
|
// Parse command line arguments
|
||
|
|
$outputFile = $argv[1] ?? __DIR__ . '/../public/docs/openapi.json';
|
||
|
|
if (isset($argv[1]) && $argv[1] === '--output' && isset($argv[2])) {
|
||
|
|
$outputFile = $argv[2];
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
// Bootstrap application
|
||
|
|
$app = AppBootstrap::create();
|
||
|
|
|
||
|
|
// Register all routes (same as public/index.php)
|
||
|
|
// Note: This requires database connection
|
||
|
|
HealthRoutes::register($app);
|
||
|
|
AuthRoutes::register($app);
|
||
|
|
RetribusiRoutes::register($app);
|
||
|
|
SummaryRoutes::register($app);
|
||
|
|
DashboardRoutes::register($app);
|
||
|
|
RealtimeRoutes::register($app);
|
||
|
|
|
||
|
|
// Generate OpenAPI spec
|
||
|
|
$generator = new OpenAPIGenerator($app);
|
||
|
|
$spec = $generator->generate();
|
||
|
|
|
||
|
|
// Write to file
|
||
|
|
$json = json_encode($spec, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||
|
|
file_put_contents($outputFile, $json);
|
||
|
|
|
||
|
|
echo "✅ OpenAPI spec generated successfully!\n";
|
||
|
|
echo "📄 Output: {$outputFile}\n";
|
||
|
|
echo "📊 Total paths: " . count($spec['paths']) . "\n";
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
echo "❌ Error generating OpenAPI spec: " . $e->getMessage() . "\n";
|
||
|
|
echo "💡 Tip: Make sure database is configured in .env file\n";
|
||
|
|
exit(1);
|
||
|
|
}
|