ronanflavio/laradocs-generate
Composer 安装命令:
composer require ronanflavio/laradocs-generate
包简介
A package to create a simple API docs from your Laravel application
README 文档
README
Live preview
Click here to check the output result.
Installation
PHP 7.2 and Laravel 6.x or higher are required.
composer require --dev ronanflavio/laradocs-generate
After updating composer, add the service provider to the providers array in config/app.php
Ronanflavio\LaradocsGenerate\LaradocsGenerateServiceProvider::class,
Generating docs
To generate docs simply run the command:
php artisan docs:generate
This command will create the routes.json file into your resource folder. The file will be used to provide data to render the view.
You may want to ignore the routes.json file into your .gitignore.
Access your app host with /docs URI to see the docs page:
E.g.: http://127.0.0.1:8000/docs
Writing docs
Tha main goal of this package is to indicate which specifically is the URI parameters, the request body parameters and what is coming within the response.
To achieve this, you may want to write some custom PHPDocs above your controller class, actions and your DTOs' properties. Let's see some practical examples:
Typing the request and response objects
To indicate which is the URI parameter type, use the default @param annotation.
To indicate which class object must be given within the request, you must write the full qualified name of it's class within the @request annotation.
To indicate which class object will be returned, you must write the full qualified name of it's class within the @response annotation. If there is no class object to be returned, just type the the variable type (e.g.: boolean, int etc...) instead. void will be provided if there is no @response.
<?php // namespace and uses here... /** * Users management * * Here will be shown the description of * your UsersController group. If there is * no description, the class name will be * shown instead. */ class UsersController extends Controller { /** * Lists all users * @response \App\DataTransferObjects\User\ListUsersDto */ public function index() { // your code here... } /** * Returns the details about the given user * @param string $id * @response \App\DataTransferObjects\User\UserDetailsDto */ public function details(string $id) { // your code here... } /** * Creates a new user * @request \App\DataTransferObjects\User\CreateUserDto * @response \App\DataTransferObjects\User\UserDetailsDto */ public function create(CreateUserRequest $request) { // your code here... }
Typing the DTOs' attributes specifications
To indicate which is the variable type from an attribute you may use the standard @var annotation. If you want to be more specific, you can also indicate a practical example to that attribute using the @example annotation. See some code bellow:
<?php namespace App\DataTransferObjects\User; use App\DataTransferObjects\DataTransferObject; class CreateUserDto extends DataTransferObject { /** * @var string * @example email@example.local */ public $email; /** * @var string * @example John Doe */ public $name; /** * @var string * @example 123456 */ public $password; /** * @var string * @example 4c0c9e5d-f18f-4197-8531-02c90f9a81e0 */ public $role_id; }
Publishing
Publish the config file by running:
php artisan vendor:publish --provider="Ronanflavio\LaradocsGenerate\LaradocsGenerateServiceProvider" --tag=laradocs-config
This will create the docs.php file in your config directory.
You can also publish the view blade file by running:
php artisan vendor:publish --provider="Ronanflavio\LaradocsGenerate\LaradocsGenerateServiceProvider" --tag=laradocs-views
This will create the docs.blade.php file in your resource/views directory.
License
The Laradocs Generate is free software licensed under the MIT license.
ronanflavio/laradocs-generate 适用场景与选型建议
ronanflavio/laradocs-generate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「docs」 「laravel」 「generate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ronanflavio/laradocs-generate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ronanflavio/laradocs-generate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ronanflavio/laradocs-generate 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
Api documentation generator for Laravel 5
Replacement for Swagger. It is built for Laravel
A PSR-7 compatible library for making CRUD API endpoints
Laravel API documentation generating tool
The StyleCI Docs
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-01