|
| 1 | +--- |
| 2 | +title: Setting up Scribe |
| 3 | +sidebar_position: 1 |
| 4 | +--- |
| 5 | + |
| 6 | +This package supports automatically generating API docs using [Scribe](https://github.com/knuckleswtf/scribe/). |
| 7 | +Before you can generate API docs, you need to first properly setup Scribe. |
| 8 | + |
| 9 | +## Install Scribe |
| 10 | + |
| 11 | +To get started, first install Scribe. |
| 12 | + |
| 13 | +```bash |
| 14 | +composer require knuckleswtf/scribe |
| 15 | +``` |
| 16 | + |
| 17 | +## Publish Scribe Config |
| 18 | + |
| 19 | +Then publish the Scribe config. |
| 20 | + |
| 21 | +```bash |
| 22 | +php artisan vendor:publish --tag=scribe-config |
| 23 | +``` |
| 24 | + |
| 25 | +## Add custom Sribe Strategies |
| 26 | + |
| 27 | +Now add the following Strategies provided by this package to the `scribe.php` config file. |
| 28 | + |
| 29 | +```php |
| 30 | +// in scribe.php config file |
| 31 | +'strategies' => [ |
| 32 | + 'metadata' => [ |
| 33 | + ...Defaults::METADATA_STRATEGIES, |
| 34 | + \Javaabu\QueryBuilder\Scribe\Strategies\MetadataStrategy::class, // add this to metadata strategies |
| 35 | + ], |
| 36 | + |
| 37 | + .. |
| 38 | + |
| 39 | + 'queryParameters' => [ |
| 40 | + ...Defaults::QUERY_PARAMETERS_STRATEGIES, |
| 41 | + \Javaabu\QueryBuilder\Scribe\Strategies\QueryParametersStrategy::class, // add this to query parameter strategies |
| 42 | + ], |
| 43 | +], |
| 44 | +``` |
| 45 | + |
| 46 | +## Configure Auth |
| 47 | + |
| 48 | +You would most probably need to configure auth for Scribe. Add the following recommended auth config to `scribe.php` config file. |
| 49 | + |
| 50 | +```php |
| 51 | +// How is your API authenticated? This information will be used in the displayed docs, generated examples and response calls. |
| 52 | +'auth' => [ |
| 53 | + // Set this to true if ANY endpoints in your API use authentication. |
| 54 | + 'enabled' => true, |
| 55 | + |
| 56 | + // Set this to true if your API should be authenticated by default. If so, you must also set `enabled` (above) to true. |
| 57 | + // You can then use @unauthenticated or @authenticated on individual endpoints to change their status from the default. |
| 58 | + 'default' => true, |
| 59 | + |
| 60 | + // Where is the auth value meant to be sent in a request? |
| 61 | + 'in' => AuthIn::BEARER->value, |
| 62 | + |
| 63 | + // The name of the auth parameter (e.g. token, key, apiKey) or header (e.g. Authorization, Api-Key). |
| 64 | + 'name' => 'Authorization', |
| 65 | + |
| 66 | + // Generate an access token / API key and add to the .env file |
| 67 | + 'use_value' => env('SCRIBE_AUTH_KEY'), |
| 68 | + |
| 69 | + // Placeholder your users will see for the auth parameter in the example requests. |
| 70 | + // Set this to null if you want Scribe to use a random value as placeholder instead. |
| 71 | + 'placeholder' => '{OAUTH_ACCESS_TOKEN}', |
| 72 | + |
| 73 | + // Add instructions on how to get the access token |
| 74 | + 'extra_info' => 'You can retrieve your access token by visiting your profile in the dashboard and clicking <b>New API Token</b>. '. |
| 75 | + 'Only users that have the "Generate Personal Access Token" permission will be able to generate new access tokens.', |
| 76 | +], |
| 77 | +``` |
| 78 | + |
| 79 | +Then add the access token to the `.env` file for Scribe to use. |
| 80 | + |
| 81 | +```dotenv |
| 82 | +SCRIBE_AUTH_KEY=your-access-token |
| 83 | +``` |
| 84 | + |
| 85 | +## Generate API Docs |
| 86 | + |
| 87 | +That's it! Now when you just need to run. |
| 88 | + |
| 89 | +```bash |
| 90 | +php artisan scribe:generate |
| 91 | +``` |
| 92 | + |
| 93 | +And your API docs will be magically created with sensible documentation. |
| 94 | + |
| 95 | + |
0 commit comments