From a1e293968c084fdd7012b1ab236dade398eec5c3 Mon Sep 17 00:00:00 2001 From: JapSeyz Date: Sun, 30 Oct 2016 01:44:09 +0200 Subject: [PATCH 001/655] Allow changes to be made to the info vendor view --- src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index a8d1a2fe..da9ed004 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -118,10 +118,6 @@ private function writeMarkdown($parsedRoutes) $generatedDocumentation = file_get_contents($targetFile); $compareDocumentation = file_get_contents($compareFile); - if (preg_match('/(.*)/is', $generatedDocumentation, $generatedInfoText)) { - $infoText = trim($generatedInfoText[1], "\n"); - } - if (preg_match('/---(.*)---\\s/is', $generatedDocumentation, $generatedFrontmatter)) { $frontmatter = trim($generatedFrontmatter[1], "\n"); } From 585669e8d0ee41a356ef37741b835eaacebc3ff9 Mon Sep 17 00:00:00 2001 From: Rudie Dirkx Date: Fri, 28 Apr 2017 11:55:14 +0200 Subject: [PATCH 002/655] #176 don't document HEAD --- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index 0c89a37d..1f59b43e 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -32,10 +32,13 @@ public function getUri($route) public function getMethods($route) { if (version_compare(app()->version(), '5.4', '<')) { - return $route->getMethods(); + $methods = $route->getMethods(); + } + else { + $methods = $route->methods(); } - return $route->methods(); + return array_diff($methods, ['HEAD']); } /** From 8c82799a65a8b7c57f05dd6d7f140191c08a339c Mon Sep 17 00:00:00 2001 From: Rudie Dirkx Date: Fri, 28 Apr 2017 12:03:51 +0200 Subject: [PATCH 003/655] #176 don't document HEAD II --- src/Mpociot/ApiDoc/Generators/DingoGenerator.php | 2 +- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php index d85ac8c4..933e639a 100644 --- a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php @@ -81,6 +81,6 @@ public function getUri($route) */ public function getMethods($route) { - return $route->getMethods(); + return array_diff($route->getMethods(), ['HEAD']); } } diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index 1f59b43e..b2c98dee 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -33,8 +33,7 @@ public function getMethods($route) { if (version_compare(app()->version(), '5.4', '<')) { $methods = $route->getMethods(); - } - else { + } else { $methods = $route->methods(); } From 3fd150e2304bde88d2907063399daed4c9c44e4f Mon Sep 17 00:00:00 2001 From: Rudie Dirkx Date: Thu, 25 May 2017 23:07:21 +0200 Subject: [PATCH 004/655] #176 don't document HEAD III - tests --- tests/ApiDocGeneratorTest.php | 2 +- tests/DingoGeneratorTest.php | 2 +- tests/Fixtures/index.md | 4 ---- tests/Fixtures/resource_index.md | 8 -------- tests/GenerateDocumentationTest.php | 12 ++++++------ 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/tests/ApiDocGeneratorTest.php b/tests/ApiDocGeneratorTest.php index 38cf7b54..f9c1aead 100644 --- a/tests/ApiDocGeneratorTest.php +++ b/tests/ApiDocGeneratorTest.php @@ -53,7 +53,7 @@ public function testCanParseRouteMethods() $route = new Route(['GET'], '/get', ['uses' => TestController::class.'@parseMethodDescription']); $parsed = $this->generator->processRoute($route); - $this->assertSame(['GET', 'HEAD'], $parsed['methods']); + $this->assertSame(['GET'], $parsed['methods']); $route = new Route(['POST'], '/post', ['uses' => TestController::class.'@parseMethodDescription']); $parsed = $this->generator->processRoute($route); diff --git a/tests/DingoGeneratorTest.php b/tests/DingoGeneratorTest.php index 49aa9a2e..2311498d 100644 --- a/tests/DingoGeneratorTest.php +++ b/tests/DingoGeneratorTest.php @@ -68,7 +68,7 @@ public function testCanParseRouteMethods() }); $route = app('Dingo\Api\Routing\Router')->getRoutes()['v1']->getRoutes()[0]; $parsed = $this->generator->processRoute($route); - $this->assertSame(['GET', 'HEAD'], $parsed['methods']); + $this->assertSame(['GET'], $parsed['methods']); $route = app('Dingo\Api\Routing\Router')->getRoutes()['v1']->getRoutes()[1]; $parsed = $this->generator->processRoute($route); diff --git a/tests/Fixtures/index.md b/tests/Fixtures/index.md index 2f2effbd..4ef3bc0d 100644 --- a/tests/Fixtures/index.md +++ b/tests/Fixtures/index.md @@ -59,8 +59,6 @@ null ### HTTP Request `GET api/test` -`HEAD api/test` - @@ -105,8 +103,6 @@ $.ajax(settings).done(function (response) { ### HTTP Request `GET api/fetch` -`HEAD api/fetch` - diff --git a/tests/Fixtures/resource_index.md b/tests/Fixtures/resource_index.md index c0cc4451..08388f88 100644 --- a/tests/Fixtures/resource_index.md +++ b/tests/Fixtures/resource_index.md @@ -58,8 +58,6 @@ $.ajax(settings).done(function (response) { ### HTTP Request `GET api/user` -`HEAD api/user` - @@ -100,8 +98,6 @@ $.ajax(settings).done(function (response) { ### HTTP Request `GET api/user/create` -`HEAD api/user/create` - @@ -175,8 +171,6 @@ $.ajax(settings).done(function (response) { ### HTTP Request `GET api/user/{user}` -`HEAD api/user/{user}` - @@ -217,8 +211,6 @@ $.ajax(settings).done(function (response) { ### HTTP Request `GET api/user/{user}/edit` -`HEAD api/user/{user}/edit` - diff --git a/tests/GenerateDocumentationTest.php b/tests/GenerateDocumentationTest.php index b538c0ce..41cf492e 100644 --- a/tests/GenerateDocumentationTest.php +++ b/tests/GenerateDocumentationTest.php @@ -64,8 +64,8 @@ public function testConsoleCommandDoesNotWorkWithClosure() $output = $this->artisan('api:generate', [ '--routePrefix' => 'api/*', ]); - $this->assertContains('Skipping route: [GET,HEAD] api/closure', $output); - $this->assertContains('Processed route: [GET,HEAD] api/test', $output); + $this->assertContains('Skipping route: [GET] api/closure', $output); + $this->assertContains('Processed route: [GET] api/test', $output); } public function testConsoleCommandDoesNotWorkWithClosureUsingDingo() @@ -85,8 +85,8 @@ public function testConsoleCommandDoesNotWorkWithClosureUsingDingo() '--router' => 'dingo', '--routePrefix' => 'v1', ]); - $this->assertContains('Skipping route: [GET,HEAD] closure', $output); - $this->assertContains('Processed route: [GET,HEAD] test', $output); + $this->assertContains('Skipping route: [GET] closure', $output); + $this->assertContains('Processed route: [GET] test', $output); }); } @@ -98,8 +98,8 @@ public function testCanSkipSingleRoutesCommandDoesNotWorkWithClosure() $output = $this->artisan('api:generate', [ '--routePrefix' => 'api/*', ]); - $this->assertContains('Skipping route: [GET,HEAD] api/skip', $output); - $this->assertContains('Processed route: [GET,HEAD] api/test', $output); + $this->assertContains('Skipping route: [GET] api/skip', $output); + $this->assertContains('Processed route: [GET] api/test', $output); } public function testCanParseResourceRoutes() From ed92f93d01c406d672806599a404887ceb87dd5d Mon Sep 17 00:00:00 2001 From: Rudie Dirkx Date: Thu, 25 May 2017 23:18:23 +0200 Subject: [PATCH 005/655] #176 don't document HEAD Iv - tests --- tests/Fixtures/index.md | 8 ++++---- tests/Fixtures/resource_index.md | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Fixtures/index.md b/tests/Fixtures/index.md index 4ef3bc0d..f34641d4 100644 --- a/tests/Fixtures/index.md +++ b/tests/Fixtures/index.md @@ -21,7 +21,7 @@ Welcome to the generated API reference. #general - + ## Example title. This will be the long description. @@ -60,9 +60,9 @@ null `GET api/test` - + - + ## api/fetch > Example request: @@ -104,5 +104,5 @@ $.ajax(settings).done(function (response) { `GET api/fetch` - + diff --git a/tests/Fixtures/resource_index.md b/tests/Fixtures/resource_index.md index 08388f88..027c3b6a 100644 --- a/tests/Fixtures/resource_index.md +++ b/tests/Fixtures/resource_index.md @@ -21,7 +21,7 @@ Welcome to the generated API reference. #general - + ## Display a listing of the resource. > Example request: @@ -59,9 +59,9 @@ $.ajax(settings).done(function (response) { `GET api/user` - + - + ## Show the form for creating a new resource. > Example request: @@ -99,7 +99,7 @@ $.ajax(settings).done(function (response) { `GET api/user/create` - + ## Store a newly created resource in storage. @@ -134,7 +134,7 @@ $.ajax(settings).done(function (response) { - + ## Display the specified resource. > Example request: @@ -172,9 +172,9 @@ $.ajax(settings).done(function (response) { `GET api/user/{user}` - + - + ## Show the form for editing the specified resource. > Example request: @@ -212,7 +212,7 @@ $.ajax(settings).done(function (response) { `GET api/user/{user}/edit` - + ## Update the specified resource in storage. From 28ff33be15424ff5a5b819dbe88b34468d1752b2 Mon Sep 17 00:00:00 2001 From: Manash Jyoti Sonowal Date: Fri, 16 Jun 2017 23:18:28 +0530 Subject: [PATCH 006/655] added support for multiple prefixes for routes which can be passed as separated by comma --- .../ApiDoc/Commands/GenerateDocumentation.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index f430fc7d..ece88884 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -79,10 +79,18 @@ public function handle() $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']); From d06292ac3b654f80965df141de1fbef0deec6f26 Mon Sep 17 00:00:00 2001 From: Manash Jyoti Sonowal Date: Fri, 16 Jun 2017 23:37:48 +0530 Subject: [PATCH 007/655] updated the readme with last commit 28ff33be15424ff5a5b819dbe88b34468d1752b2 which adds support for generation when there are multiple prefixes --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 098fa35e..ede1f974 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,14 @@ To generate your API documentation, use the `api:generate` artisan command. $ php artisan api:generate --routePrefix="api/v1/*" ``` +After 28ff33be15424ff5a5b819dbe88b34468d1752b2 this commit, it supports passing generation of 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 @@ -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 From 08a330c80a287d59ac199f566696db9991b9c11b Mon Sep 17 00:00:00 2001 From: Manash Jyoti Sonowal Date: Fri, 16 Jun 2017 23:42:12 +0530 Subject: [PATCH 008/655] apply patch from StyleCI --- src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index ece88884..6c97a204 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -81,7 +81,7 @@ public function handle() $routePrefixes = explode(",", $routePrefix); - $parsedRoutes = []; + $parsedRoutes = []; if ($this->option('router') === 'laravel') { foreach ($routePrefixes as $routePrefix) { From 03ec9e4c36e625f8ee495d38f5f8252933f24529 Mon Sep 17 00:00:00 2001 From: Manash Jyoti Sonowal Date: Fri, 16 Jun 2017 23:43:15 +0530 Subject: [PATCH 009/655] Apply fixes from StyleCI --- src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index 6c97a204..d210bf02 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -81,7 +81,7 @@ public function handle() $routePrefixes = explode(",", $routePrefix); - $parsedRoutes = []; + $parsedRoutes = []; if ($this->option('router') === 'laravel') { foreach ($routePrefixes as $routePrefix) { From ec2c9590e577c9fcd96aafcdb90171f50d894508 Mon Sep 17 00:00:00 2001 From: Manash Jyoti Sonowal Date: Fri, 16 Jun 2017 23:44:44 +0530 Subject: [PATCH 010/655] apply fixes from StyleCI --- src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index d210bf02..4ab9e2f4 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -79,7 +79,7 @@ public function handle() $generator->prepareMiddleware($this->option('useMiddlewares')); - $routePrefixes = explode(",", $routePrefix); + $routePrefixes = explode(',', $routePrefix); $parsedRoutes = []; From 130b59129e1aa9e9254b42a4257c0d646b80f614 Mon Sep 17 00:00:00 2001 From: Alexander Reichardt Date: Thu, 29 Jun 2017 23:01:36 +0200 Subject: [PATCH 011/655] allow custom description for custom validation rules --- src/Mpociot/ApiDoc/Generators/AbstractGenerator.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index b4efdcbc..650d17be 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -433,6 +433,12 @@ protected function parseRule($rule, $ruleName, &$attributeData, $seed) $attributeData['value'] = $faker->ipv4; $attributeData['type'] = $rule; break; + default: + $unknownRuleDescription = Description::parse($rule)->getDescription(); + if ($unknownRuleDescription) { + $attributeData['description'][] = $unknownRuleDescription; + } + break; } if ($attributeData['value'] === '') { From fef471296653e335a81f65d1a32ab7226ac5a3fa Mon Sep 17 00:00:00 2001 From: Gustavo Real Date: Tue, 10 Oct 2017 17:21:48 +0100 Subject: [PATCH 012/655] support custom validator method on laravel form request --- .../ApiDoc/Generators/LaravelGenerator.php | 4 ++- tests/ApiDocGeneratorTest.php | 10 +++++++ tests/Fixtures/CustomValidatorRequest.php | 30 +++++++++++++++++++ tests/Fixtures/TestController.php | 5 ++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/Fixtures/CustomValidatorRequest.php diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index f86e6f2c..9faa7485 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Request; use League\Fractal\Resource\Collection; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Contracts\Validation\Factory as ValidationFactory; class LaravelGenerator extends AbstractGenerator { @@ -266,7 +267,8 @@ protected function getRouteRules($route, $bindings) $parameterReflection->request->add($bindings); if (method_exists($parameterReflection, 'validator')) { - return app()->call([$parameterReflection, 'validator']) + $factory = app()->make(ValidationFactory::class); + return app()->call([$parameterReflection, 'validator'], [$factory]) ->getRules(); } else { return app()->call([$parameterReflection, 'rules']); diff --git a/tests/ApiDocGeneratorTest.php b/tests/ApiDocGeneratorTest.php index e9009399..2d4926c5 100644 --- a/tests/ApiDocGeneratorTest.php +++ b/tests/ApiDocGeneratorTest.php @@ -337,6 +337,16 @@ public function testCanParseFormRequestRules() } } + public function testCustomFormRequestValidatorIsSupported() + { + RouteFacade::post('/post', TestController::class.'@customFormRequestValidator'); + $route = new Route(['POST'], '/post', ['uses' => TestController::class.'@customFormRequestValidator']); + $parsed = $this->generator->processRoute($route); + $parameters = $parsed['parameters']; + + $this->assertNotEmpty($parameters); + } + public function testCanParseResponseTag() { RouteFacade::post('/responseTag', TestController::class.'@responseTag'); diff --git a/tests/Fixtures/CustomValidatorRequest.php b/tests/Fixtures/CustomValidatorRequest.php new file mode 100644 index 00000000..9ce53682 --- /dev/null +++ b/tests/Fixtures/CustomValidatorRequest.php @@ -0,0 +1,30 @@ +make( + $this->validationData(), $this->container->call([$this, 'foo']), + $this->messages(), $this->attributes() + ); + } + + public function foo() + { + return [ + 'required' => 'required', + ]; + } +} diff --git a/tests/Fixtures/TestController.php b/tests/Fixtures/TestController.php index 1f3be0d6..c9abc8b7 100644 --- a/tests/Fixtures/TestController.php +++ b/tests/Fixtures/TestController.php @@ -27,6 +27,11 @@ public function parseFormRequestRules(TestRequest $request) return ''; } + public function customFormRequestValidator(CustomValidatorRequest $request) + { + return ''; + } + public function addRouteBindingsToRequestClass(DynamicRequest $request) { return ''; From bc27ba4de20cebae977be2cc9b772ee6e44c7a48 Mon Sep 17 00:00:00 2001 From: Gustavo Real Date: Tue, 10 Oct 2017 17:38:38 +0100 Subject: [PATCH 013/655] fix code style --- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index 9faa7485..a6f6ebd2 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -268,6 +268,7 @@ protected function getRouteRules($route, $bindings) if (method_exists($parameterReflection, 'validator')) { $factory = app()->make(ValidationFactory::class); + return app()->call([$parameterReflection, 'validator'], [$factory]) ->getRules(); } else { From f8564b60ff0b54c9a57a4cc943055ec0a13f7e5d Mon Sep 17 00:00:00 2001 From: Bogdan Shtybin Date: Thu, 28 Dec 2017 19:30:25 +0200 Subject: [PATCH 014/655] Added Subdomain API Router Support --- .../ApiDoc/Commands/GenerateDocumentation.php | 17 +++++++---- .../ApiDoc/Generators/AbstractGenerator.php | 7 +++++ .../ApiDoc/Generators/DingoGenerator.php | 8 ++++++ .../ApiDoc/Generators/LaravelGenerator.php | 28 +++++++++++++++---- 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index 857be1ca..0ff9bb07 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -22,6 +22,7 @@ class GenerateDocumentation extends Command */ protected $signature = 'api:generate {--output=public/docs : The output path for the generated documentation} + {--routeDomain= : The route domain to use for generation} {--routePrefix= : The route prefix to use for generation} {--routes=* : The route names to use for generation} {--middleware= : The middleware to use for generation} @@ -68,13 +69,14 @@ public function handle() } $allowedRoutes = $this->option('routes'); + $routeDomain = $this->option('routeDomain'); $routePrefix = $this->option('routePrefix'); $middleware = $this->option('middleware'); $this->setUserToBeImpersonated($this->option('actAsUserId')); - 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.'); + if ($routePrefix === null && $routeDomain === null && ! count($allowedRoutes) && $middleware === null) { + $this->error('You must provide either a route prefix or a route domain a route or a middleware to generate the documentation.'); return false; } @@ -82,8 +84,9 @@ public function handle() $generator->prepareMiddleware($this->option('useMiddlewares')); if ($this->option('router') === 'laravel') { - $parsedRoutes = $this->processLaravelRoutes($generator, $allowedRoutes, $routePrefix, $middleware); + $parsedRoutes = $this->processLaravelRoutes($generator, $allowedRoutes, $routeDomain, $routePrefix, $middleware); } else { + // TODO: implement Dingo domain route filter $parsedRoutes = $this->processDingoRoutes($generator, $allowedRoutes, $routePrefix, $middleware); } $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sort(function ($a, $b) { @@ -248,18 +251,22 @@ private function getRoutes() /** * @param AbstractGenerator $generator * @param $allowedRoutes + * @param $routeDomain * @param $routePrefix * * @return array */ - private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix, $middleware) + private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routeDomain, $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, $generator->getUri($route)) || in_array($middleware, $route->middleware())) { + if (in_array($route->getName(), $allowedRoutes) + || str_is($routeDomain, $generator->getDomain($route)) + || str_is($routePrefix, $generator->getUri($route)) + || in_array($middleware, $route->middleware())) { if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { $parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse); $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index b4efdcbc..b1452a91 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -14,6 +14,13 @@ abstract class AbstractGenerator { + /** + * @param $route + * + * @return mixed + */ + abstract public function getDomain($route); + /** * @param $route * diff --git a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php index d85ac8c4..cd741bb5 100644 --- a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php @@ -68,6 +68,14 @@ public function callRoute($method, $uri, $parameters = [], $cookies = [], $files return call_user_func_array([$dispatcher, strtolower($method)], [$uri]); } + /** + * {@inheritdoc} + */ + public function getDomain($route) + { + return $route->uri(); + } + /** * {@inheritdoc} */ diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index f86e6f2c..92441644 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -2,18 +2,31 @@ namespace Mpociot\ApiDoc\Generators; -use ReflectionClass; -use League\Fractal\Manager; +use Illuminate\Foundation\Http\FormRequest; use Illuminate\Routing\Route; -use League\Fractal\Resource\Item; +use Illuminate\Routing\RouteUrlGenerator; use Illuminate\Support\Facades\App; -use Mpociot\Reflection\DocBlock\Tag; use Illuminate\Support\Facades\Request; +use Illuminate\Support\Facades\URL; +use League\Fractal\Manager; use League\Fractal\Resource\Collection; -use Illuminate\Foundation\Http\FormRequest; +use League\Fractal\Resource\Item; +use Mpociot\Reflection\DocBlock\Tag; +use ReflectionClass; class LaravelGenerator extends AbstractGenerator { + /** + * @param Route $route + * + * @return mixed + */ + public function getDomain($route) + { + return $route->domain(); + } + + /** * @param Route $route * @@ -54,11 +67,16 @@ public function processRoute($route, $bindings = [], $headers = [], $withRespons { $content = ''; + $routeDomain = $route->domain(); $routeAction = $route->getAction(); $routeGroup = $this->getRouteGroup($routeAction['uses']); $routeDescription = $this->getRouteDescription($routeAction['uses']); $showresponse = null; + // set correct route domain + $headers[] = "HTTP_HOST: {$routeDomain}"; + $headers[] = "SERVER_NAME: {$routeDomain}"; + if ($withResponse) { $response = null; $docblockResponse = $this->getDocblockResponse($routeDescription['tags']); From e852f6b439ad0e62dbb91425fae1623f74f2d5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20=C5=9Amiarowski?= Date: Wed, 3 Jan 2018 07:41:32 +0100 Subject: [PATCH 015/655] Memory leak, too many connections to SQL --- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index f86e6f2c..fa729b15 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -140,11 +140,6 @@ public function callRoute($method, $uri, $parameters = [], $cookies = [], $files $kernel->terminate($request, $response); - if (file_exists($file = App::bootstrapPath().'/app.php')) { - $app = require $file; - $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap(); - } - return $response; } From 4aab1b4498627d87bad3497f1c3bec95b935513c Mon Sep 17 00:00:00 2001 From: Fongoh Martin Date: Wed, 3 Jan 2018 11:51:07 +0200 Subject: [PATCH 016/655] Removed duplicate words(typo) from the sentence (#249) Initially had As of as of Larave ... so removed one of the as of so that the language is fluent. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 57a202d8..a41cdc2b 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ The generator automatically creates a Postman collection file, which you can imp If you don't want to create a Postman collection, use the `--noPostmanCollection` option, when generating the API documentation. -As of as of Laravel 5.3, the default base URL added to the Postman collection will be that found in your Laravel `config/app.php` file. This will likely be `http://localhost`. If you wish to change this setting you can directly update the url or link this config value to your environment file to make it more flexible (as shown below): +As of Laravel 5.3, the default base URL added to the Postman collection will be that found in your Laravel `config/app.php` file. This will likely be `http://localhost`. If you wish to change this setting you can directly update the url or link this config value to your environment file to make it more flexible (as shown below): ```php 'url' => env('APP_URL', 'http://yourappdefault.app/'), From fe58fa263b14165eb4cfcf072ca933e83ac966df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Lajos?= Date: Wed, 3 Jan 2018 10:51:47 +0100 Subject: [PATCH 017/655] Fixed flat design for StyleCI shield. (#244) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a41cdc2b..fb9e8f21 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Automatically generate your API documentation from your existing Laravel routes. [![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)](https://styleci.io/repos/57999295) +[![StyleCI](https://styleci.io/repos/57999295/shield?style=flat)](https://styleci.io/repos/57999295) [![Dependency Status](https://www.versioneye.com/php/mpociot:laravel-apidoc-generator/dev-master/badge?style=flat)](https://www.versioneye.com/php/mpociot:laravel-apidoc-generator/dev-master) From 4a78f3db0f5c5d0c87e4a64d33809091f1ec8b56 Mon Sep 17 00:00:00 2001 From: Fabien SOMNIER Date: Wed, 3 Jan 2018 09:52:42 +0000 Subject: [PATCH 018/655] [BUGFIXES] Header containing ":" + invalid "showresponse" condition (#242) * [BUGFIX] Header containing ":" values management * [CHANGE] To pass styleci.io tests * [BUGFIX] Invalid condition test to display response --- src/Mpociot/ApiDoc/Generators/AbstractGenerator.php | 6 ++++-- src/resources/views/partials/route.blade.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index b4efdcbc..313883f4 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -112,9 +112,11 @@ protected function getRouteResponse($route, $bindings, $headers = []) // Split headers into key - value pairs $headers = collect($headers)->map(function ($value) { - $split = explode(':', $value); + $split = explode(':', $value); // explode to get key + values + $key = array_shift($split); // extract the key and keep the values in the array + $value = implode(':', $split); // implode values into string again - return [trim($split[0]) => trim($split[1])]; + return [trim($key) => trim($value)]; })->collapse()->toArray(); //Changes url with parameters like /users/{user} to /users/1 diff --git a/src/resources/views/partials/route.blade.php b/src/resources/views/partials/route.blade.php index f285dc4a..03b4f639 100644 --- a/src/resources/views/partials/route.blade.php +++ b/src/resources/views/partials/route.blade.php @@ -38,7 +38,7 @@ }); ``` -@if(in_array('GET',$parsedRoute['methods']) || isset($parsedRoute['showresponse']) && $parsedRoute['showresponse']) +@if(in_array('GET',$parsedRoute['methods']) || (isset($parsedRoute['showresponse']) && $parsedRoute['showresponse'])) > Example response: ```json From 8917ca4c968867ba370ef9c24298ffa4d05f7ec2 Mon Sep 17 00:00:00 2001 From: Jonathan JEAN Date: Wed, 3 Jan 2018 10:53:18 +0100 Subject: [PATCH 019/655] Laravel 5.5 auto-discovery (#217) * Laravel 5.5 auto-discovery * Removing extra trailing comma --- composer.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/composer.json b/composer.json index 086555c6..c4ce211d 100644 --- a/composer.json +++ b/composer.json @@ -37,5 +37,12 @@ "psr-4": { "Mpociot\\ApiDoc\\Tests\\": "tests/" } + }, + "extra": { + "laravel": { + "providers": [ + "Mpociot\\ApiDoc\\ApiDocGeneratorServiceProvider" + ] + } } } From e8021d243f62cb83073c23ae4ae8b9c82484b433 Mon Sep 17 00:00:00 2001 From: antimech Date: Wed, 3 Jan 2018 15:54:02 +0600 Subject: [PATCH 020/655] Update README.md (#226) README.md ready for 5.5! --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb9e8f21..203b45f7 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Require this package with composer using the following command: ```sh $ composer require mpociot/laravel-apidoc-generator ``` -Go to your `config/app.php` and add the service provider: +Using Laravel < 5.5? Go to your `config/app.php` and add the service provider: ```php Mpociot\ApiDoc\ApiDocGeneratorServiceProvider::class, From 0925f838047284955f00fab2dd1e8956cba24dfa Mon Sep 17 00:00:00 2001 From: Sergei Belyakov Date: Wed, 3 Jan 2018 11:54:19 +0200 Subject: [PATCH 021/655] Update README.md (#224) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 203b45f7..1452ea73 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ 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|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'` +`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. From 70fd369b61615d590d4f57ca3d305f5ec53aa3b0 Mon Sep 17 00:00:00 2001 From: Rafael Villa-Verde Date: Fri, 5 Jan 2018 13:55:02 -0200 Subject: [PATCH 022/655] remove --actAsUserId parameter conversion to int --- src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index 857be1ca..9ceb59a0 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -222,12 +222,12 @@ private function setUserToBeImpersonated($actAs) if (! empty($actAs)) { if (version_compare($this->laravel->version(), '5.2.0', '<')) { $userModel = config('auth.model'); - $user = $userModel::find((int) $actAs); + $user = $userModel::find($actAs); $this->laravel['auth']->setUser($user); } else { $provider = $this->option('authProvider'); $userModel = config("auth.providers.$provider.model"); - $user = $userModel::find((int) $actAs); + $user = $userModel::find($actAs); $this->laravel['auth']->guard($this->option('authGuard'))->setUser($user); } } From 5f8c5b505cd5ba991f2b995557e5bfcb02840672 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 15 Feb 2018 17:46:49 +1100 Subject: [PATCH 023/655] allow formatting and aside tags The group description was escaping everything by default meaning that the aside tag (which is quite useful) can't be used in a group header. This addresses that by no longer escaping the content, as is consistent with the rest of the library. --- src/resources/views/documentarian.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/views/documentarian.blade.php b/src/resources/views/documentarian.blade.php index 9e2a136a..6d7a3c24 100644 --- a/src/resources/views/documentarian.blade.php +++ b/src/resources/views/documentarian.blade.php @@ -7,7 +7,7 @@ @foreach($parsedRoutes as $group => $routes) @if($group) -#{{$group}} +#{!! $group !!} @endif @foreach($routes as $parsedRoute) @if($writeCompareFile === true) From 9d20bd6d7058f2d984e4b633d45c696e8d40326d Mon Sep 17 00:00:00 2001 From: sempixel Date: Mon, 12 Mar 2018 16:16:53 +0100 Subject: [PATCH 024/655] Correct JSON format for @response --- src/Mpociot/ApiDoc/Generators/AbstractGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index 313883f4..bf904b54 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -67,7 +67,7 @@ protected function getDocblockResponse($tags) } $responseTag = \array_first($responseTags); - return \response(\json_encode($responseTag->getContent())); + return \response($responseTag->getContent(), 200, ['content-type' => 'application/json']); } /** From c557ca970ad67794c046f0967be415addcb0faa8 Mon Sep 17 00:00:00 2001 From: sempixel Date: Mon, 12 Mar 2018 17:27:35 +0100 Subject: [PATCH 025/655] =?UTF-8?q?We=20have=20to=20go=20deeper=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Mpociot/ApiDoc/Generators/AbstractGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index bf904b54..8e5a2f79 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -67,7 +67,7 @@ protected function getDocblockResponse($tags) } $responseTag = \array_first($responseTags); - return \response($responseTag->getContent(), 200, ['content-type' => 'application/json']); + return \response(json_encode($responseTag->getContent()), 200, ['Content-Type' => 'application/json']); } /** From 460d221a075f7dd0ab5dfb913753b1c049dbb558 Mon Sep 17 00:00:00 2001 From: sempixel Date: Mon, 12 Mar 2018 17:28:17 +0100 Subject: [PATCH 026/655] Fix test --- tests/ApiDocGeneratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ApiDocGeneratorTest.php b/tests/ApiDocGeneratorTest.php index e9009399..9cee1f79 100644 --- a/tests/ApiDocGeneratorTest.php +++ b/tests/ApiDocGeneratorTest.php @@ -345,7 +345,7 @@ public function testCanParseResponseTag() $this->assertTrue(is_array($parsed)); $this->assertArrayHasKey('showresponse', $parsed); $this->assertTrue($parsed['showresponse']); - $this->assertSame($parsed['response'], '"{\n data: [],\n}"'); + $this->assertSame($parsed['response'], "{\n data: [],\n}"); } public function testCanParseTransformerTag() From fbdc6033b8c73037683a1494e60233f21d6598fb Mon Sep 17 00:00:00 2001 From: sempixel Date: Mon, 12 Mar 2018 17:35:09 +0100 Subject: [PATCH 027/655] =?UTF-8?q?Too=20fast=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index f86e6f2c..0330d78a 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -79,7 +79,7 @@ public function processRoute($route, $bindings = [], $headers = [], $withRespons $response = $this->getRouteResponse($route, $bindings, $headers); } if ($response->headers->get('Content-Type') === 'application/json') { - $content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT); + $content = json_decode($response->getContent(), JSON_PRETTY_PRINT); } else { $content = $response->getContent(); } From 0dcb277043cca4731285fc7986afeddad7850514 Mon Sep 17 00:00:00 2001 From: vagrant Date: Sat, 14 Apr 2018 12:41:33 +0000 Subject: [PATCH 028/655] Make generator only fetch response from route if method is GET --- src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index 857be1ca..24726428 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -261,7 +261,7 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout foreach ($routes as $route) { if (in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $generator->getUri($route)) || in_array($middleware, $route->middleware())) { if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { - $parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse); + $parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse && in_array('GET', $generator->getMethods($route))); $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); } else { $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); From 831fe37dc1e5f460ba1d2f80ef9ac4a9c20ee8fb Mon Sep 17 00:00:00 2001 From: Amir Hossein Babaeian Date: Sun, 5 Aug 2018 16:36:20 +0430 Subject: [PATCH 029/655] updating route-model-binding binding technique and preparing middlewares --- src/Mpociot/ApiDoc/Generators/AbstractGenerator.php | 5 +++-- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 9 ++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index 313883f4..7b357501 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -44,7 +44,7 @@ abstract public function processRoute($route, $bindings = [], $withResponse = tr * * @return void */ - abstract public function prepareMiddleware($disable = false); + abstract public function prepareMiddleware($enable = false); /** * Get the response from the docblock if available. @@ -120,7 +120,7 @@ protected function getRouteResponse($route, $bindings, $headers = []) })->collapse()->toArray(); //Changes url with parameters like /users/{user} to /users/1 - $uri = preg_replace('/{(.*?)}/', 1, $uri); + $uri = preg_replace('/{(.*?)}/', 1, $uri); // 1 is the default value for route parameters return $this->callRoute(array_shift($methods), $uri, [], [], [], $headers); } @@ -136,6 +136,7 @@ protected function addRouteModelBindings($route, $bindings) $uri = $this->getUri($route); foreach ($bindings as $model => $id) { $uri = str_replace('{'.$model.'}', $id, $uri); + $uri = str_replace('{'.$model.'?}', $id, $uri); } return $uri; diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index f86e6f2c..b9ec284d 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -105,9 +105,9 @@ public function processRoute($route, $bindings = [], $headers = [], $withRespons * * @return void */ - public function prepareMiddleware($disable = true) + public function prepareMiddleware($enable = true) { - App::instance('middleware.disable', true); + App::instance('middleware.disable', !$enable); } /** @@ -140,11 +140,6 @@ public function callRoute($method, $uri, $parameters = [], $cookies = [], $files $kernel->terminate($request, $response); - if (file_exists($file = App::bootstrapPath().'/app.php')) { - $app = require $file; - $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap(); - } - return $response; } From fdca5eeeb1e8b91af0240c670abd116705155284 Mon Sep 17 00:00:00 2001 From: Tihomir Tonov Date: Tue, 14 Aug 2018 16:33:11 +0300 Subject: [PATCH 030/655] Add method to generate validation rules for nested array properties --- .../ApiDoc/Generators/AbstractGenerator.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index 313883f4..90bbb5f1 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -79,8 +79,9 @@ protected function getDocblockResponse($tags) */ protected function getParameters($routeData, $routeAction, $bindings) { - $validator = Validator::make([], $this->getRouteRules($routeAction['uses'], $bindings)); - foreach ($validator->getRules() as $attribute => $rules) { + $rules = $this->simplifyRules($this->getRouteRules($routeAction['uses'], $bindings)); + + foreach ($rules as $attribute => $rules) { $attributeData = [ 'required' => false, 'type' => null, @@ -88,6 +89,7 @@ protected function getParameters($routeData, $routeAction, $bindings) 'value' => '', 'description' => [], ]; + foreach ($rules as $ruleName => $rule) { $this->parseRule($rule, $attribute, $attributeData, $routeData['id']); } @@ -97,6 +99,30 @@ protected function getParameters($routeData, $routeAction, $bindings) return $routeData; } + /** + * Format the validation rules as plain array + * + * @param array $rules + * @return array + */ + protected function simplifyRules($rules) + { + $simplifiedRules = Validator::make([], $rules)->getRules(); + + if (count($simplifiedRules) === 0) { + return $simplifiedRules; + } + + $values = collect($simplifiedRules) + ->filter(function ($values) { + return in_array('array', $values); + })->map(function ($val, $key) { + return ['']; + })->all(); + + return Validator::make($values, $rules)->getRules(); + } + /** * @param $route * @param $bindings From 6bb9a8cf479062545fda88d6d15a82b13e529e87 Mon Sep 17 00:00:00 2001 From: Tihomir Tonov Date: Tue, 14 Aug 2018 16:40:25 +0300 Subject: [PATCH 031/655] Remove linting option as depricated in style CI --- .styleci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 2fe66ad1..75bf3532 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -4,5 +4,3 @@ enabled: - phpdoc_order - phpdoc_separation - unalign_double_arrow - -linting: true From d6e7e79aedeeb616e3ca38cb8d694e63fb97f71c Mon Sep 17 00:00:00 2001 From: Tihomir Tonov Date: Tue, 14 Aug 2018 16:43:56 +0300 Subject: [PATCH 032/655] Fix style violation --- src/Mpociot/ApiDoc/Generators/AbstractGenerator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index 90bbb5f1..327a76c0 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -100,9 +100,10 @@ protected function getParameters($routeData, $routeAction, $bindings) } /** - * Format the validation rules as plain array + * Format the validation rules as plain array. * * @param array $rules + * * @return array */ protected function simplifyRules($rules) From 0fce50f42199ee5f8964babd6c5722c4174dd02c Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Fri, 7 Sep 2018 09:54:12 +0000 Subject: [PATCH 033/655] Apply fixes from StyleCI --- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index 8b1c6444..20659abf 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -107,7 +107,7 @@ public function processRoute($route, $bindings = [], $headers = [], $withRespons */ public function prepareMiddleware($enable = true) { - App::instance('middleware.disable', !$enable); + App::instance('middleware.disable', ! $enable); } /** From afeca2faf71529fd94ce08ef44a2513b1d277ea5 Mon Sep 17 00:00:00 2001 From: Shalvah A Date: Fri, 7 Sep 2018 11:05:27 +0100 Subject: [PATCH 034/655] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ede1f974..3ffc3539 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ To generate your API documentation, use the `api:generate` artisan command. ```sh $ php artisan api:generate --routePrefix="api/v1/*" -``` -After 28ff33be15424ff5a5b819dbe88b34468d1752b2 this commit, it supports passing generation of multiple prefixes by spearating each prefix with comma. +``` +You can pass in multiple prefixes by spearating each prefix with comma. ```sh $ php artisan api:generate --routePrefix="api/v1/*,api/public/*" From 2830ae485a320db85dfe918ba949736196c5f1cd Mon Sep 17 00:00:00 2001 From: Shalvah A Date: Sun, 9 Sep 2018 02:10:58 +0100 Subject: [PATCH 035/655] Update DingoGenerator.php --- src/Mpociot/ApiDoc/Generators/DingoGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php index cd741bb5..30f865e1 100644 --- a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php @@ -73,7 +73,7 @@ public function callRoute($method, $uri, $parameters = [], $cookies = [], $files */ public function getDomain($route) { - return $route->uri(); + return $route->domain(); } /** From ac70e500bf501869b47b7c22659c286e963fad69 Mon Sep 17 00:00:00 2001 From: Shalvah A Date: Sun, 9 Sep 2018 02:41:59 +0100 Subject: [PATCH 036/655] Change error message for when neither of required options is supplied --- src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index 0991347e..eb49f0b8 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -76,7 +76,7 @@ public function handle() $this->setUserToBeImpersonated($this->option('actAsUserId')); if ($routePrefix === null && $routeDomain === null && ! count($allowedRoutes) && $middleware === null) { - $this->error('You must provide either a route prefix or a route domain or a middleware to generate the documentation.'); + $this->error('You must provide either a route prefix, a route domain, a route or a middleware to generate the documentation.'); return false; } From 32620365fba71cd729c3e2d5b79360fadb9a9732 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Sun, 9 Sep 2018 01:44:31 +0000 Subject: [PATCH 037/655] Apply fixes from StyleCI --- .../ApiDoc/Commands/GenerateDocumentation.php | 8 ++++---- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 13 +++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index eb49f0b8..826fcfde 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -272,7 +272,7 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout $parsedRoutes = []; foreach ($routes as $route) { if (in_array($route->getName(), $allowedRoutes) - || (str_is($routeDomain, $generator->getDomain($route)) + || (str_is($routeDomain, $generator->getDomain($route)) && str_is($routePrefix, $generator->getUri($route))) || in_array($middleware, $route->middleware()) ) { @@ -303,11 +303,11 @@ private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes $bindings = $this->getBindings(); $parsedRoutes = []; foreach ($routes as $route) { - if (empty($allowedRoutes) + if (empty($allowedRoutes) // TODO extract this into a method || in_array($route->getName(), $allowedRoutes) - || (str_is($routeDomain, $generator->getDomain($route)) - && str_is($routePrefix, $generator->getUri($route))) + || (str_is($routeDomain, $generator->getDomain($route)) + && str_is($routePrefix, $generator->getUri($route))) || in_array($middleware, $route->middleware()) ) { if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index 2571ac10..60330f59 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -2,17 +2,15 @@ namespace Mpociot\ApiDoc\Generators; -use Illuminate\Foundation\Http\FormRequest; +use ReflectionClass; +use League\Fractal\Manager; use Illuminate\Routing\Route; -use Illuminate\Routing\RouteUrlGenerator; +use League\Fractal\Resource\Item; use Illuminate\Support\Facades\App; +use Mpociot\Reflection\DocBlock\Tag; use Illuminate\Support\Facades\Request; -use Illuminate\Support\Facades\URL; -use League\Fractal\Manager; use League\Fractal\Resource\Collection; -use League\Fractal\Resource\Item; -use Mpociot\Reflection\DocBlock\Tag; -use ReflectionClass; +use Illuminate\Foundation\Http\FormRequest; class LaravelGenerator extends AbstractGenerator { @@ -26,7 +24,6 @@ public function getDomain($route) return $route->domain(); } - /** * @param Route $route * From f92322729814a39a379233dd7c2d44d0720630ec Mon Sep 17 00:00:00 2001 From: shalvah Date: Sun, 9 Sep 2018 20:29:10 +0100 Subject: [PATCH 038/655] Update tests, ignore IDE files --- .gitignore | 3 +++ .travis.yml | 4 ++-- composer.json | 3 +++ tests/GenerateDocumentationTest.php | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 338893d3..8532760a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ composer.lock .php_cs.cache /vendor/ /public +.idea/ +coverage.xml +results.xml diff --git a/.travis.yml b/.travis.yml index dd082e4c..36f2c9ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,10 +10,10 @@ before_script: - travis_retry composer install --prefer-dist --no-interaction script: - - vendor/bin/phpunit --coverage-clover=coverage.xml + - composer test-ci before_install: - pip install --user codecov after_success: - - codecov \ No newline at end of file + - codecov diff --git a/composer.json b/composer.json index c4ce211d..a7fa4a08 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,9 @@ "Mpociot\\ApiDoc\\Tests\\": "tests/" } }, + "scripts": { + "test-ci": "phpunit --coverage-clover=coverage.xml" + }, "extra": { "laravel": { "providers": [ diff --git a/tests/GenerateDocumentationTest.php b/tests/GenerateDocumentationTest.php index 41cf492e..09af58a7 100644 --- a/tests/GenerateDocumentationTest.php +++ b/tests/GenerateDocumentationTest.php @@ -51,7 +51,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 or a middleware to generate the documentation.'.PHP_EOL, $output); + $this->assertEquals('You must provide either a route prefix, a route domain, a route or a middleware to generate the documentation.'.PHP_EOL, $output); } public function testConsoleCommandDoesNotWorkWithClosure() From 2c4ba45935ba418abfd30fadd41c252561529975 Mon Sep 17 00:00:00 2001 From: shalvah Date: Sun, 9 Sep 2018 21:14:42 +0100 Subject: [PATCH 039/655] Add changelog --- CHANGELOG.md | 38 ++++++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..dfc8e8bb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,38 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). If you make a pull request to this project, please update this changelog. + +## Unreleased +### Added + +### Changed + +### Fixed + +### Removed + +## [2.1.0] - 2018-09-00 +### Added +- Added support for multiple route domains (https://github.com/mpociot/laravel-apidoc-generator/pull/255) +- Added support for descriptions in custom validation rules (https://github.com/mpociot/laravel-apidoc-generator/pull/208) +- Added support for multiple route prefixes (https://github.com/mpociot/laravel-apidoc-generator/pull/203) +- Added support for formatting and `