Installation & setup

Scramble requires:

  • PHP 8.1 or higher
  • Laravel 10.x or higher

You can install Scramble via composer:

1
composer require dedoc/scramble

When Scramble is installed, 2 routes are added to your application:

  • /docs/api - UI viewer for your documentation
  • /docs/api.json - Open API document in JSON format describing your API.

And that’s it! You can now visit /docs/api to see your API documentation.

By default, these routes are available only in local environment. You can change this behavior by defining viewApiDocs gate.

Publishing config

Optionally, you can publish the package’s config file:

1
php artisan vendor:publish --provider="Dedoc\Scramble\ScrambleServiceProvider" --tag="scramble-config"

This will allow you to customize API routes resolution and OpenAPI document’s details.

The content of scramble config:

1
<?php
2
3
use Dedoc\Scramble\Http\Middleware\RestrictedDocsAccess;
4
5
return [
6
/*
7
* Your API path. By default, all routes starting with this path will be added to the docs.
8
* If you need to change this behavior, you can add your custom routes resolver using `Scramble::routes()`.
9
*/
10
'api_path' => 'api',
11
12
/*
13
* Your API domain. By default, app domain is used. This is also a part of the default API routes
14
* matcher, so when implementing your own, make sure you use this config if needed.
15
*/
16
'api_domain' => null,
17
18
'info' => [
19
/*
20
* API version.
21
*/
22
'version' => env('API_VERSION', '0.0.1'),
23
24
/*
25
* Description rendered on the home page of the API documentation (`/docs/api`).
26
*/
27
'description' => '',
28
],
29
30
/*
31
* The list of servers of the API. By default (when `null`), server URL will be created from
32
* `scramble.api_path` and `scramble.api_domain` config variables. When providing an array, you
33
* will need to specify the local server URL manually (if needed).
34
*
35
* Example of non-default config (final URLs are generated using Laravel `url` helper):
36
*
37
* ```php
38
* 'servers' => [
39
* 'Live' => 'api',
40
* 'Prod' => 'https://scramble.dedoc.co/api',
41
* ],
42
* ```
43
*/
44
'servers' => null,
45
46
'middleware' => [
47
'web',
48
RestrictedDocsAccess::class,
49
],
50
51
'extensions' => [],
52
];
Scramble PRO
Comprehensive API documentation generation for Spatie’s Laravel Data, Laravel Query Builder, and other packages.