scalar / laravel
Render your OpenAPI-based API reference
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
README
Use your OpenAPI documents to render modern API references in Laravel
Installation
You can install the package via composer:
composer require scalar/laravel
You can publish the config file with:
php artisan vendor:publish --tag="scalar-config"
Optionally, you can publish the views using
php artisan vendor:publish --tag="scalar-views"
Usage
You’ll need an OpenAPI/Swagger document to render your API reference with Scalar. Here are some packages that help generating those documents:
Once done, you can pass it to Scalar. Just make sure it’s a publicly accessible URL.
<?php // config/scalar.php return [ // … 'url' => '/openapi.yaml', // … ]
Authorization
The Scalar API reference may be accessed via the /scalar route. By default, everyone will be able to access this route. However, within your App\Providers\AppServiceProvider.php file, you can overwrite the gate definition. This authorization gate controls access to Scalar in non-local environments. You are free to modify this gate as needed to restrict access to your Horizon installation:
<?php namespace App\Providers; use Illuminate\Support\Facades\Gate; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function boot(): void { Gate::define('viewScalar', function ($user) { return in_array($user->email, [ // ]); }); } }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome.
Credits
License
The MIT License (MIT). Please see License File for more information.