mhamlet/laravel-apidocs

该包已被废弃,不再维护。未建议替代包。

Laravel API 文档生成器

dev-master / 1.0.x-dev 2017-05-21 10:59 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:04:30 UTC


README

Latest Version Build Status Quality Score Total Downloads

此 Laravel 包提供 API 文档生成器。它基于您的路由和控制器方法 DocBlock 注释。

该包需要 PHP >= 7.0 和 Laravel 5.4。

安装

通过执行以下命令将包添加到您的 composer.json。

composer require mhamlet/laravel-apidocs

接下来,将服务提供者添加到 config/app.php

MHamlet\Apidocs\ApidocsServiceProvider::class,

文档

// The main class of package is MHamlet\Apidocs\Generator
// Let's write a simple "use"
use MHamlet\Apidocs\Generator;

// Generator has two statically declared methods - "forAllRoutes" and "forRoutesWithPrefix".

// The first one will provide you to generate documentation for all defined
// routes in your application.
$routeGenerator = Generator::forAllRoutes();

// The second one will provide you to generate documentation for routes,
// which URL's starts with given prefix.
$routeGenerator = Generator::forRoutesWithPrefix('api');

// The route generator also has two methods - "describeRoutes" and "generate"

// The first one will parse and describe the routes for you.
$routeGenerator->describeRoutes()

// It will return the following (the result is serialized in json to make it readable in this example)
/*
[
    {
        "path":"api/users",
        "controller":"App\\Http\\Controllers\\UserController",
        "method":"index",
        "verbs":[
            "GET",
            "HEAD"
        ]
    }
]
*/

// The second one will parse routes, controller comments and return the
// API documentation itself.
$routeGenerator->generate()

// It will return the following result
/*
[
    {
        "path":"api\/users",
        "verbs":[
            "GET",
            "HEAD"
        ],
        "description":"Returns list of all users",
        "params":[
            {
                "type":"int",
                "name":"from",
                "description":"test from"
            },
            {
                "type":"int",
                "name":"offset",
                "description":"test offset"
            }
        ],
    }
]
*/

许可证

本包是开源软件,许可协议为MIT 许可证