beauty-framework/openapi-support
Composer 安装命令:
composer require beauty-framework/openapi-support
包简介
Beauty OpenAPI Support
README 文档
README
Modern OpenAPI 3 integration for beauty-framework powered by swagger-php and beautiful Redoc UI out of the box.
Features
- ⚡️ PSR-7 compatible
- 🍰 Attribute-based OpenAPI documentation (PHP 8.1+)
- 🛠 Easy integration in your project
- 🚀 Out-of-the-box routes for OpenAPI spec and Redoc UI
- 💾 CLI command for static spec generation
Installation
Require via composer:
composer require beauty-framework/openapi-support
Requirements:
- PHP >=8.1
- beauty-framework/cli ^1.0 (for CLI integration)
- zircote/swagger-php ^5.1 (OpenAPI generator)
Dev Requirements (for testing):
- phpunit/phpunit ^12.3
- psr/container ^2.0
Quick Start
- Create your API controller inheriting from
BaseOpenApiController:
namespace App\Controllers; use Beauty\OpenApi\Http\Controllers\BaseOpenApiController; use OpenApi\Attributes as OAT; #[OAT\OpenApi(openapi: OAT\OpenApi::VERSION_3_1_0, security: [['bearerAuth' => []]])] #[OAT\Info( version: '1.0.0', title: 'Basic single file API', attachables: [new OAT\Attachable()] )] #[OAT\License(name: 'MIT', identifier: 'MIT')] #[OAT\Server(url: 'https://localhost/', description: 'API server')] #[OAT\SecurityScheme(securityScheme: 'bearerAuth', type: 'http', scheme: 'bearer', description: 'Basic Auth')] #[OAT\Tag(name: 'products', description: 'All about products')] #[OAT\Tag(name: 'catalog', description: 'Catalog API')] class ApiController extends BaseOpenApiController { // Everything works out of the box! }
- Annotate your endpoints and models using swagger-php attributes:
use OpenApi\Attributes as OAT; #[OAT\Get(path: '/products', tags: ['products'], ...)] #[Route(method: HttpMethodsEnum::GET, path: '/products')] public function listProducts() { ... }
- Register console commands (optional, for static generation):
Add to config/commands.php:
return array_merge( // ... \Beauty\OpenApi\Console\RegisterCommands::commands(), // ... );
- Access your docs at:
/openapi.jsonfor raw spec/docs/apifor interactive Stoplight UI (change between Swagger, Redoc, Rapid, Stoplight via.envOPENAPI_MODE=)- You can also provide your own action classes (see SpecsAction and RedocAction) if you want to use custom logic for rendering the spec or documentation page. Just typehint your custom action classes in your controller methods. Example:
#[Route(method: HttpMethodsEnum::GET, path: '/products')] public function openApiJson(MyCustomSpecsAction $action): ResponseInterface { return $action(); }
- This gives you full control over how the OpenAPI spec and documentation UI are served.
Switching Documentation UI
You can control which documentation UI is shown at /docs/api by setting the OPENAPI_MODE variable in your .env file:
OPENAPI_MODE=stoplight # or swagger, redoc, rapid
Supported values:
- stoplight (default)
- swagger
- redoc
- rapid
The selected viewer will be automatically rendered at /docs/api depending on this value.
If you provide an invalid value, Stoplight will be used by default.
Customization
- Override
redoc()oropenApiJson()methods in your controller to change the output. - Redoc page can be replaced or extended as needed.
How it works
- At runtime,
SpecsActionusesOpenApiGeneratorto scan your codebase and build the OpenAPI spec. RedocActionrenders a simple Redoc UI page pointing to your/openapi.json.- For production, you can pre-generate the spec and serve it as a static file for performance.
Advanced: Static Generation
You can generate the spec as a file using the CLI command:
./beauty openapi:generate
This allows serving the OpenAPI spec statically in production.
Under the Hood
- Built on zircote/swagger-php — the de-facto OpenAPI generator for PHP.
- Fully compatible with beauty/http responses.
Limitations & Tips
- Static vs. Dynamic: If you have a static
/public/openapi.json, RoadRunner will serve it as a file instead of going through the controller. Remove the file if you want dynamic generation. - Performance: Generating the spec dynamically on every request can be slow on large projects. Consider using static generation for production.
- Customization: For advanced Redoc pages, simply override the
redoc()method.
Links
License
MIT
beauty-framework/openapi-support 适用场景与选型建议
beauty-framework/openapi-support 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「support」 「openapi」 「beauty」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 beauty-framework/openapi-support 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 beauty-framework/openapi-support 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 beauty-framework/openapi-support 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
a simple toolkit for social networks
ARCANEDEV Support Helpers
The following pages give you some general information on how to use our APIs.<br/>The actual API services documentation then follows further below. You can use the menu to jump between API sections.<br/><br/>This page has a built-in HTTP(S) client, so you can test the services directly from within t
The beauty Library.
The beauty Framework.
common components
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-23