PHP code example of on1kel / hyperf-fly-docs

1. Go to this page and download the library: Download on1kel/hyperf-fly-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/ */

    

on1kel / hyperf-fly-docs example snippets


return [
    'default_collection' => 'latest',

    'cache' => [
        'enabled' => true,
        'path' => BASE_PATH . '/runtime/flydocs',
    ],

    'ui' => [
        'index_title' => 'API Documentation',
        'use_cdn' => false, // false = использовать локальные файлы из publish/fly-docs
    ],
];



declare(strict_types=1);

namespace App\Http\Controllers\Api;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use On1kel\HyperfFlyDocs\Attributes\Operation;
use On1kel\HyperfFlyDocs\Attributes\Complex;
use App\Models\Comment;
use App\Http\Resources\CommentCollection;
use On1kel\HyperfLighty\OpenApi\Complexes\IndexActionComplex;

#[Controller(prefix: 'api/comments')]
final class CommentController
{
    #[PostMapping(path: 'search')]
    #[Operation(tags: ['Comment'])]
    #[Complex(
        factory: IndexActionComplex::class,
        model_class: Comment::class,
        collection_resource: CommentCollection::class,
        options: []
    )]
    public function search()
    {
        // обычная бизнес-логика
    }
}

final class IndexActionComplex implements ComplexFactoryInterface
{
    public function build(...$arguments): ComplexResultDTO
    {
        // 1. Сбор схем через ModelReflector
        // 2. Построение query-параметров (pagination, orders)
        // 3. Формирование RequestBody с фильтрацией
        // 4. Добавление успешных и ошибочных ответов
        // 5. Возврат ComplexResultDTO с готовыми описаниями
    }
}
bash
php bin/hyperf.php vendor:publish on1kel/hyperf-flydocs