Skip to content

Commit 512cfee

Browse files
committed
Add route filtering
1 parent 16c298f commit 512cfee

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/GenerateSwaggerDoc.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class GenerateSwaggerDoc extends Command
1212
* @var string
1313
*/
1414
protected $signature = 'laravel-swagger:generate
15-
{--format=json : The format of the output, current options are json and yaml}';
15+
{--format=json : The format of the output, current options are json and yaml}
16+
{--filter= : Filter to a specific route prefix, such as /api or /v2/api}';
1617

1718
/**
1819
* The console command description.
@@ -30,7 +31,7 @@ public function handle()
3031
{
3132
$config = config('laravel-swagger');
3233

33-
$docs = (new Generator($config))->generate();
34+
$docs = (new Generator($config, $this->option('filter') ?: null))->generate();
3435

3536
$formattedDocs = (new FormatterManager($docs))
3637
->setFormat($this->option('format'))

src/Generator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Generator
1111
{
1212
protected $config;
1313

14+
protected $routeFilter;
15+
1416
protected $docs;
1517

1618
protected $uri;
@@ -21,9 +23,10 @@ class Generator
2123

2224
protected $action;
2325

24-
public function __construct($config)
26+
public function __construct($config, $routeFilter = null)
2527
{
2628
$this->config = $config;
29+
$this->routeFilter = $routeFilter;
2730
}
2831

2932
public function generate()
@@ -33,6 +36,11 @@ public function generate()
3336
foreach ($this->getAppRoutes() as $route) {
3437
$this->originalUri = $uri = $this->getRouteUri($route);
3538
$this->uri = strip_optional_char($uri);
39+
40+
if ($this->routeFilter && !preg_match('/^' . preg_quote($this->routeFilter, '/') . '/', $this->uri)) {
41+
continue;
42+
}
43+
3644
$this->action = $route->getAction('uses');
3745
$methods = $route->methods();
3846

0 commit comments

Comments
 (0)