Skip to content

Commit 20e2a1c

Browse files
Merge pull request rakutentech#29 from JustRaviga/fork
Add ability to generate docs only for specific route uri prefix
2 parents 319837e + 2df28b8 commit 20e2a1c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

config/request-docs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
'sort_by' => 'default',
2424

25+
//Use only routes where ->uri start with next string Using Str::startWith( . e.g. - /api/mobile
26+
'only_route_uri_start_with' => '',
27+
2528
'hide_matching' => [
2629
"#^telescope#",
2730
"#^docs#",

src/LaravelRequestDocs.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Rakutentech\LaravelRequestDocs;
44

5+
use ErrorException;
56
use Route;
67
use ReflectionMethod;
78
use Illuminate\Http\Request;
89
use Illuminate\Foundation\Http\FormRequest;
910
use Illuminate\Support\Str;
1011
use Exception;
12+
use Throwable;
1113

1214
class LaravelRequestDocs
1315
{
@@ -76,7 +78,13 @@ public function getControllersInfo(): array
7678
{
7779
$controllersInfo = [];
7880
$routes = collect(Route::getRoutes());
81+
$onlyRouteStartWith = config('request-docs.only_route_uri_start_with') ?? '';
82+
7983
foreach ($routes as $route) {
84+
if($onlyRouteStartWith && !Str::startsWith($route->uri, $onlyRouteStartWith)){
85+
continue;
86+
}
87+
8088
try {
8189
/// Show Pnly Controller Name
8290
$controllerFullPath = explode('@', $route->action['controller'])[0];
@@ -121,13 +129,13 @@ public function appendRequestRules(array $controllersInfo)
121129
$requestClass = null;
122130
try {
123131
$requestClass = new $requestClassName();
124-
} catch (\Throwable $th) {
132+
} catch (Throwable $th) {
125133
//throw $th;
126134
}
127135
if ($requestClass instanceof FormRequest) {
128136
try {
129137
$controllersInfo[$index]['rules'] = $this->flattenRules($requestClass->rules());
130-
} catch (\ErrorException $th) {
138+
} catch (ErrorException $th) {
131139
$controllerInfo[$index]['rules'] = $this->rulesByRegex($requestClassName);
132140
}
133141
$controllersInfo[$index]['docBlock'] = $this->lrdDocComment($reflectionMethod->getDocComment());

0 commit comments

Comments
 (0)