From 871e93a38c5d21d03571e3dfeb965729ae6bb9d2 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sat, 11 May 2024 17:38:44 -0400 Subject: [PATCH] Add scramble api docs --- app/Providers/RouteServiceProvider.php | 4 + composer.json | 1 + composer.lock | 172 +++++++++++++----- .../views/vendor/scramble/docs.blade.php | 20 ++ routes/docs.php | 51 ++++++ 5 files changed, 199 insertions(+), 49 deletions(-) create mode 100644 resources/views/vendor/scramble/docs.blade.php create mode 100644 routes/docs.php diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 73330b3c0..03e4c0b68 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -36,6 +36,10 @@ class RouteServiceProvider extends ServiceProvider $this->routes(function () { Route::middleware('web')->group(function () { + Route::middleware(['auth.session', RequireTwoFactorAuthentication::class]) + ->prefix('docs') + ->group(base_path('routes/docs.php')); + Route::middleware(['auth.session', RequireTwoFactorAuthentication::class]) ->group(base_path('routes/base.php')); diff --git a/composer.json b/composer.json index 544715fc1..eb0497e09 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "abdelhamiderrahmouni/filament-monaco-editor": "^0.2.0", "aws/aws-sdk-php": "~3.288.1", "chillerlan/php-qrcode": "^5.0", + "dedoc/scramble": "^0.9.0", "doctrine/dbal": "~3.6.0", "filament/filament": "^3.2", "guzzlehttp/guzzle": "^7.5", diff --git a/composer.lock b/composer.lock index 2c13d13dc..1934a37d5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d56ab7da7dfcd2fe28a500ccac69fca5", + "content-hash": "5b1de0c6d4c6fc9fbcd5d36196ce3d5f", "packages": [ { "name": "abdelhamiderrahmouni/filament-monaco-editor", @@ -843,6 +843,80 @@ ], "time": "2024-01-21T14:53:34+00:00" }, + { + "name": "dedoc/scramble", + "version": "v0.9.0", + "source": { + "type": "git", + "url": "https://github.com/dedoc/scramble.git", + "reference": "6280da6809eecaa03243d726b957cc174b1ccb70" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dedoc/scramble/zipball/6280da6809eecaa03243d726b957cc174b1ccb70", + "reference": "6280da6809eecaa03243d726b957cc174b1ccb70", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^10.0|^11.0", + "nikic/php-parser": "^5.0", + "php": "^8.1", + "phpstan/phpdoc-parser": "^1.0", + "spatie/laravel-package-tools": "^1.9.2" + }, + "require-dev": { + "laravel/pint": "^v1.1.0", + "nunomaduro/collision": "^7.0|^8.0", + "orchestra/testbench": "^8.0|^9.0", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-laravel": "^2.3", + "phpunit/phpunit": "^10.5", + "spatie/pest-plugin-snapshots": "^2.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Dedoc\\Scramble\\ScrambleServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Dedoc\\Scramble\\": "src", + "Dedoc\\Scramble\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Lytvynenko", + "email": "litvinenko95@gmail.com", + "role": "Developer" + } + ], + "description": "Automatic generation of API documentation for Laravel applications.", + "homepage": "https://github.com/dedoc/scramble", + "keywords": [ + "documentation", + "laravel", + "openapi" + ], + "support": { + "issues": "https://github.com/dedoc/scramble/issues", + "source": "https://github.com/dedoc/scramble/tree/v0.9.0" + }, + "funding": [ + { + "url": "https://github.com/romalytvynenko", + "type": "github" + } + ], + "time": "2024-03-11T19:27:28+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.2", @@ -5400,6 +5474,53 @@ ], "time": "2024-03-03T02:14:58+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.28.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", + "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.28.0" + }, + "time": "2024-04-03T18:51:33+00:00" + }, { "name": "pragmarx/google2fa", "version": "v8.0.1", @@ -11163,53 +11284,6 @@ ], "time": "2024-01-20T20:34:02+00:00" }, - { - "name": "phpstan/phpdoc-parser", - "version": "1.28.0", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", - "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "require-dev": { - "doctrine/annotations": "^2.0", - "nikic/php-parser": "^4.15", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.5", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^9.5", - "symfony/process": "^5.2" - }, - "type": "library", - "autoload": { - "psr-4": { - "PHPStan\\PhpDocParser\\": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPDoc parser with support for nullable, intersection and generic types", - "support": { - "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.28.0" - }, - "time": "2024-04-03T18:51:33+00:00" - }, { "name": "phpstan/phpstan", "version": "1.10.67", @@ -12969,7 +13043,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.2", + "php": "^8.2 || ^8.3", "ext-intl": "*", "ext-json": "*", "ext-mbstring": "*", diff --git a/resources/views/vendor/scramble/docs.blade.php b/resources/views/vendor/scramble/docs.blade.php new file mode 100644 index 000000000..98498c2e9 --- /dev/null +++ b/resources/views/vendor/scramble/docs.blade.php @@ -0,0 +1,20 @@ + + + + + + Pelican - {{ str($api ?? 'all')->title() }} API Docs + + + + + + + + diff --git a/routes/docs.php b/routes/docs.php new file mode 100644 index 000000000..9348483ed --- /dev/null +++ b/routes/docs.php @@ -0,0 +1,51 @@ + 'api'], function () { + Scramble::extendOpenApi(fn (OpenApi $openApi) => $openApi->secure(SecurityScheme::http('bearer'))); + + Route::view('application', 'scramble::docs', ['api' => 'application'])->name('scramble.docs.api.application'); + Route::view('client', 'scramble::docs', ['api' => 'client'])->name('scramble.docs.api.client'); + Route::view('remote', 'scramble::docs', ['api' => 'remote'])->name('scramble.docs.api.remote'); + + Route::get('application.json', function (Dedoc\Scramble\Generator $generator) { + config()->set('scramble.api_path', 'api/application'); + config()->set('scramble.info.description', ' + These are the Application API endpoints for admins. + They let you interact with your Panel on a root basis. + '); + + return $generator(); + })->name('scramble.docs.application'); + + Route::get('client.json', function (Dedoc\Scramble\Generator $generator) { + config()->set('scramble.api_path', 'api/client'); + config()->set('scramble.info.description', ' + These are the Client API endpoints for individual users. + They let your users interact with your Panel. + '); + + return $generator(); + })->name('scramble.docs.client'); + + Route::get('remote.json', function (Dedoc\Scramble\Generator $generator) { + config()->set('scramble.api_path', 'api/remote'); + config()->set('scramble.info.description', ' + These are the Remote API endpoints for Wings. + They let Wings interact with your Panel. + '); + + return $generator(); + })->name('scramble.docs.remote'); + + Route::get('', fn () => ' +
  • Application API for Admins
  • +
  • Client API for Users
  • +
  • Daemon API for Wings
  • + '); +})->middleware(config('scramble.middleware', [RestrictedDocsAccess::class]));