Download the PHP package hyperf-plus/swagger without Composer
On this page you can find all versions of the php package hyperf-plus/swagger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download hyperf-plus/swagger
More information about hyperf-plus/swagger
Files in hyperf-plus/swagger
Download hyperf-plus/swagger
More information about hyperf-plus/swagger
Files in hyperf-plus/swagger
Vendor hyperf-plus
Package swagger
Short Description HPlus Swagger 组件 - 自动生成 API 文档,支持 OpenAPI 3.0 规范
License MIT
Homepage https://github.com/lphkxd/hyperf-plus
Package swagger
Short Description HPlus Swagger 组件 - 自动生成 API 文档,支持 OpenAPI 3.0 规范
License MIT
Homepage https://github.com/lphkxd/hyperf-plus
Please rate this library. Is it a good library?
Informations about the package swagger
HPlus Swagger 4.0
为 Hyperf 框架打造的智能 API 文档生成组件,支持 OpenAPI 3.1.1 规范,自动集成 Route 和 Validate 组件。
✨ 4.0 新特性
- 🚀 OpenAPI 3.1.1 - 完整支持最新规范
- 🔄 智能集成 - 自动识别 Route 和 Validate 注解
- 📝 验证规则转换 - 自动将验证规则转为 JSON Schema
- ⚡ 软依赖设计 - validate 插件可选,无则跳过参数解析
- 🎨 美观 UI - 集成 Swagger UI,支持在线测试
- 💾 懒加载+缓存 - 启动零开销,首次访问构建并缓存
- 📋 FormRequest 支持 - 自动识别 Hyperf FormRequest 验证器
📦 安装
可选依赖
🚀 快速开始
1. 发布配置
2. 配置
编辑 config/autoload/swagger.php:
3. 使用示例
4. 访问文档
启动服务后访问:http://localhost:9501/swagger
📋 注解说明
@ApiResponse
@ApiResponseExample
@RequestBody
🎯 验证规则转换
当安装了 hyperf-plus/validate 时,Swagger 会自动将验证规则转换为 OpenAPI 参数定义:
| 验证规则 | JSON Schema |
|---|---|
required |
required: true |
string |
type: string |
integer |
type: integer |
numeric |
type: number |
boolean |
type: boolean |
array |
type: array |
email |
format: email |
url |
format: uri |
date |
format: date |
min:N |
minimum: N / minLength: N |
max:N |
maximum: N / maxLength: N |
between:M,N |
minimum: M, maximum: N |
in:a,b,c |
enum: [a, b, c] |
示例
生成的 Schema:
🔧 配置详解
🛠️ 命令行工具
⚡ 性能优化
懒加载 + 缓存机制
Swagger 文档不在启动时生成,而是在首次访问 /swagger/json 时才构建,并缓存结果:
手动刷新缓存
如果代码有更新,需要重新生成文档:
🤝 组件协作
🧪 测试覆盖
运行测试:
📊 与 3.x 版本对比
| 特性 | 3.x | 4.0 |
|---|---|---|
| OpenAPI 版本 | 3.0.x | 3.1.1 |
| validate 依赖 | 硬依赖 | 软依赖(可选) |
dateType 参数 |
✅ | ❌ 改为 mode |
| 规则转换 | 部分支持 | 完整支持 |
📝 最佳实践
-
文档质量
- 为每个接口添加
summary和description - 提供请求和响应示例
- 使用有意义的标签分组
- 为每个接口添加
-
安全考虑
- 生产环境关闭
auto_generate - 限制文档访问权限
- 不暴露敏感信息
- 生产环境关闭
- 版本管理
- 使用版本前缀区分 API 版本
- 标记废弃的接口
deprecated: true
🔗 相关链接
📄 License
MIT
All versions of swagger with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.1
hyperf/framework Version ^3.1.0
hyperf/di Version ^3.1.0
hyperf/http-server Version ^3.1.0
hyperf-plus/route Version *
hyperf/framework Version ^3.1.0
hyperf/di Version ^3.1.0
hyperf/http-server Version ^3.1.0
hyperf-plus/route Version *
The package hyperf-plus/swagger contains the following files
Loading the files please wait ...