Skip to content

gumennikov2002/apidoc-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[ENG] ApiDoc is a plugin for documenting the API.

Installation:

1st option: php artisan plugin:install Gumennikov2002.ApiDoc

2nd option: Via marketplace

Document properties:

  • title (string, required)
  • tags (string[]) / tag (string)
  • url (string, required)
  • method (string, required)
  • params (array)
  • responses (array)

Parameter properties:

  • title (string, required)
  • description (string)
  • in (string, required)
  • required (boolean, required)
  • example (mixed, required)

Response properties:

  • status_code (int, required)
  • response (array, required)

Usage example:

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...'
                                ],
                            ]
                        ]
                    ]
                ]
            ];
        });
    }

[RUS] ApiDoc - Плагин для документирования API.

Установка:

Вариант 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...'
                            ],
                        ]
                    ]
                ]
            ]
        ];
    });
}

About

API Documentation plugin for OctoberCMS

Resources

Stars

Watchers

Forks

Packages

No packages published