Search by

hyperfai / swagger

qiaohengshan

this is hyperf annotation document generate package

2.0.4 2026-09-22 06:05 UTC

This package is not auto-updated.

Last update: 2026-09-22 06:05:51 UTC


README

安装

composer require joyqhs/hyperf-swagger

根据注解生成 API 文档

# 类的注解  分组
use joyqhs\Swagger\Annotation\Api;
# 方法的注解 接口描述
use joyqhs\Swagger\Annotation\ApiOperation;
# 参数组的注解
use joyqhs\Swagger\Annotation\ApiParams;
# 参数的注解
use joyqhs\Swagger\Annotation\ApiParam;
# 响应注解
use joyqhs\Swagger\Annotation\ApiResponses;

参数说明

参数
注解参数名称说明其他
Apiname分组名称
ApiOperationname接口名称
ApiOperationdesc接口描述
ApiParamsname参数组名称
ApiParamsvalue参数组数组,多个ApiParam 或者 ApiParams
ApiParamname参数名
ApiParamdesc参数描述
ApiParamtype参数类型 integer string ....
ApiParamrequired是否必填 true or false
ApiParamchildren子参数 , 一般用于响应结果的多维数组数组 多个 ApiParam
ApiResponsesvalue响应组数组,多个ApiParam 或者 ApiParams

配置

php bin/hyperf.php vendor:public joyqhs/hyperf-swagger

在 config/autoload/swagger.php 中简单配置

使用例子

<?php

declare(strict_types=1);

namespace App\Controller;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use hyperfai\Swagger\Annotation\Api;
use hyperfai\Swagger\Annotation\ApiOperation;

#[Controller()]
#[Api('系统设置')]
class AuthController extends AbstractController
{
    
    #[PostMapping(path: '/api/login')]
    #[ApiOperation(module: '用户管理', name: '用户登陆', desc: '用户登陆')]
    public function login($id)
    {

    }
    
    #[PostMapping(path: '/api/logout')]
    #[ApiOperation(module: '用户管理', name: '退出登陆', desc: '退出登陆')]
    public function logout(){

    }
    
}

查看接口

 php bin/hyperf.php swagger:gen 

可指定参数 -S server.php 中的服务名称 默认 http -P 路由地址 -E 导出

命令行

 php bin/hyperf.php swagger:gen  -S admin
 php bin/hyperf.php swagger:gen  -P auth/login
 php bin/hyperf.php swagger:gen  -S admin -E 

展示

hyperf 注解文档生成

hyperf 注解文档生成

hyperf 注解文档生成

hyperf 注解文档生成

hyperf 注解文档生成

目前仅支持导出 easydoc.xyz 的 json api文件 可以在 easydoc.xyz 中导入 实现模拟请求等 后期会支持更多和内置接口展示。