diff --git a/src/GeneratorConfig.php b/src/GeneratorConfig.php index 6a852ac1..39109d98 100644 --- a/src/GeneratorConfig.php +++ b/src/GeneratorConfig.php @@ -14,12 +14,6 @@ public function __construct( private ?Closure $routeResolver = null, private ?Closure $afterOpenApiGenerated = null, ) { - $this->routeResolver = $this->routeResolver ?: function (Route $route) { - $expectedDomain = $this->get('api_domain'); - - return Str::startsWith($route->uri, $this->get('api_path', 'api')) - && (! $expectedDomain || $route->getDomain() === $expectedDomain); - }; } public function config(array $config) @@ -32,7 +26,7 @@ public function config(array $config) public function routes(?Closure $routeResolver = null) { if (count(func_get_args()) === 0) { - return $this->routeResolver; + return $this->routeResolver ?: $this->defaultRoutesFilter(...); } if ($routeResolver) { @@ -42,6 +36,14 @@ public function routes(?Closure $routeResolver = null) return $this; } + private function defaultRoutesFilter(Route $route) + { + $expectedDomain = $this->get('api_domain'); + + return Str::startsWith($route->uri, $this->get('api_path', 'api')) + && (! $expectedDomain || $route->getDomain() === $expectedDomain); + } + public function afterOpenApiGenerated(?Closure $afterOpenApiGenerated = null) { if (count(func_get_args()) === 0) {