Skip to content

Commit be5e3b4

Browse files
committed
wip
1 parent 9015d39 commit be5e3b4

File tree

15 files changed

+137
-184
lines changed

15 files changed

+137
-184
lines changed

docs/Makefile

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
packageName: Laravel API Documentation Generator
3+
githubUrl: https://github.com/mpociot/laravel-api-doc-generator
4+
---

docs/conf.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

docs/extending/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Extending
3+
order: 2
4+
---

docs/plugins.md renamed to docs/extending/plugins.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
title: Plugins
3+
order: 1
4+
---
15
# Extending functionality with plugins
26
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.
37

@@ -29,8 +33,6 @@ The `__invoke` method of the strategy is where you perform your actions and retu
2933
Here's what your strategy in our example would look like:
3034

3135
```php
32-
<?php
33-
3436
use Illuminate\Routing\Route;
3537
use Mpociot\ApiDoc\Extracting\Strategies\Strategy;
3638

docs/getting-started/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Getting Started
3+
order: 1
4+
---

docs/config.md renamed to docs/getting-started/configuration.md

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,86 @@
1+
---
2+
title: Configuration
3+
order: 2
4+
---
15
# Configuration
26

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.
48

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.
917

1018
> In both instances, the source markdown file will be generated in `resources/docs/source`.
1119
12-
## `laravel`
20+
### laravel
1321
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.
1422

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`
1725

1826
You may, of course, use your own routing instead of using `autoload`.
1927

20-
### `docs_url`
28+
### docs_url
2129
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`
2230

2331
> 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.
2432
25-
### `middleware`
33+
## middleware
2634
Here, you can specify middleware to be attached to the documentation endpoint (if `autoload` is true).
2735

28-
## `router`
36+
## router
2937
The router to use when processing your routes (can be Laravel or Dingo. Defaults to **Laravel**)
3038

31-
## `base_url`
39+
## base_url
3240
The base URL to be used in examples and the Postman collection. By default, this will be the value of config('app.url').
3341

34-
## `postman`
42+
## postman
3543
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..
3844

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
4050
Whether or not to generate a Postman API collection. Default: **true**
4151

42-
### `name`
52+
### name
4353
The name for the exported Postman collection. If you leave this as null, this package will default to `config('app.name')." API"`.
4454

45-
### `description`
55+
### description
4656
The description for the generated Postman collection.
4757

48-
## `logo`
58+
## logo
4959
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:
5060
```
5161
'logo' => resource_path('views') . '/api/logo.png'
5262
```
5363

5464
If you want to use this, please note that the image size must be 230 x 52.
5565

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"**.
5868

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"]`
6171

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))
6474

65-
## `routeMatcher`
75+
## routeMatcher
6676
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`.
6777

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.
7080

7181
> Note: using transformers requires league/fractal package. Run `composer require league/fractal to install
7282
83+
7384
### serializer
7485
If you are using a custom serializer with league/fractal, you can specify it here. league/fractal comes with the following serializers:
7586
- \League\Fractal\Serializer\ArraySerializer::class
@@ -78,16 +89,14 @@ If you are using a custom serializer with league/fractal, you can specify it he
7889

7990
Leave this as null to use no serializer or return a simple JSON.
8091

81-
## `routes`
92+
## routes
8293
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.
8394

8495
> 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.
8596
8697
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:
8798

8899
```php
89-
<?php
90-
91100
Route::group(['domain' => 'api.acme.co'], function () {
92101
Route::get('/apps', 'AppController@listApps')
93102
->name('apps.list');
@@ -112,14 +121,13 @@ Route::group(['domain' => 'status.acme.co'], function () {
112121
});
113122
```
114123

115-
### `match`
124+
### match
116125
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):
117126

118-
#### `domains`
127+
### domains
119128
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:
120129

121130
```php
122-
<?php
123131
return [
124132
//...,
125133

@@ -146,11 +154,10 @@ The first group will match all routes on the 'api.acme.co' domain, and add a hea
146154

147155
You can use the `*` wildcard to match all domains (or as a placeholder in a pattern).
148156

149-
#### `prefixes`
157+
### prefixes
150158
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:
151159

152160
```php
153-
<?php
154161
return [
155162
//...,
156163

@@ -178,13 +185,12 @@ This would achieve the same as the first configuration. As with domains, the `*`
178185

179186
> The `domains` and `prefixes` keys are both required for all route groups.
180187
181-
#### `versions`
188+
### versions
182189
> This section only applies if you're using Dingo Router
183190
184191
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:
185192

186193
```php
187-
<?php
188194
return [
189195
//...,
190196

@@ -200,14 +206,15 @@ return [
200206
];
201207
```
202208

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*.
206214

207215
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:
208216

209217
```php
210-
<?php
211218
return [
212219
//...,
213220

@@ -235,11 +242,11 @@ return [
235242

236243
These values support wildcards and paths, so you can have `'exclude' => ['users/*']` to exclude all routes with URLs matching the pattern.
237244

238-
### `apply`
245+
### apply
239246
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:
240247

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.
243250

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.

docs/documenting.md renamed to docs/getting-started/documenting-your-api.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
title: Documenting Your API
3+
order: 4
4+
---
15
# Documenting Your API
26
This package generates documentation from your code using mainly annotations (in doc block comments).
37

@@ -45,7 +49,7 @@ class UserController extends Controller
4549

4650
**Result:**
4751

48-
![Doc block result](http://headsquaredsoftware.co.uk/images/api_generator_docblock.png)
52+
![Doc block result](/img/api_generator_docblock.png)
4953

5054
## Specifying request parameters
5155
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()
9296

9397
They will be included in the generated documentation text and example requests.
9498

95-
**Result:**
96-
97-
![](./../body_params_1.png)
98-
99-
![](./../body_params_2.png)
100-
10199
### Example parameters
102100
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:
103101

docs/generating-documentation.md renamed to docs/getting-started/generating-documentation.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
---
2+
title: Generating Documentation
3+
order: 5
4+
---
15
# Generating Documentation
26

37
To generate your API documentation, use the `apidoc:generate` artisan command.
48

59
```sh
610
php artisan apidoc:generate
7-
811
```
912

1013
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

Comments
 (0)