PHP code example of dasher / webman-docs

1. Go to this page and download the library: Download dasher/webman-docs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dasher / webman-docs example snippets




namespace app\controller;

use support\Request;
use Dasher\WebmanDocs\Annotation as Api;

#[Api\Group(name: '用户管理', description: '用户相关接口')]
class UserController
{
    #[Api\Endpoint(
        path: '/api/users',
        method: 'GET',
        summary: '获取用户列表',
        description: '分页获取所有用户信息'
    )]
    #[Api\QueryParam(name: 'page', type: 'integer', example: 1, description: '页码')]
    #[Api\QueryParam(name: 'limit', type: 'integer', example: 10, description: '每页数量')]
    #[Api\Response(status: 200, description: '成功', schema: [
        'code' => 200,
        'data' => [
            'list' => [['id' => 1, 'name' => '张三']],
            'total' => 100
        ]
    ])]
    public function index(Request $request)
    {
        return json(['code' => 200, 'data' => []]);
    }

    #[Api\Endpoint(
        path: '/api/users',
        method: 'POST',
        summary: '创建用户',
        description: '创建新用户'
    )]
    #[Api\BodyParam(name: 'name', type: 'string', 



return [
    'enable' => true,
    'title' => 'API Documentation',
    'description' => 'Auto-generated API documentation',
    'version' => '1.0.0',
    'controllers' => [
        base_path() . '/app/controller',
    ],
    'route' => [
        'prefix' => '/api-docs',
    ],
    'auth' => [
        'enabled' => false,
        'token' => '',
    ],
];
bash
# 导出文档为 JSON
php vendor/bin/generate-docs.php --output docs.json

# 导出文档为 YAML
php vendor/bin/generate-docs.php --output docs.yaml --format yaml

# 查看帮助
php vendor/bin/generate-docs.php --help