gungcahyadipp/auto-docs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gungcahyadipp/auto-docs

Composer 安装命令:

composer require gungcahyadipp/auto-docs

包简介

All-in-one API documentation for Laravel. Bundles Scramble and Scramble Pro.

README 文档

README

All-in-one API documentation package for Laravel. Bundles Scramble and Scramble Pro into a single package with automatic configuration, Bearer token auth, dark theme UI, and external docs support.

Features

  • Zero-config API documentation generation from your Laravel code
  • Dark theme UI by default with Stoplight Elements
  • Bearer JWT authentication auto-configured
  • External markdown docs — separate endpoint descriptions from controller code
  • Multi-version API support (V1, V2, etc.) with conflict detection
  • Conditional extension loading for optional packages (Laravel Data, Query Builder, JSON:API, Laravel Actions)
  • Single unified config file (autodocs.php)

Versions Bundled

  • dedoc/scramble v0.13.13
  • dedoc/scramble-pro v0.8.7

Installation

composer require gungcahyadipp/auto-docs

The package auto-discovers via Laravel's package discovery. No manual provider registration needed.

Configuration

Publish the config file:

php artisan vendor:publish --tag=autodocs-config

Publish the API description markdown:

php artisan vendor:publish --tag=autodocs-description

Publish everything at once:

php artisan vendor:publish --tag=autodocs

Usage

Visit /docs to see the generated API documentation.

The JSON OpenAPI spec is available at /docs/api.json.

Config Overview

All configuration lives in config/autodocs.php:

return [
    'api_path' => env('AUTODOCS_API_PATH', 'api'),
    'api_domain' => null,

    'info' => [
        'version' => env('API_VERSION', '1.0.0'),
        'description' => null, // Loaded from markdown file
    ],

    'description_file' => base_path('autodocs/description.md'),

    'ui' => [
        'title' => env('APP_NAME', 'API Documentation'),
        'theme' => 'dark', // 'light', 'dark', 'system'
        'layout' => 'responsive',
    ],

    'security' => [
        'type' => 'bearer',
        'format' => 'JWT',
    ],

    'docs_path' => base_path('autodocs'),
    'description_strategy' => 'file', // 'file', 'merge', 'fallback'
];

Security Scheme

Bearer JWT is enabled by default. All endpoints will show the lock icon in the docs UI.

To exclude an endpoint from authentication, use @unauthenticated in the PHPDoc:

/**
 * @unauthenticated
 */
public function login(Request $request) { ... }

To switch to API Key authentication:

// config/autodocs.php
'security' => [
    'type' => 'apiKey',
    'in' => 'header',
    'name' => 'X-API-Key',
],

To disable security entirely:

'security' => null,

External Docs (Separated Descriptions)

Instead of writing long descriptions in your controller PHPDoc, you can create separate markdown files. No changes needed in your controller — the extension automatically matches doc files to endpoints based on controller name and method.

Quick Start

  1. Generate the skeleton:

    php artisan autodocs:generate
  2. Edit the generated .md files in autodocs/

  3. Visit /docs — descriptions are loaded automatically

How It Works (No Controller Changes Needed)

Given this controller:

// app/Http/Controllers/Api/V1/UserController.php

namespace App\Http\Controllers\Api\V1;

class UserController extends Controller
{
    public function store(StoreUserRequest $request)
    {
        // Your logic here — NO PHPDoc needed for description
        return new UserResource(User::create($request->validated()));
    }
}

And this file:

autodocs/V1/UserController/store.md

The docs UI will automatically show the content from store.md as the endpoint description. You don't need to add any annotation, attribute, or PHPDoc to the controller.

Combining with PHPDoc

If you still want to use PHPDoc for some things (like @unauthenticated or @tags), that works fine:

/**
 * @unauthenticated
 */
public function login(LoginRequest $request)
{
    // Description comes from autodocs/AuthController/login.md
    // @unauthenticated still works from PHPDoc
}

The description_strategy config controls how external docs interact with any existing PHPDoc description.

File Structure

autodocs/
├── description.md          ← API homepage description
├── UserController/
│   ├── index.md            → GET /api/users
│   ├── store.md            → POST /api/users
│   └── show.md             → GET /api/users/{id}
├── V1/
│   └── UserController/
│       └── index.md        → For Api\V1\UserController@index
├── V2/
│   └── UserController/
│       └── index.md        → For Api\V2\UserController@index
└── OrderController/
    └── store.md

Markdown Format

# Create a new user

Creates a new user account in the system. The user will receive
a verification email after successful registration.

## Business Rules

- Email must be unique
- Password must meet complexity requirements
- Users are created with 'pending' status by default
  • First line (or # heading) becomes the summary/title
  • Everything after the first blank line becomes the description

Path Resolution

For a controller like App\Http\Controllers\Api\V1\UserController@store, the extension searches these paths in order:

  1. autodocs/Api/V1/UserController/store.md (most specific)
  2. autodocs/V1/UserController/store.md
  3. autodocs/UserController/store.md (only if no V1/V2 conflict)
  4. autodocs/Api/V1/User/store.md (without "Controller" suffix)
  5. autodocs/User/store.md

Multi-Version Safety

When both V1/UserController/ and V2/UserController/ exist in your docs folder, the short name fallback (UserController/store.md) is automatically disabled to prevent cross-version contamination.

Description Strategy

Control how external docs interact with PHPDoc in your controllers:

Strategy Behavior
'file' Markdown file overrides PHPDoc description (default)
'merge' Markdown file is appended after PHPDoc description
'fallback' Markdown file is used only when PHPDoc is empty

API Description (Homepage)

The API homepage description is loaded from a markdown file:

  1. Default: bundled template from the package
  2. After publish: autodocs/description.md

Edit this file to customize the description shown on the docs homepage.

Optional Package Support

Auto-Docs conditionally enables extensions for these packages when installed:

Package What it enables
spatie/laravel-data Data object schema generation
spatie/laravel-query-builder Filter/sort/include parameter docs
timacdonald/json-api JSON:API resource schema
lorisleiva/laravel-actions Actions as controllers
spatie/laravel-json-api-paginate JSON:API pagination params

No configuration needed — just install the package and docs are generated automatically.

Custom Extensions

Register your own Scramble extensions:

// config/autodocs.php
'extensions' => [
    App\Docs\MyCustomExtension::class,
],

Or programmatically in a service provider:

use Dedoc\Scramble\Scramble;

Scramble::registerExtension(MyTypeToSchemaExtension::class);
Scramble::registerExtension(MyOperationExtension::class);

Auto-Generate Docs Skeleton

Automatically scaffold markdown doc files for all your API endpoints:

php artisan autodocs:generate

This scans all registered API routes and creates .md files with a ready-to-fill template:

autodocs/
├── description.md
├── Api/V1/UserController/
│   ├── index.md
│   ├── store.md
│   ├── show.md
│   ├── update.md
│   └── destroy.md
└── Api/V1/OrderController/
    └── index.md

Options

Option Description
--force Overwrite existing doc files
--path= Custom output path (default: from config docs_path)
--api-path= Filter routes by API path prefix

Example

# Generate for all API routes
php artisan autodocs:generate

# Only generate for v2 routes
php artisan autodocs:generate --api-path=api/v2

# Regenerate all (overwrite existing)
php artisan autodocs:generate --force

Each generated file includes:

  • Auto-generated title based on method name (e.g. "List all users", "Create a new order")
  • HTTP method and URI as comment
  • Placeholder sections for authentication, request body, and response

Testing

composer test

License

MIT

gungcahyadipp/auto-docs 适用场景与选型建议

gungcahyadipp/auto-docs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 159 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「documentation」 「laravel」 「openapi」 「scramble」 「auto-docs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gungcahyadipp/auto-docs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gungcahyadipp/auto-docs 我们能提供哪些服务?
定制开发 / 二次开发

基于 gungcahyadipp/auto-docs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 159
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-13