Add scramble api docs

This commit is contained in:
Lance Pioch 2024-05-11 17:38:44 -04:00
parent 585fe8d1a1
commit 871e93a38c
5 changed files with 199 additions and 49 deletions

View File

@ -36,6 +36,10 @@ class RouteServiceProvider extends ServiceProvider
$this->routes(function () { $this->routes(function () {
Route::middleware('web')->group(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]) Route::middleware(['auth.session', RequireTwoFactorAuthentication::class])
->group(base_path('routes/base.php')); ->group(base_path('routes/base.php'));

View File

@ -12,6 +12,7 @@
"abdelhamiderrahmouni/filament-monaco-editor": "^0.2.0", "abdelhamiderrahmouni/filament-monaco-editor": "^0.2.0",
"aws/aws-sdk-php": "~3.288.1", "aws/aws-sdk-php": "~3.288.1",
"chillerlan/php-qrcode": "^5.0", "chillerlan/php-qrcode": "^5.0",
"dedoc/scramble": "^0.9.0",
"doctrine/dbal": "~3.6.0", "doctrine/dbal": "~3.6.0",
"filament/filament": "^3.2", "filament/filament": "^3.2",
"guzzlehttp/guzzle": "^7.5", "guzzlehttp/guzzle": "^7.5",

172
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "d56ab7da7dfcd2fe28a500ccac69fca5", "content-hash": "5b1de0c6d4c6fc9fbcd5d36196ce3d5f",
"packages": [ "packages": [
{ {
"name": "abdelhamiderrahmouni/filament-monaco-editor", "name": "abdelhamiderrahmouni/filament-monaco-editor",
@ -843,6 +843,80 @@
], ],
"time": "2024-01-21T14:53:34+00:00" "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", "name": "dflydev/dot-access-data",
"version": "v3.0.2", "version": "v3.0.2",
@ -5400,6 +5474,53 @@
], ],
"time": "2024-03-03T02:14:58+00:00" "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", "name": "pragmarx/google2fa",
"version": "v8.0.1", "version": "v8.0.1",
@ -11163,53 +11284,6 @@
], ],
"time": "2024-01-20T20:34:02+00:00" "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", "name": "phpstan/phpstan",
"version": "1.10.67", "version": "1.10.67",
@ -12969,7 +13043,7 @@
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": "^8.2", "php": "^8.2 || ^8.3",
"ext-intl": "*", "ext-intl": "*",
"ext-json": "*", "ext-json": "*",
"ext-mbstring": "*", "ext-mbstring": "*",

View File

@ -0,0 +1,20 @@
<!doctype html>
<html lang="en" data-theme="{{ config('scramble.theme', 'dark') }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Pelican - {{ str($api ?? 'all')->title() }} API Docs</title>
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css">
</head>
<body style="height: 100vh; overflow-y: hidden">
<elements-api
apiDescriptionUrl="{{ route('scramble.docs.' . $api ?? 'all') }}"
tryItCredentialsPolicy="{{ config('scramble.ui.try_it_credentials_policy', 'include') }}"
router="hash"
@if(config('scramble.ui.hide_try_it')) hideTryIt="true" @endif
logo="/pelican.svg"
/>
</body>
</html>

51
routes/docs.php Normal file
View File

@ -0,0 +1,51 @@
<?php
use Dedoc\Scramble\Http\Middleware\RestrictedDocsAccess;
use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi;
use Dedoc\Scramble\Support\Generator\SecurityScheme;
use Illuminate\Support\Facades\Route;
Route::group(['prefix' => '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 () => '
<li><a href="/docs/api/application">Application API for Admins</a></li>
<li><a href="/docs/api/client">Client API for Users</a></li>
<li><a href="/docs/api/remote">Daemon API for Wings</a></li>
');
})->middleware(config('scramble.middleware', [RestrictedDocsAccess::class]));