File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff 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 ' ))
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments