Skip to content

Commit 8b72eae

Browse files
committed
Added 'noResponseCalls' option
1 parent d37e1c8 commit 8b72eae

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Option | Description
4444
`routePrefix` | The route prefix to use for generation - `*` can be used as a wildcard
4545
`routes` | The route names to use for generation - Required if no routePrefix is provided
4646
`actAsUserId` | The user ID to use for authenticated API response calls
47+
`noResponseCalls` | Disable API response calls
48+
`actAsUserId` | The user ID to use for authenticated API response calls
4749
`router` | The router to use, when processing the route files (can be Laravel or Dingo - defaults to Laravel)
4850
`bindings` | List of route bindings that should be replaced when trying to retrieve route results. Syntax format: `binding_one,id|binding_two,id`
4951

@@ -96,6 +98,12 @@ If your API needs an authenticated user, you can use the `actAsUserId` option to
9698
$ php artisan api:generate --routePrefix=api/* --actAsUserId=1
9799
```
98100

101+
If you don't want to automatically perform API response calls, use the `noResponseCalls` option.
102+
103+
```sh
104+
$ php artisan api:generate --routePrefix=api/* --noResponseCalls
105+
```
106+
99107
> Note: The example API responses work best with seeded data.
100108
101109

src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class GenerateDocumentation extends Command
2121
{--output=public/docs : The output path for the generated documentation}
2222
{--routePrefix= : The route prefix to use for generation}
2323
{--routes=* : The route names to use for generation}
24+
{--noResponseCalls : The user ID to use for API response calls}
2425
{--actAsUserId= : The user ID to use for API response calls}
2526
{--router=laravel : The router to be used (Laravel or Dingo)}
2627
{--bindings= : Route Model Bindings}
@@ -163,13 +164,14 @@ private function getRoutes()
163164
*/
164165
private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix)
165166
{
167+
$withResponse = $this->option('noResponseCalls') === false;
166168
$routes = $this->getRoutes();
167169
$bindings = $this->getBindings();
168170
$parsedRoutes = [];
169171
foreach ($routes as $route) {
170172
if (in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $route->getUri())) {
171173
if ($this->isValidRoute($route)) {
172-
$parsedRoutes[] = $generator->processRoute($route, $bindings);
174+
$parsedRoutes[] = $generator->processRoute($route, $bindings, $withResponse);
173175
$this->info('Processed route: '.$route->getUri());
174176
} else {
175177
$this->warn('Skipping route: '.$route->getUri().' - contains closure.');
@@ -189,12 +191,13 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout
189191
*/
190192
private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix)
191193
{
194+
$withResponse = $this->option('noResponseCalls') === false;
192195
$routes = $this->getRoutes();
193196
$bindings = $this->getBindings();
194197
$parsedRoutes = [];
195198
foreach ($routes as $route) {
196199
if (empty($allowedRoutes) || in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $route->uri())) {
197-
$parsedRoutes[] = $generator->processRoute($route, $bindings);
200+
$parsedRoutes[] = $generator->processRoute($route, $bindings, $withResponse);
198201
$this->info('Processed route: '.$route->uri());
199202
}
200203
}

src/Mpociot/ApiDoc/Generators/AbstractGenerator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ abstract protected function getUri($route);
2121
/**
2222
* @param \Illuminate\Routing\Route $route
2323
* @param array $bindings
24-
*
24+
* @param bool $withResponse
25+
*
2526
* @return array
2627
*/
27-
abstract public function processRoute($route, $bindings = []);
28+
abstract public function processRoute($route, $bindings = [], $withResponse = true);
2829

2930
/**
3031
* @param array $routeData

src/Mpociot/ApiDoc/Generators/DingoGenerator.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
class DingoGenerator extends AbstractGenerator
88
{
99
/**
10-
* @param $route
10+
* @param \Illuminate\Routing\Route $route
1111
* @param array $bindings
12-
*
12+
* @param bool $withResponse
13+
*
1314
* @return array
1415
*/
15-
public function processRoute($route, $bindings = [])
16+
public function processRoute($route, $bindings = [], $withResponse = true)
1617
{
17-
try {
18-
$response = $this->getRouteResponse($route, $bindings);
19-
} catch (Exception $e) {
20-
$response = '';
18+
$response = '';
19+
20+
if ($withResponse) {
21+
try {
22+
$response = $this->getRouteResponse($route, $bindings);
23+
} catch (Exception $e) {}
2124
}
25+
2226
$routeAction = $route->getAction();
2327
$routeGroup = $this->getRouteGroup($routeAction['uses']);
2428
$routeDescription = $this->getRouteDescription($routeAction['uses']);

src/Mpociot/ApiDoc/Generators/LaravelGenerator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ protected function getUri($route)
2121
/**
2222
* @param \Illuminate\Routing\Route $route
2323
* @param array $bindings
24+
* @param bool $withResponse
2425
*
2526
* @return array
2627
*/
27-
public function processRoute($route, $bindings = [])
28+
public function processRoute($route, $bindings = [], $withResponse = true)
2829
{
29-
$response = $this->getRouteResponse($route, $bindings);
30+
$response = '';
31+
32+
if ($withResponse) {
33+
$response = $this->getRouteResponse($route, $bindings);
34+
}
3035

3136
$routeAction = $route->getAction();
3237
$routeGroup = $this->getRouteGroup($routeAction['uses']);

0 commit comments

Comments
 (0)