Skip to content

Commit 290c1f0

Browse files
docs: update documentation package docs
API-513
1 parent bd337ed commit 290c1f0

File tree

2 files changed

+126
-258
lines changed

2 files changed

+126
-258
lines changed

docs/pacakges/documentation.md

+63-129
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,51 @@
11
---
22
sidebar_position: 1
33
title: Documentation
4+
tags:
5+
- package
46
---
57

6-
Every great API needs a great Documentation.
7-
8-
Apiato make writing and generating documentations very easy with the `php artisan apiato:apidoc` command.
8+
:::info
9+
This package is installed by default with an Apiato fresh installation.
10+
:::
911

10-
## Requirements {#requirements}
12+
The Documentation Generator Container is a package that generates API documentation for your API Endpoints.
13+
It uses [ApiDocJs](https://apidocjs.com/) to generate the documentation.
1114

12-
- Install [ApiDocJs](https://apidocjs.com/) in the project directory
13-
- (`npm install apidoc`)
15+
It is recommended
16+
to read about the `Public` and `Private` [routes](../components/main-components/routes.md#public--private-routes)
17+
before using this package.
1418

15-
- (Recommended) read the [Routes](../components/main-components/routes.md) page first.
19+
## Requirements
1620

17-
## Installation {#installation}
21+
This package depends on [ApiDocJs](https://apidocjs.com/).
22+
Make sure to install it in the project directory by running:
1823

24+
```shell
25+
npm install apidoc
1926
```
27+
28+
## Installation
29+
30+
```shell
2031
composer require apiato/documentation-generator-container
2132
```
2233

23-
:::tip
24-
This container is installed by default with an Apiato fresh installation.
25-
:::
34+
## Publishing Configs
35+
```shell
36+
php artisan vendor:publish
37+
```
38+
Config file will be placed at `app/Ship/Configs/vendor-documentation.php`
2639

27-
## Usage {#usage}
40+
## Usage
2841

29-
### Write PHP **docblock** {#write-php-docblock}
42+
### Write the DocBlocks
3043

31-
Write a PHP **docblock** on top of your endpoint like this:
44+
Write the `DocBlocks` for your API Endpoints in your Route files.
3245

33-
*For more info about the parameters check out [ApiDocJs](https://apidocjs.com/#install) documentation*
46+
:::info
47+
For more info about the parameters check out [ApiDocJs](https://apidocjs.com/#install) documentation.
48+
:::
3449

3550
```php
3651
/**
@@ -53,13 +68,11 @@ Write a PHP **docblock** on top of your endpoint like this:
5368
* "id": "XbPW7awNkzl83LD6",
5469
* "name": "Super Admin",
5570
* "email": "[email protected]"
56-
* ...
5771
* }
5872
*
5973
* @apiErrorExample {json} Error-Response:
6074
* {
6175
* "message":"401 Credentials Incorrect.",
62-
* "status_code":401
6376
* }
6477
*
6578
* @apiErrorExample {json} Error-Response:
@@ -70,7 +83,6 @@ Write a PHP **docblock** on top of your endpoint like this:
7083
* "The email field is required."
7184
* ]
7285
* },
73-
* "status_code":422
7486
* }
7587
*/
7688

@@ -84,142 +96,64 @@ Route::post('clients/web/login', Controller::class);
8496
All the Endpoint `DocBlocks` MUST be written inside Routes files, otherwise they won't be loaded.
8597
:::
8698

87-
### Run Documentation Generator {#run-documentation-generator}
99+
### Generate the Documentation
88100

89-
Run the documentation generator command from the root directory:
90-
91-
```
101+
You can generate the API documentation by running the following command:
92102

103+
```shell
93104
php artisan apiato:apidoc
94-
95105
```
96106

97-
#### Error: ApiDoc not found !!
98-
99-
If you get an error (`apidoc not found`),
107+
:::info Error: ApiDoc not found
108+
If you get the `apidoc not found` error,
109+
you need to update the `executable` path in the `vendor-documentation.php` config file.
100110

101111
1. [Publish the configs](#publishing-configs)
102-
103112
2. Edit the `executable` path to **`$(npm bin)/apidoc`** or to however you access the `apidoc` tool on your machine.
104113

105114
```php
106-
/*
107-
|--------------------------------------------------------------------------
108-
| Executable
109-
|--------------------------------------------------------------------------
110-
|
111-
| Specify how you run or access the `apidoc` tool on your machine.
112-
|
113-
*/
114-
115-
'executable' => 'node_modules/.bin/apidoc',
116-
// 'executable' => 'apidoc',
115+
/*
116+
|--------------------------------------------------------------------------
117+
| Executable
118+
|--------------------------------------------------------------------------
119+
|
120+
| Specify how you run or access the `apidoc` tool on your machine.
121+
|
122+
*/
123+
124+
'executable' => 'node_modules/.bin/apidoc',
125+
// 'executable' => 'apidoc',
117126
```
127+
:::
118128

119-
### Visit Documentation URL's {#visit-docs-urls}
129+
### Visit Documentation URL's
120130

121-
Visit documentation URL's as shown in your terminal:
131+
Visit the documentation URLs as shown in your terminal:
122132

123133
- Public (external) API at [http://apiato.test/docs](http://apiato.test/docs).
124134
- Private (internal) API at [http://apiato.test/docs/private](http://apiato.test/docs/private).
125135

126-
:::note
127-
Every time you change the DocBlock of a Route file you need to run the `apiato:apidoc` command, to regenerate.
136+
:::tip
137+
Don't forget to regenerate the documentation after making changes to the `DocBlocks`.
128138
:::
129139

130-
### Shared Response {#shared-response}
131-
132-
You can use shared responses to update the documentation faster, with less outdated responses and prevent duplicating the responses between routes.
133-
134-
Example: `_user.v1.public.php` will contain all responses (single, multiple...) of the User:
135-
136-
```php
137-
/**
138-
* @apiDefine UserSuccessSingleResponse
139-
* @apiSuccessExample {json} Success-Response:
140-
HTTP/1.1 200 OK
141-
{
142-
"data":{
143-
"object":"User",
144-
"id":eqwja3vw94kzmxr0,
145-
},
146-
"meta":{
147-
"include":[],
148-
"custom":[]
149-
}
150-
}
151-
*/
152-
```
153-
154-
**Usage of the shared User response from any endpoint:**
155-
156-
```php
157-
* @apiUse UserSuccessSingleResponse
158-
```
159-
160-
## Documentation Container Customization {#documentation-customization}
161-
162-
There are 2 ways you can customize this container: Using its configs or by modifying the source code.
163-
164-
### Publishing configs
165-
```
166-
php artisan vendor:publish
167-
```
168-
Config file will be copied to `app/Ship/Configs/vendor-documentation.php`
169-
170-
### Modifying the source code {#modify-code}
171-
172-
1. Copy the container from `Vendor` to `AppSection` (or any of your custom sections) of your project
173-
2. Fix the namespaces
174-
3. Remove `apiato/documentation-generator-container` dependency from project root composer.json
175-
4. Update `section_name` & `html_files` in container configs
176-
5. Update `apidoc.private.json` & `apidoc.public.json` files in `ApiDocJs/Configs` and fix the `filename`
177-
178-
```json
179-
{
180-
"header": {
181-
"filename": "Containers/NEW_SECTION_NAME/Documentation/UI/WEB/Views/documentation/header.md"
182-
}
183-
}
184-
```
185-
186-
### Change the Documentations URL's {#change-the-documentations-urls}
187-
[Publish the configs](#publishing-configs) and change `types.public.url` & `types.private.url`.
188-
189-
### Private Documentation Protection {#private-docs-protection}
140+
## Private Documentation Protection
190141
By default, this feature is **disabled** in local environment and **enabled** in production.
191-
To change this behaviour [Publish the configs](#publishing-configs) and change `protect-private-docs`.
142+
To change this behavior, [Publish the configs](#publishing-configs) and change `protect-private-docs`.
192143

193144
Private documentations route is protected with the `auth:web` middleware.
194-
You can grant users access to the protected docs by updating `access-private-docs-roles` &
145+
You can grant users access to the protected docs by updating `access-private-docs-roles` and
195146
`access-private-docs-permission` values in documentation config.
196147
By default, users need `access-private-docs` permission to access private docs.
197148

198-
### Edit Default Generated Values in Templates {#edit-default-generated-values-in-templates}
149+
## Documentation Header Localization
199150

200-
Apiato by defaults generates 2 API documentations, each one has its own `apidoc.json` file. Both can be modified from
201-
the Documentation Container in `app/Containers/Vendor/Documentation/ApiDocJs` and need Source code modification.
151+
The documentation header is in English `en` by default.
152+
To see the documentation header in another language, you can change the locale in the `.env` file.
202153

203-
### Edit the Documentation Header {#edit-the-documentation-header}
204-
205-
The header is usually the Overview of your API. It contains Info about authenticating users, making requests, responses, potential errors, rate limiting, pagination, query parameters and anything you want.
206-
207-
All this information is written in `app/Containers/Vendor/Documentation/ApiDocJs/shared/header.template.en.md` file, and the same file is used as header for both private and public documentations.
208-
209-
To edit its content you need to modify its source code and open the markdown file in any markdown editor and edit it.
210-
211-
You will notice some variables like `{{rate-limit}}` and `{{token-expires}}`. Those are replaced when running `apiato:apidoc` with real values from your application configuration files.
212-
213-
Feel free to extend them to include more info about your API from the `app/Containers/Vendor/Documentation/Tasks/RenderTemplatesTask.php` class.
214-
215-
### Localization for Documentation Header {#localization-for-documentation-header}
216-
217-
Default, the documentation title is in English `en` localization.
218-
219-
See which locales are supported by going in `app/Containers/Vendor/Documentation/ApiDocJs/shared`
220-
221-
There will be some `header.template.{locale}.md` files in the folder.
222-
223-
You can change the language by adding `APIDOC_LOCALE=ru` to the `.env` file.
154+
```shell
155+
APIDOC_LOCALE=ru
156+
```
224157

225-
If you didn't find a file with your locale, you can create it. You need to modify its source code and create new file like `header.template.cn.md`
158+
To see the list of supported locales, check the `app/Containers/Vendor/Documentation/ApiDocJs/shared` folder.
159+
If you want to add a new language, you can create a new file in the `shared` folder and submit a PR.

0 commit comments

Comments
 (0)