Multiple API versions
When you have multiple APIs or multiple API versions in your project, you can create different documentation websites using Scramble.
Registering an API
By default, Scramble automatically registers default
API and uses configuration from config/scramble.php
for the API.
To enable other API documentation websites, you need to register an API in boot
method of a service provider using Scramble::registerApi
method. As a first argument it accepts the API name, and a second parameter is configuration’s overrides (it is a part of configuration that will be merged with config from config/scramble.php
).
You can also pass routes resolver function by chaining routes
method and post-OpenAPI generation hook using afterOpenApiGenerated
method.
Registering routes
After you register an API, you need to register routes for the documentation. This is done by using the Scramble::registerUiRoute
and Scramble::registerJsonSpecificationRoute
methods. These methods accept route path as a first argument and API’s name as a second argument and return Route
instance.
Scramble::registerUiRoute
registers a route (UI route) for documentation website, and Scramble::registerJsonSpecificationRoute
registers a route for documentation’s OpenAPI JSON document (API specification).
Disabling default documentation routes
By default, Scramble registers docs/api
as UI route, and docs/api.json
as API specification route for default
API (which is registered by default).
You can disable these routes by calling Scramble::ignoreDefaultRoutes
from register
method of a service provider. For example, in your App\Services\AppServiceProvider
:
This is particularly useful when you need to have only those documentation websites you registered manually.