0% found this document useful (0 votes)
31 views

Installation: Available Command Options

The document discusses how to install and use the laravel-apidoc-generator package to generate API documentation from Laravel routes and controllers. Key steps include requiring the package, adding the service provider, running the api:generate command to parse routes and controllers, and publishing language files to customize documentation text. Controller docblocks are used to provide descriptions that populate the documentation.

Uploaded by

Camilo Vargas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Installation: Available Command Options

The document discusses how to install and use the laravel-apidoc-generator package to generate API documentation from Laravel routes and controllers. Key steps include requiring the package, adding the service provider, running the api:generate command to parse routes and controllers, and publishing language files to customize documentation text. Controller docblocks are used to provide descriptions that populate the documentation.

Uploaded by

Camilo Vargas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Installation

Require this package with composer using the following command:

$ composer require mpociot/laravel-apidoc-generator

Using Laravel < 5.5? Go to your config/app.php and add the service provider:

Mpociot\ApiDoc\ApiDocGeneratorServiceProvider::class,

Using Laravel < 5.4? Use version 1.0! For Laravel 5.4 and up, use 2.0 instead.

Usage
To generate your API documentation, use the api:generate artisan command.

$ php artisan api:generate --routePrefix="api/v1/*"

This command will scan your applications routes for the URIs matching api/v1/* and will
parse these controller methods and form requests. For example:

// API Group Routes


Route::group(array('prefix' => 'api/v1', 'middleware' => []), function ()
{
// Custom route added to standard Resource
Route::get('example/foo', 'ExampleController@foo');
// Standard Resource route
Route::resource('example', 'ExampleController');
});

Available command options:

Option Description
output The output path used for the generated documentation. Default:
public/docs

routePrefix
The route prefix to use for generation - * can be used as a
wildcard
routes
The route names to use for generation - Required if no routePrefix
is provided
middleware The middlewares to use for generation
noResponseCalls Disable API response calls
noPostmanCollection Disable Postman collection creation
Use all configured route middlewares (Needed for Laravel 5.3
useMiddlewares
SubstituteBindings middleware)
actAsUserId The user ID to use for authenticated API response calls
Option Description
router
The router to use, when processing the route files (can be Laravel
or Dingo - defaults to Laravel)
bindings
List of route bindings that should be replaced when trying to
retrieve route results. Syntax format: `binding_one,id
force Force the re-generation of existing/modified API routes
Custom HTTP headers to add to the example requests. Separate
header the header name and value with ":". For example: --
header="Authorization: CustomToken"

Publish rule descriptions for customisation or


translation.
By default, this package returns the descriptions in english. You can publish the packages
language files, to customise and translate the documentation output.

$ php artisan vendor:publish

After the files are published you can customise or translate the descriptions in the language
you want by renaming the en folder and editing the files in
public/vendor/apidoc/resources/lang.

How does it work?

This package uses these resources to generate the API documentation:

Controller doc block

This package uses the HTTP controller doc blocks to create a table of contents and show
descriptions for your API methods.

Using @resource in a doc block prior to each controller is useful as it creates a Group
within the API documentation for all methods defined in that controller (rather than listing
every method in a single list for all your controllers), but using @resource is not required.
The short description after the @resource should be unique to allow anchor tags to
navigate to this section. A longer description can be included below.

Above each method within the controller you wish to include in your API documentation
you should have a doc block. This should include a unique short description as the first
entry. An optional second entry can be added with further information. Both descriptions
will appear in the API documentation in a different format as shown below.

/**
* @resource Example
*
* Longer description
*/
class ExampleController extends Controller {

/**
* This is the short description [and should be unique as anchor
tags link to this in navigation menu]
*
* This can be an optional longer description of your API call,
used within the documentation.
*
*/
public function foo(){

You might also like