## 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 apidoc:generate` [![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 > Note: version 3.x requires PHP 7 and Laravel 5.5 or higher. Version 2.x requires Laravel 5.4. ```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, ``` Then publish the config file by running: ```bash php artisan vendor:publish --provider=Mpociot\ApiDoc\ApiDocGeneratorServiceProvider --tag=config ``` This will create an `apidoc.php` file in your `config` folder. ## Usage Before you can generate your documentation, you'll need to configure a few things in your `config/apidoc.php`. ### output This is the file path where the generated documentation will be written to. Default: `**public/docs** ### postman Set this option to true if you want a Postman collection to be generated along with the documentation. Default: `**true** ### router The router to use when processing the route (can be Laravel or Dingo. Defaults to **Laravel**) ### routes This is where you specify what rules documentation should be generated for. You specify routes to be parsed by defining conditions that the routes should meet and rules that should be applied when generating documentation. These conditions and rules are specified in groups, allowing you to apply different rules to different routes. For instance, suppose your configuration looks like this: ```php [ [ 'match' => [ 'domains' => ['*'], 'prefixes' => ['api/*', 'v2-api/*'], 'versions' => ['v1'], ], 'include' => ['users.index'], 'exclude' => ['users.create'], 'apply' => [ 'headers' => [ 'Authorization' => 'Bearer: {token}', ], ], ], ]; ``` This means documentation will be generated for routes in all domains ('*' is a wildcard meaning 'any character') which match any of the patterns 'api/*' or 'v2-api/*', excluding the 'users.create' route, and including the 'users.index' route. (The `versions` key is ignored unless you are using Dingo router). Also, in the generated documentation, these routes will have the header 'Authorization: Bearer: {token}' added to the example requests. You can also separate routes into groups to apply different rules to them: ```php [ [ 'match' => [ 'domains' => ['v1.*'], 'prefixes' => ['*'], ], 'include' => [], 'exclude' => [], 'apply' => [ 'headers' => [ 'Token' => '{token}', 'Version' => 'v1', ], ], ], [ 'match' => [ 'domains' => ['v2.*'], 'prefixes' => ['*'], ], 'include' => [], 'exclude' => [], 'apply' => [ 'headers' => [ 'Authorization' => 'Bearer: {token}', 'Api-Version' => 'v2', ], ], ], ]; ``` With the configuration above, routes on the `v1.*` domain will have the `Token` and `Version` headers applied, while routes on the `v2.*` domain will have the `Authorization` and `Api-Version` headers applied. > Note: If you're using DIngo router, the `versions` parameter is required in each route group. This parameter does not support wildcards. Each version must be listed explicitly, To generate your API documentation, use the `apidoc:generate` artisan command. ```sh $ php artisan apidoc:generate ``` It will generate documentation using your specified configuration. ## Documenting your API This package uses these resources to generate the API documentation: ### Grouping endpoints 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 `