Scramble 0.11.0 is here! Laravel Data support, schema enforcement and more
Learn more

Exporting specification

On this page
Scramble PRO
Comprehensive API documentation generation for Spatie’s Laravel Data and Laravel Query Builder.
Are you a visual learner?
Get most out of Scramble with in-depth screencasts.

You can export the resulting documentation (OpenAPI 3.1.0) using the scramble:export command:

php artisan scramble:export

This will create an api.json file containing the specification of the default API in the application’s root folder. You can customize the file path by providing the --path option. For example, to save the file in public/api.json:

php artisan scramble:export --path=public

If you have registered an API other than default, you can specify the API using the --api option:

php artisan scramble:export --api=v2

Using the exported specification for docs UI

By default, Scramble generates the specification file every time you access the documentation.

You can opt out of this behavior by creating your own documentation UI route and passing the exported specification file to it.

use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Http\Middleware\RestrictedDocsAccess;
Route::get('/documentation-api', function () {
return view('scramble::docs', [
'spec' => file_get_contents(base_path('api.json')),
'config' => Scramble::getGeneratorConfig('default'),
]);
})
->middleware(Scramble::getGeneratorConfig('default')->get('middleware', [RestrictedDocsAccess::class]));

If the file exists, this will render the documentation using the specification from that file. If the file does not exist, an error will be thrown.

Scramble PRO
Comprehensive API documentation generation for Spatie’s Laravel Data and Laravel Query Builder.