@@ -22,7 +22,8 @@ class GenerateDocumentation extends Command
2222 */
2323 protected $ signature = 'api:generate
2424 {--output=public/docs : The output path for the generated documentation}
25- {--routePrefix= : The route prefix to use for generation}
25+ {--routeDomain= : The route domain (or domains) to use for generation}
26+ {--routePrefix= : The route prefix (or prefixes) to use for generation}
2627 {--routes=* : The route names to use for generation}
2728 {--middleware= : The middleware to use for generation}
2829 {--noResponseCalls : Disable API response calls}
@@ -68,30 +69,36 @@ public function handle()
6869 }
6970
7071 $ allowedRoutes = $ this ->option ('routes ' );
72+ $ routeDomain = $ this ->option ('routeDomain ' );
7173 $ routePrefix = $ this ->option ('routePrefix ' );
7274 $ middleware = $ this ->option ('middleware ' );
7375
7476 $ this ->setUserToBeImpersonated ($ this ->option ('actAsUserId ' ));
7577
76- if ($ routePrefix === null && ! count ($ allowedRoutes ) && $ middleware === null ) {
77- $ this ->error ('You must provide either a route prefix or a route or a middleware to generate the documentation. ' );
78+ if ($ routePrefix === null && $ routeDomain === null && ! count ($ allowedRoutes ) && $ middleware === null ) {
79+ $ this ->error ('You must provide either a route prefix, a route domain, a route or a middleware to generate the documentation. ' );
7880
7981 return false ;
8082 }
8183
8284 $ generator ->prepareMiddleware ($ this ->option ('useMiddlewares ' ));
8385
84- $ routePrefixes = explode (', ' , $ routePrefix );
86+ $ routePrefixes = explode (', ' , $ routePrefix ?: '* ' );
87+ $ routeDomains = explode (', ' , $ routeDomain ?: '* ' );
8588
8689 $ parsedRoutes = [];
8790
8891 if ($ this ->option ('router ' ) === 'laravel ' ) {
89- foreach ($ routePrefixes as $ routePrefix ) {
90- $ parsedRoutes += $ this ->processLaravelRoutes ($ generator , $ allowedRoutes , $ routePrefix , $ middleware );
92+ foreach ($ routeDomains as $ routeDomain ) {
93+ foreach ($ routePrefixes as $ routePrefix ) {
94+ $ parsedRoutes += $ this ->processLaravelRoutes ($ generator , $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware );
95+ }
9196 }
9297 } else {
93- foreach ($ routePrefixes as $ routePrefix ) {
94- $ parsedRoutes += $ this ->processDingoRoutes ($ generator , $ allowedRoutes , $ routePrefix , $ middleware );
98+ foreach ($ routeDomains as $ routeDomain ) {
99+ foreach ($ routePrefixes as $ routePrefix ) {
100+ $ parsedRoutes += $ this ->processDingoRoutes ($ generator , $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware );
101+ }
95102 }
96103 }
97104 $ parsedRoutes = collect ($ parsedRoutes )->groupBy ('resource ' )->sort (function ($ a , $ b ) {
@@ -252,18 +259,23 @@ private function getRoutes()
252259 /**
253260 * @param AbstractGenerator $generator
254261 * @param $allowedRoutes
262+ * @param $routeDomain
255263 * @param $routePrefix
256264 *
257265 * @return array
258266 */
259- private function processLaravelRoutes (AbstractGenerator $ generator , $ allowedRoutes , $ routePrefix , $ middleware )
267+ private function processLaravelRoutes (AbstractGenerator $ generator , $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware )
260268 {
261269 $ withResponse = $ this ->option ('noResponseCalls ' ) === false ;
262270 $ routes = $ this ->getRoutes ();
263271 $ bindings = $ this ->getBindings ();
264272 $ parsedRoutes = [];
265273 foreach ($ routes as $ route ) {
266- if (in_array ($ route ->getName (), $ allowedRoutes ) || str_is ($ routePrefix , $ generator ->getUri ($ route )) || in_array ($ middleware , $ route ->middleware ())) {
274+ if (in_array ($ route ->getName (), $ allowedRoutes )
275+ || (str_is ($ routeDomain , $ generator ->getDomain ($ route ))
276+ && str_is ($ routePrefix , $ generator ->getUri ($ route )))
277+ || in_array ($ middleware , $ route ->middleware ())
278+ ) {
267279 if ($ this ->isValidRoute ($ route ) && $ this ->isRouteVisibleForDocumentation ($ route ->getAction ()['uses ' ])) {
268280 $ parsedRoutes [] = $ generator ->processRoute ($ route , $ bindings , $ this ->option ('header ' ), $ withResponse );
269281 $ this ->info ('Processed route: [ ' .implode (', ' , $ generator ->getMethods ($ route )).'] ' .$ generator ->getUri ($ route ));
@@ -279,18 +291,25 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout
279291 /**
280292 * @param AbstractGenerator $generator
281293 * @param $allowedRoutes
294+ * @param $routeDomain
282295 * @param $routePrefix
283296 *
284297 * @return array
285298 */
286- private function processDingoRoutes (AbstractGenerator $ generator , $ allowedRoutes , $ routePrefix , $ middleware )
299+ private function processDingoRoutes (AbstractGenerator $ generator , $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware )
287300 {
288301 $ withResponse = $ this ->option ('noResponseCalls ' ) === false ;
289302 $ routes = $ this ->getRoutes ();
290303 $ bindings = $ this ->getBindings ();
291304 $ parsedRoutes = [];
292305 foreach ($ routes as $ route ) {
293- if (empty ($ allowedRoutes ) || in_array ($ route ->getName (), $ allowedRoutes ) || str_is ($ routePrefix , $ route ->uri ()) || in_array ($ middleware , $ route ->middleware ())) {
306+ if (empty ($ allowedRoutes )
307+ // TODO extract this into a method
308+ || in_array ($ route ->getName (), $ allowedRoutes )
309+ || (str_is ($ routeDomain , $ generator ->getDomain ($ route ))
310+ && str_is ($ routePrefix , $ generator ->getUri ($ route )))
311+ || in_array ($ middleware , $ route ->middleware ())
312+ ) {
294313 if ($ this ->isValidRoute ($ route ) && $ this ->isRouteVisibleForDocumentation ($ route ->getAction ()['uses ' ])) {
295314 $ parsedRoutes [] = $ generator ->processRoute ($ route , $ bindings , $ this ->option ('header ' ), $ withResponse );
296315 $ this ->info ('Processed route: [ ' .implode (', ' , $ route ->getMethods ()).'] ' .$ route ->uri ());
0 commit comments