## Laravel API Documentation Generator Automatically generate your API documentation from your existing Laravel routes. Take a look at the [example documentation](http://marcelpociot.de/whiteboard/). `php artisan api:gen --routePrefix="settings/api/*"` [![Latest Stable Version](https://poser.pugx.org/mpociot/laravel-apidoc-generator/v/stable)](https://packagist.org/packages/mpociot/laravel-apidoc-generator)[![Total Downloads](https://poser.pugx.org/mpociot/laravel-apidoc-generator/downloads)](https://packagist.org/packages/mpociot/laravel-apidoc-generator) [![License](https://poser.pugx.org/mpociot/laravel-apidoc-generator/license)](https://packagist.org/packages/mpociot/laravel-apidoc-generator) [![codecov.io](https://codecov.io/github/mpociot/laravel-apidoc-generator/coverage.svg?branch=master)](https://codecov.io/github/mpociot/laravel-apidoc-generator?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mpociot/laravel-apidoc-generator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mpociot/laravel-apidoc-generator/?branch=master) [![Build Status](https://travis-ci.org/mpociot/laravel-apidoc-generator.svg?branch=master)](https://travis-ci.org/mpociot/laravel-apidoc-generator) [![StyleCI](https://styleci.io/repos/57999295/shield?style=flat)](https://styleci.io/repos/57999295) ## Installation Require this package with composer using the following command: ```sh $ composer require mpociot/laravel-apidoc-generator ``` Using Laravel < 5.5? Go to your `config/app.php` and add the service provider: ```php 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. ```sh $ php artisan api:generate --routePrefix="api/v1/*" ``` You can pass in multiple prefixes by spearating each prefix with comma. ```sh $ php artisan api:generate --routePrefix="api/v1/*,api/public/*" ``` It will generate documentation for all of the routes whose prefixes are `api/v1/` and `api/public/` This command will scan your applications routes for the URIs matching `api/v1/*` and will parse these controller methods and form requests. For example: ```php // 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(es) to use for generation. `*` can be used as a wildcard. Multiple route prefixes can be specified by separating them with a comma (for instance `/v1,/v2`) `routeDomain` | The route domain(s) to use for generation. `*` can be used as a wildcard. Multiple route domains can be specified by separating them with a comma `routes` | The route names to use for generation - Required if no routePrefix or routeDomain is provided `middleware` | The middlewares to use for generation `noResponseCalls` | Disable API response calls `noPostmanCollection` | Disable Postman collection creation `useMiddlewares` | Use all configured route middlewares (Needed for Laravel 5.3 `SubstituteBindings` middleware) `actAsUserId` | The user ID to use for authenticated API response calls `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|binding_two,id` `force` | Force the re-generation of existing/modified API routes `header` | Custom HTTP headers to add to the example requests. Separate 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. ```sh $ 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. Custom formatting and `