Skip to content

Commit

Permalink
Merge pull request #370 from dedoc/fix/serialize-issue
Browse files Browse the repository at this point in the history
Fixed routes serialization error
  • Loading branch information
romalytvynenko committed May 15, 2024
2 parents f2ac696 + cf4ba0c commit 4efa098
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/GeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 4efa098

Please sign in to comment.