From 876777ac9f6b2fbb7a53e2137b5935d1adf7c979 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Fri, 26 Aug 2016 21:09:34 +0000 Subject: [PATCH 1/2] Applied fixes from StyleCI --- src/Mpociot/ApiDoc/Generators/DingoGenerator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php index 4d952307..713f55b3 100644 --- a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php @@ -46,6 +46,7 @@ public function processRoute($route, $bindings = [], $withResponse = true) public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) { $dispatcher = app('Dingo\Api\Dispatcher')->raw(); + return call_user_func_array([$dispatcher, strtolower($method)], [$uri]); } From 976f5ed3a1b37c31d3f31e500d461d244d7525f2 Mon Sep 17 00:00:00 2001 From: Priyabrata Sarkar Date: Tue, 30 Aug 2016 18:43:04 +0530 Subject: [PATCH 2/2] Middleware generate (#92) * added middleware generate support * added middleware generate support * added middleware generate support * added middleware generate support to dingo --- README.md | 1 + .../ApiDoc/Commands/GenerateDocumentation.php | 18 ++++++++++-------- tests/GenerateDocumentationTest.php | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d298dedb..954ae9fc 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ 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 `actAsUserId` | The user ID to use for authenticated API response calls diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index 8d0bf567..96ec0069 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -24,6 +24,7 @@ class GenerateDocumentation extends Command {--output=public/docs : The output path for the generated documentation} {--routePrefix= : The route prefix to use for generation} {--routes=* : The route names to use for generation} + {--middleware= : The middleware to use for generation} {--noResponseCalls : Disable API response calls} {--noPostmanCollection : Disable Postman collection creation} {--actAsUserId= : The user ID to use for API response calls} @@ -64,19 +65,20 @@ public function handle() $allowedRoutes = $this->option('routes'); $routePrefix = $this->option('routePrefix'); + $middleware = $this->option('middleware'); $this->setUserToBeImpersonated($this->option('actAsUserId')); - if ($routePrefix === null && ! count($allowedRoutes)) { - $this->error('You must provide either a route prefix or a route to generate the documentation.'); + if ($routePrefix === null && ! count($allowedRoutes) && $middleware === null) { + $this->error('You must provide either a route prefix or a route or a middleware to generate the documentation.'); return false; } if ($this->option('router') === 'laravel') { - $parsedRoutes = $this->processLaravelRoutes($generator, $allowedRoutes, $routePrefix); + $parsedRoutes = $this->processLaravelRoutes($generator, $allowedRoutes, $routePrefix, $middleware); } else { - $parsedRoutes = $this->processDingoRoutes($generator, $allowedRoutes, $routePrefix); + $parsedRoutes = $this->processDingoRoutes($generator, $allowedRoutes, $routePrefix, $middleware); } $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sortBy('resource'); @@ -242,14 +244,14 @@ private function getRoutes() * * @return array */ - private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix) + private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix, $middleware) { $withResponse = $this->option('noResponseCalls') === false; $routes = $this->getRoutes(); $bindings = $this->getBindings(); $parsedRoutes = []; foreach ($routes as $route) { - if (in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $route->getUri())) { + if (in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $route->getUri()) || in_array($middleware, $route->middleware())) { if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { $parsedRoutes[] = $generator->processRoute($route, $bindings, $withResponse); $this->info('Processed route: ['.implode(',', $route->getMethods()).'] '.$route->getUri()); @@ -269,14 +271,14 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout * * @return array */ - private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix) + private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix, $middleware) { $withResponse = $this->option('noResponseCalls') === false; $routes = $this->getRoutes(); $bindings = $this->getBindings(); $parsedRoutes = []; foreach ($routes as $route) { - if (empty($allowedRoutes) || in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $route->uri())) { + if (empty($allowedRoutes) || in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $route->uri()) || in_array($middleware, $route->middleware())) { $parsedRoutes[] = $generator->processRoute($route, $bindings, $withResponse); $this->info('Processed route: ['.implode(',', $route->getMethods()).'] '.$route->uri()); } diff --git a/tests/GenerateDocumentationTest.php b/tests/GenerateDocumentationTest.php index 6dd36259..6eab6285 100644 --- a/tests/GenerateDocumentationTest.php +++ b/tests/GenerateDocumentationTest.php @@ -45,7 +45,7 @@ protected function getPackageProviders($app) public function testConsoleCommandNeedsAPrefixOrRoute() { $output = $this->artisan('api:generate'); - $this->assertEquals('You must provide either a route prefix or a route to generate the documentation.'.PHP_EOL, $output); + $this->assertEquals('You must provide either a route prefix or a route or a middleware to generate the documentation.'.PHP_EOL, $output); } public function testConsoleCommandDoesNotWorkWithClosure()