1st option:
php artisan plugin:install Gumennikov2002.ApiDoc
2nd option: Via marketplace
- title (string, required)
- tags (string[]) / tag (string)
- url (string, required)
- method (string, required)
- params (array)
- responses (array)
- title (string, required)
- description (string)
- in (string, required)
- required (boolean, required)
- example (mixed, required)
- status_code (int, required)
- response (array, required)
In your plugin in the Plugin class, in the boot method, add the Gumennikov2002\ApiDoc\Controllers\Docs controller, assign its public docs property an array containing arrays with instructions.
Code example:
public function boot(): void
{
\Gumennikov2002\ApiDoc\Controllers\Docs::extend(function (\Backend\Classes\Controller $controller) {
$controller->docs = [
[
'title' => 'Get posts',
'tag' => 'Pосты',
'url' => 'https://example.com/api/v1/posts',
'method' => 'get',
'responses' => [
[
'status_code' => 200,
'response' => [
'data' => [
[
'id' => 1,
'title' => 'First blog post!',
'description' => 'No description provided...'
],
[
'id' => 2,
'title' => 'Second blog post!',
'description' => null
]
]
]
]
]
],
[
'title' => 'Get post by ID',
'tag' => 'Posts',
'url' => 'https://example.com/api/v1/posts/{id}',
'method' => 'get',
'params' => [
[
'title' => 'id',
'description' => 'Post ID',
'in' => 'path',
'required' => true,
'example' => 1
]
],
'responses' => [
[
'status_code' => 200,
'response' => [
'data' => [
'id' => 1,
'title' => 'First blog post!',
'description' => 'No description provided...'
],
]
]
]
]
];
});
}
Вариант 1:
php artisan plugin:install Gumennikov2002.ApiDoc
Вариант 2: Через маркетплейс
- title (Заголовок, string, обязательный)
- tags (Теги, string[]) / tag (Тег, string)
- url (string, обязательный)
- method (Метод, string, обязательный)
- params (Параметры, array)
- responses (Ответы, array)
- title (Заголовок, string, обязательный)
- description (Описание, string)
- in (string, обязательный)
- required (Обязательный?, boolean, обязательный)
- example (Пример, mixed, обязательный)
- status_code (Код ответа, int, обязательный)
- response (Данные ответа, array, обязательный)
В вашем плагине в классе Plugin, в методе boot дополните контроллер Gumennikov2002\ApiDoc\Controllers\Docs, присвойте его публичному свойству docs массив содержащий массивы с инструкциями.
Пример кода:
public function boot(): void
{
\Gumennikov2002\ApiDoc\Controllers\Docs::extend(function (\Backend\Classes\Controller $controller) {
$controller->docs = [
[
'title' => 'Получить список постов',
'tag' => 'Посты',
'url' => 'https://example.com/api/v1/posts',
'method' => 'get',
'responses' => [
[
'status_code' => 200,
'response' => [
'data' => [
[
'id' => 1,
'title' => 'First blog post!',
'description' => 'No description provided...'
],
[
'id' => 2,
'title' => 'Second blog post!',
'description' => null
]
]
]
]
]
],
[
'title' => 'Получить пост по ID',
'tag' => 'Посты',
'url' => 'https://example.com/api/v1/posts/{id}',
'method' => 'get',
'params' => [
[
'title' => 'id',
'description' => 'ID поста',
'in' => 'path',
'required' => true,
'example' => 1
]
],
'responses' => [
[
'status_code' => 200,
'response' => [
'data' => [
'id' => 1,
'title' => 'First blog post!',
'description' => 'No description provided...'
],
]
]
]
]
];
});
}