jetlee0797/apidocs

Api documentation generator for Laravel 5


Keywords
documentation, api, docs, blueprint, laravel, API Blueprint
License
MIT

Documentation

ApiDocs Generator

Scrutinizer Code Quality Build Status

L5 API Documentation generator based upon DocBlock comments.

Installation

You can install the package through Composer:

composer require yaro/apidocs

Add this service provider and alias to config/app.php:

'providers' => [
    //...
    Yaro\ApiDocs\ServiceProvider::class,
    //...
]

'aliases' => [
    //...
    'ApiDocs' => Yaro\ApiDocs\Facade::class,
    //...
]

Then publish the config and assets files:

php artisan vendor:publish --provider="Yaro\ApiDocs\ServiceProvider"

And you should add a disk named snapshots to config/filesystems.php on which the blueprint snapshots will be saved:

//...
'disks' => [
    //...
    'apidocs' => [
        'driver' => 'local',
        'root'   => storage_path('apidocs'),
    ],
//...    

Usage

All your routes must begin with some segment, e.g. /api/ (changed in config). Package will collect routes, that starts with this segment only.

Add to your route method DocBlock comment. e.g.:

/**
 * Some api endpoint for important stuff.
 * 
 * Just show some template with     
 * some very long description    
 * on several lines
 * 
 * @param int    $offset   Just an offset size
 * @param string $password 
 */
public function getSomeStuff()
{
    return response()->json([]);
}

And create route to view your documentation.

Route::get('/docs', function() {
    return ApiDocs::show();
});

Also you can force authorization prompt by adding apidocs.auth.basic middleware. Authorized identites placed under apidocs.auth.credentials config.

Route::get('/docs', function() {
    return ApiDocs::show();
})->middleware(['apidocs.auth.basic']);

To exclude some routes/classes add them to config's exclude. Asterisks may be used to indicate wildcards.

'exclude' => [
    'classes' => [
        // 'App\Http\Controllers\*' - exclude all controllers from docs.
        // 'App\Http\Controllers\MyController@*' - remove all methods for specific controller from docs.
    ],
    
    'routes' => [
        // 'payment/test',
        // 'simulate/*',
    ],
 ],

Additionally you can create API Blueprint file:

ApiDocs::blueprint()->create();
// or pass snapshot name and/or filesystem disc name
ApiDocs::blueprint()->create('my-newest-snapshot', 's3-blueprint');

Or just render its contents without creating file:

echo ApiDocs::blueprint()->render();

Or via artisan:

php artisan apidocs:blueprint-create

TODO

  • generate plain html page with all documentation info.
  • fullsize block with response.

License

The MIT License (MIT). Please see LICENSE for more information.