mako/open-api
Composer 安装命令:
composer require mako/open-api
包简介
Generate routes based on OpenAPI specifications and OpenAPI specifications from code
关键字:
README 文档
README
The mako/open-api package allows you to generate an OpenApi specification by documenting your code using PHP attributes, and to generate routes from an OpenAPI specification.
In addition, the package can render interactive API documentation for your OpenAPI specification using one of the following user interface providers:
- Elements
- Redoc
- Scalar
- Swagger (default)
Requirements
Mako 12.0 or greater.
Installation
First you'll need to install the package as a dependency to your project.
composer require mako/open-api
Next you'll need to add the package to the cli section of the packages configuration array in the application.php config file.
'cli' => [ mako\openapi\OpenApiPackage::class, ]
And finally replace the contents of your routes.php file with the following:
<?php use mako\openapi\http\routing\Registrar; Registrar::register( $routes, cachedRoutes: __DIR__ . '/openapi.php', openApiSpec: __DIR__ . '/openapi.yaml', );
Usage
You can build an OpenAPI specification using a tool such as Apicurito or by documenting your code using PHP attributes. For details on the available syntax, see the zircote/swagger-php documentation.
Here is a basic example of documenting API routes using attributes::
<?php namespace app\http\controllers; use OpenApi\Attributes as OA; #[OA\Info( title: 'Example API', version: '1.0.0' )] class OpenApiExample { #[OA\Get( path: '/', responses: [ new OA\Response(response: 200, description: 'Displays a greeting to the user.'), ] )] public function __invoke(): string { return 'Welcome to the OpenApi example!'; } }
If you want to generate a specification file from your documentation, you can do so by running the open-api:generate-spec command.
Below is an example of the generated specification:
openapi: 3.0.0 info: title: 'Example API' version: 1.0.0 paths: /: get: operationId: app\http\controllers\OpenApiExample responses: '200': description: 'Displays a greeting to the user.'
Note: If you manually write your OpenAPI specification, you must set the
operationIdparameter to the fully qualified method name (for example, app\controllers\Index::welcome) of the controller action in order for the route generator to work.
When running in production, it is strongly recommended to generate a cached route file for maximum performance. To do so, run the open-api:generate-routes command.
mako/open-api 适用场景与选型建议
mako/open-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37.13k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「mako」 「open-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mako/open-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mako/open-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mako/open-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
PHP-code generator (based on OAS) for Laravel framework, with complete support of JSON-API data format
A debug toolbar for the Mako Framework
A REPL for the Mako Framework
Mako Framework
Generates swagger documentation based on your laravel API.
统计信息
- 总下载量: 37.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2021-10-12