You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/extending/plugins.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,7 @@
1
+
---
2
+
title: Plugins
3
+
order: 1
4
+
---
1
5
# Extending functionality with plugins
2
6
You can use plugins to alter how the Generator fetches data about your routes. For instance, suppose all your routes have a body parameter `organizationId`, and you don't want to annotate this with `@queryParam` on each method. You can create a plugin that adds this to all your body parameters. Let's see how to do this.
3
7
@@ -29,8 +33,6 @@ The `__invoke` method of the strategy is where you perform your actions and retu
29
33
Here's what your strategy in our example would look like:
30
34
31
35
```php
32
-
<?php
33
-
34
36
use Illuminate\Routing\Route;
35
37
use Mpociot\ApiDoc\Extracting\Strategies\Strategy;
Copy file name to clipboardExpand all lines: docs/getting-started/configuration.md
+54-47Lines changed: 54 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,75 +1,86 @@
1
+
---
2
+
title: Configuration
3
+
order: 2
4
+
---
1
5
# Configuration
2
6
3
-
Before you can generate your documentation, you'll need to configure a few things in your `config/apidoc.php`. If you aren't sure what an option does, it's best to leave it set to the default. If you don't have this config file, see the [installation instructions](index.html#installation).
7
+
Before you can generate your documentation, you'll need to configure a few things in your `config/apidoc.php`file.
4
8
5
-
## `type`
6
-
This is the type of documentation output to generate.
7
-
-`static` will generate a static HTMl page in the `public/docs` folder, so anyone can visit your documentation page by going to {yourapp.domain}/docs.
8
-
-`laravel` will generate the documentation as a Blade view within the `resources/views/apidoc` folder, so you can add routing and authentication.
9
+
If you aren't sure what an option does, it's best to leave it set to the default.
10
+
11
+
## type
12
+
This is the type of documentation output to generate.
13
+
14
+
`static` will generate a static HTML page in the `public/docs` folder, so anyone can visit your documentation page by going to {yourapp.domain}/docs.
15
+
16
+
`laravel` will generate the documentation as a Blade view within the `resources/views/apidoc` folder, so you can add routing and authentication to your liking.
9
17
10
18
> In both instances, the source markdown file will be generated in `resources/docs/source`.
11
19
12
-
##`laravel`
20
+
### laravel
13
21
If you're using `laravel` type output, this package can automatically set up an endpoint for you to view your generated docs. You can configure this here.
14
22
15
-
### `autoload`
16
-
Set this to `true` if you want the documentation endpoint to be automatically set up for you. Default: `false` (*note that this will change in the next major release*)
23
+
### autoload
24
+
Set this to `true` if you want the documentation endpoint to be automatically set up for you. Default: `false`
17
25
18
26
You may, of course, use your own routing instead of using `autoload`.
19
27
20
-
### `docs_url`
28
+
### docs_url
21
29
The path for the documentation endpoint (if `autoload` is true). Your Postman collection (if you have that enabled) will be at this path + '.json' (eg `/doc.json`). Default: `/doc`
22
30
23
31
> Note: There is currently a known issue with using `/docs` as the path for `laravel` docs. You should not use it, as it conflicts with the folder structure in the `public` folder and may confuse the webserver.
24
32
25
-
### `middleware`
33
+
##middleware
26
34
Here, you can specify middleware to be attached to the documentation endpoint (if `autoload` is true).
27
35
28
-
## `router`
36
+
## router
29
37
The router to use when processing your routes (can be Laravel or Dingo. Defaults to **Laravel**)
30
38
31
-
## `base_url`
39
+
## base_url
32
40
The base URL to be used in examples and the Postman collection. By default, this will be the value of config('app.url').
33
41
34
-
## `postman`
42
+
## postman
35
43
This package can automatically generate a Postman collection for your routes, along with the documentation. This section is where you can configure (or disable) that.
36
-
- For `static` docs (see [type](#type)), the collection will be created in `public/docs/collection.json`, so it can be accessed by visiting {yourapp.domain}/docs/colllection.json.
37
-
- For `laravel` docs, the collection will be generated to `storage/app/apidoc/collection.json`. The `ApiDoc::routes()` helper will add a `/docs.json` endpoint to fetch it..
38
44
39
-
### `enabled`
45
+
For `static` docs (see [type](#type)), the collection will be created in `public/docs/collection.json`, so it can be accessed by visiting {yourapp.domain}/docs/colllection.json.
46
+
47
+
For `laravel` docs, the collection will be generated to `storage/app/apidoc/collection.json`. The `ApiDoc::routes()` helper will add a `/docs.json` endpoint to fetch it..
48
+
49
+
### enabled
40
50
Whether or not to generate a Postman API collection. Default: **true**
41
51
42
-
### `name`
52
+
### name
43
53
The name for the exported Postman collection. If you leave this as null, this package will default to `config('app.name')." API"`.
44
54
45
-
### `description`
55
+
### description
46
56
The description for the generated Postman collection.
47
57
48
-
## `logo`
58
+
## logo
49
59
You can specify a custom logo to be used on the generated documentation. Set the `logo` option to an absolute path pointing to your logo file. For example:
If you want to use this, please note that the image size must be 230 x 52.
55
65
56
-
## `default_group`
57
-
When [documenting your api](documenting.md), you use `@group` annotations to group API endpoints. Endpoints which do not have a group annotation will be grouped under the `default_group`. Defaults to **"general"**.
66
+
## default_group
67
+
When [documenting your api](/docs/laravel-api-doc-generator/getting-started/documenting-your-api), you use `@group` annotations to group API endpoints. Endpoints which do not have a group annotation will be grouped under the `default_group`. Defaults to **"general"**.
58
68
59
-
## `example_languages`
60
-
For each endpoint, an example request is shown in each of the languages specified in this array. Currently only `bash`, `javascript`, `php` and `python` are supported. You can add your own language, but you must also define the corresponding view (see [Specifying languages for examples](generating-documentation.html#specifying-language-for-examples)). Default: `["bash", "javascript"]`
69
+
## example_languages
70
+
For each endpoint, an example request is shown in each of the languages specified in this array. Currently only `bash`, `javascript`, `php` and `python` are supported. You can add your own language, but you must also define the corresponding view (see [Specifying languages for examples](/docs/laravel-api-doc-generator/getting-started/generating-documentation)). Default: `["bash", "javascript"]`
61
71
62
-
## `faker_seed`
63
-
When generating example requests, this package uses fzanninoto/faker to generate random values. If you would like the package to generate the same example values for parameters on each run, set this to any number (eg. 1234). (Note: alternatively, you can set example values for parameters when [documenting them.](documenting.html#specifying-request-parameters))
72
+
## faker_seed
73
+
When generating example requests, this package uses fzanninoto/faker to generate random values. If you would like the package to generate the same example values for parameters on each run, set this to any number (eg. 1234). (Note: alternatively, you can set example values for parameters when [documenting them.](/docs/laravel-api-doc-generator/getting-started/documenting-your-api))
64
74
65
-
## `routeMatcher`
75
+
## routeMatcher
66
76
The route matcher class provides the algorithm that determines what routes should be documented. The default matcher used is the included `\Mpociot\ApiDoc\Matching\RouteMatcher::class`, and you can provide your own custom implementation if you wish to programmatically change the algorithm. The provided matcher must be an instance of the `RouteMatcherInterface`.
67
77
68
-
## `fractal`
69
-
This section only applies if you're using [Transformers]() for your API, and documenting responses with `@transformer` and `@transformerCollection`. Here, you configure how responses are transformed.
78
+
## fractal
79
+
This section only applies if you're using Transformers for your API, and documenting responses with `@transformer` and `@transformerCollection`. Here, you configure how responses are transformed.
70
80
71
81
> Note: using transformers requires league/fractal package. Run `composer require league/fractal to install
72
82
83
+
73
84
### serializer
74
85
If you are using a custom serializer with league/fractal, you can specify it here. league/fractal comes with the following serializers:
@@ -78,16 +89,14 @@ If you are using a custom serializer with league/fractal, you can specify it he
78
89
79
90
Leave this as null to use no serializer or return a simple JSON.
80
91
81
-
## `routes`
92
+
## routes
82
93
The `routes` section is an array of items, describing what routes in your application that should have documentation generated for them. Each item in the array contains rules about what routes belong in that group, and what rules to apply to them. This allows you to apply different settings to different routes.
83
94
84
95
> Note: This package does not work with Closure-based routes. If you want your route to be captured by this package, you need a controller.
85
96
86
97
Each item in the `routes` array (a route group) has keys which are explained below. We'll use this sample route definition for a Laravel app to demonstrate them:
87
98
88
99
```php
89
-
<?php
90
-
91
100
Route::group(['domain' => 'api.acme.co'], function () {
92
101
Route::get('/apps', 'AppController@listApps')
93
102
->name('apps.list');
@@ -112,14 +121,13 @@ Route::group(['domain' => 'status.acme.co'], function () {
112
121
});
113
122
```
114
123
115
-
### `match`
124
+
### match
116
125
In this section, you define the rules that will be used to determine what routes in your application fall into this group. There are three kinds of rules defined here (keys in the `match` array):
117
126
118
-
#### `domains`
127
+
###domains
119
128
This key takes an array of domain names as its value. Only routes which are defined on the domains specified here will be matched as part of this group. For instance, in our sample routes above, we may wish to apply different settings to documentation based on the domains. For instance, the routes on the `api.acme.co` domain need authentication, while those on the other domains do not. We can separate them into two groups like this:
120
129
121
130
```php
122
-
<?php
123
131
return [
124
132
//...,
125
133
@@ -146,11 +154,10 @@ The first group will match all routes on the 'api.acme.co' domain, and add a hea
146
154
147
155
You can use the `*` wildcard to match all domains (or as a placeholder in a pattern).
148
156
149
-
#### `prefixes`
157
+
###prefixes
150
158
The prefixes key is similar to the `domains` key, but is based on URL path prefixes (ie. what the part starts with, after the domain name). You could use prefixes to rewrite our example configuration above in a different way:
151
159
152
160
```php
153
-
<?php
154
161
return [
155
162
//...,
156
163
@@ -178,13 +185,12 @@ This would achieve the same as the first configuration. As with domains, the `*`
178
185
179
186
> The `domains` and `prefixes` keys are both required for all route groups.
180
187
181
-
#### `versions`
188
+
###versions
182
189
> This section only applies if you're using Dingo Router
183
190
184
191
When using Dingo's Router, all routes must be specified inside versions. This means that you must specify the versions to be matched along with the domains and prefixes when describing a route group. Note that wildcards in `versions` are not supported; you must list out all your versions explicitly. Example:
185
192
186
193
```php
187
-
<?php
188
194
return [
189
195
//...,
190
196
@@ -200,14 +206,15 @@ return [
200
206
];
201
207
```
202
208
203
-
### `include` and `exclude`
204
-
The `include` key holds an array of patterns (route names or paths) which should be included in this group, *even if they do not match the rules in the `match` section*.
205
-
The `exclude` key holds an array of patterns (route names or paths) which should be excluded from this group, *even if they match the rules in the `match` section*.
209
+
### include and exclude
210
+
211
+
The `include` key holds an array of patterns (route names or paths) which should be included in this group, *even if they do not match the rules in the match section*.
212
+
213
+
The `exclude` key holds an array of patterns (route names or paths) which should be excluded from this group, *even if they match the rules in the match section*.
206
214
207
215
Using our above sample routes, assuming you wanted to place the `users.list` route in the second group (no Authorization header), here's how you could do it:
208
216
209
217
```php
210
-
<?php
211
218
return [
212
219
//...,
213
220
@@ -235,11 +242,11 @@ return [
235
242
236
243
These values support wildcards and paths, so you can have `'exclude' => ['users/*']` to exclude all routes with URLs matching the pattern.
237
244
238
-
### `apply`
245
+
### apply
239
246
After defining the routes in `match` (and `include` or `exclude`), `apply` is where you specify the settings to be applied to those routes when generating documentation. There are a bunch of settings you can tweak here:
240
247
241
-
#### `headers`
242
-
Like we've demonstrated above, any headers you specify here will be added to the headers shown in the example requests in your documentation. They will also be included in ["response calls"](documenting.html#generating-responses-automatically). Headers are specified as key => value strings.
248
+
###headers
249
+
Like we've demonstrated above, any headers you specify here will be added to the headers shown in the example requests in your documentation. They will also be included in ["response calls"](/docs/laravel-api-doc-generator/getting-started/documenting-your-api). Headers are specified as key => value strings.
243
250
244
-
#### `response_calls`
245
-
These are the settings that will be applied when making ["response calls"](documenting.html#generating-responses-automatically). See the linked section for details.
251
+
###response_calls
252
+
These are the settings that will be applied when making ["response calls"](/docs/laravel-api-doc-generator/getting-started/documenting-your-api). See the linked section for details.
To specify a list of valid parameters your API route accepts, use the `@urlParam`, `@bodyParam` and `@queryParam` annotations.
@@ -92,12 +96,6 @@ public function listPosts()
92
96
93
97
They will be included in the generated documentation text and example requests.
94
98
95
-
**Result:**
96
-
97
-

98
-
99
-

100
-
101
99
### Example parameters
102
100
For each parameter in your request, this package will generate a random value to be used in the example requests. If you'd like to specify an example value, you can do so by adding `Example: your-example` to the end of your description. For instance:
Copy file name to clipboardExpand all lines: docs/getting-started/generating-documentation.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,13 @@
1
+
---
2
+
title: Generating Documentation
3
+
order: 5
4
+
---
1
5
# Generating Documentation
2
6
3
7
To generate your API documentation, use the `apidoc:generate` artisan command.
4
8
5
9
```sh
6
10
php artisan apidoc:generate
7
-
8
11
```
9
12
10
13
It will generate documentation using your specified configuration. The documentation will be generated as static HTML and CSS assets within the specified output folder.
0 commit comments