Skip to content

Commit 2fdc361

Browse files
committed
- Added docs on installing scribe
1 parent 948fe63 commit 2fdc361

File tree

7 files changed

+157
-4
lines changed

7 files changed

+157
-4
lines changed

docs/about-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: About Us
3-
sidebar_position: 1.7
3+
sidebar_position: 1.10
44
---
55

66
[Javaabu](https://javaabu.com) is a web design agency based in the Maldives.

docs/advanced-usage/_category_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"position": 1.5,
2+
"position": 1.7,
33
"label": "Advanced Usage",
44
"collapsible": true,
55
"collapsed": false,

docs/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Changelog
3-
sidebar_position: 1.6
3+
sidebar_position: 1.9
44
---
55

66
All notable changes to this package are documented on [GitHub](https://github.com/Javaabu/query-builder/blob/main/CHANGELOG.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"position": 1.6,
3+
"label": "Generating API Docs",
4+
"collapsible": true,
5+
"collapsed": false,
6+
"link": {
7+
"type": "generated-index",
8+
"slug": "/query-builder/_categories/generating-api-docs",
9+
"description": "How to automatically generate API docs"
10+
}
11+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Customizing API Docs Metadata
3+
sidebar_position: 2
4+
---
5+
6+
This package will try to automatically generate documentation for the sorts, fields, appends, includes, and filters you have defined for your API controllers.
7+
The package uses the class name to determine the resource name and the resource group. You can see the relevant methods in `Javaabu\QueryBuilder\Concerns\ApiDocHelpers` trait.
8+
9+
While the automatically generated documentation might be sufficient for most use cases, we recommend you to override some of the methods to provide more contextual documentation to developers.
10+
11+
Here are some of the methods we recommend to override.
12+
13+
## apiDocFilterMetadata()
14+
15+
Use this method to describe what each filter does. Will support all properties allowed by `Knuckles\Scribe\Attributes\QueryParam` Attribute.
16+
17+
```php
18+
// in ProductsController.php
19+
public static function apiDocFilterMetadata(): array
20+
{
21+
return [
22+
'id' => [
23+
'type' => 'integer',
24+
],
25+
26+
'search' => [
27+
'type' => 'string',
28+
'description' => 'Search products by name.',
29+
]
30+
];
31+
}
32+
```
33+
34+
35+
## apiDocGroupDescription()
36+
37+
Use this method to describe what your resource is.
38+
39+
```php
40+
// in ProductsController.php
41+
public static function apiDocGroupDescription(): string
42+
{
43+
return 'Endpoints for listing and viewing products'.;
44+
}
45+
```
46+
47+
Apart from these methods, you can still use Sribe docblocks, Attributes and `inheritedDocsOverrides` to fully customize the documentation.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+

docs/questions-and-security.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Questions and Security
3-
sidebar_position: 1.5
3+
sidebar_position: 1.8
44
---
55

66
Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving this package? Feel free to create an [issue](../../issues) on GitHub, we'll try to address it as soon as possible.

0 commit comments

Comments
 (0)