icodestuff/ladocumenter
Composer 安装命令:
composer require icodestuff/ladocumenter
包简介
Automatically generate beautiful API documentation for your Laravel API routes using annotations.
README 文档
README
Automatically generate beautiful API documentation for your Laravel API routes using annotations.
Installation
PHP 7.4 and Laravel 7 or higher are required.
Installing
You will need LaRecipe to serve your autogenerated markdown
run
composer require --dev binarytorch/larecipe && composer require --dev icodestuff/ladocumenter
to download both LaRecipe and LaDocumenter as a dev dependency
Then
php artisan larecipe:install to install Larecipe
And lastly publish the config
php artisan vendor:publish --provider="Icodestuff\LaDocumenter\LaDocumenterServiceProvider"
Demo Video
Here is a YouTube video showcasing the LaDocumenter package
Getting Started
The only endpoints that are documented are the ones in your api.php file.
Generating Documentation
In order to compile your annotations to markdown you will need to run:
php artisan ladocumenter:generate
Grouping Endpoints
All endpoints are grouped for easy organization. Only use @Group to group endpoints in a single controller class by adding
it to the top of the controller like so:
Example
/** * @Group(name="Foo", description="This is an example group.") */ class FooController extends Controller { }
Attributes
- Name (required)
- Description (optional)
Documenting Endpoints
The @Endpoint annotation is used for a single controller method or endpoint. Note, at this time we don't support
closures or resources 😕
Example
class FooController extends Controller { /** * @Endpoint(name="Example", description="This is an example endpoint.") */ public function bar() { } }
Attributes
- Name (required)
- Description (optional)
Specifying Request Parameters
To specify a list of valid parameters your API route accepts, use the @QueryParam or @BodyParam.
Both the @BodyParam & @QueryParam annotation takes the name, type, required, description and an example.
@BodyParam Example
class FooController extends Controller { /** * @BodyParam(name="foo", type="string", status="required", description="An example body paramater", example="bar") */ public function bar(FormRequest $request) { } }
@QueryParam Example
class FooController extends Controller { /** * @QueryParam(name="foo", type="string", status="optional", description="An example query paramater", example="bar") */ public function bar() { } }
Attributes
- Name (required)
- Type (required)
- IsRequired (required)
- Description (optional)
- Example (optional)
Generating Responses
To generate a response, you must use the @ResponseExample annotation. This takes in the status of the response
as well as a link to the response file like so:
class FooController extends Controller { /** * @ResponseExample(status=200, file="responses/example.json") */ public function bar() { return response()->json(['foo' => 'bar']); } }
Attributes
- Status (required)
- Example (required)
Be sure to add your responses to the storage directory as that is where LaDocumenter looks for them. We recommend automatically generating responses using Laravel's testing suite.
Indicating Authentication Status
LaDocumenter automatically labels an endpoint as authenticated if the route uses the middleware defined in the config/ladocumenter.php file:
'auth_middleware' => [
'auth:sanctum',
'auth'
],
If you are using a separate auth middleware, be sure to define it in the config file.
icodestuff/ladocumenter 适用场景与选型建议
icodestuff/ladocumenter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 795 次下载、GitHub Stars 达 11, 最近一次更新时间为 2020 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「documentation」 「swagger」 「apidoc」 「openapi」 「documenter」 「laravel-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 icodestuff/ladocumenter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 icodestuff/ladocumenter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 icodestuff/ladocumenter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
Laravel package that generates RESTful API documentation in Markdown based on PHPDoc.
Laravel API documentation generating tool
Swagger integration to Laravel 5
Easy Swagger endpoint using the Zend Expressive routes config
一个接口文档生成器
统计信息
- 总下载量: 795
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-20
