diff --git a/README.md b/README.md index 1452ea7..924afa4 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,15 @@ 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: @@ -53,7 +61,7 @@ Route::group(array('prefix' => 'api/v1', 'middleware' => []), function () { 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 +`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 diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index 9ceb59a..1a4d58e 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -81,10 +81,18 @@ class GenerateDocumentation extends Command $generator->prepareMiddleware($this->option('useMiddlewares')); + $routePrefixes = explode(',', $routePrefix); + + $parsedRoutes = []; + if ($this->option('router') === 'laravel') { - $parsedRoutes = $this->processLaravelRoutes($generator, $allowedRoutes, $routePrefix, $middleware); + foreach ($routePrefixes as $routePrefix) { + $parsedRoutes += $this->processLaravelRoutes($generator, $allowedRoutes, $routePrefix, $middleware); + } } else { - $parsedRoutes = $this->processDingoRoutes($generator, $allowedRoutes, $routePrefix, $middleware); + foreach ($routePrefixes as $routePrefix) { + $parsedRoutes += $this->processDingoRoutes($generator, $allowedRoutes, $routePrefix, $middleware); + } } $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sort(function ($a, $b) { return strcmp($a->first()['resource'], $b->first()['resource']);