Skip to content

Commit

Permalink
handle patterns in include list also
Browse files Browse the repository at this point in the history
  • Loading branch information
ngabor84 committed Nov 23, 2018
1 parent 0622141 commit 89ec6b2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ return [
'prefixes' => ['api/*', 'v2-api/*'],
'versions' => ['v1'],
],
'include' => ['users.index'],
'exclude' => ['users.create'],
'include' => ['users.index', 'healthcheck*'],
'exclude' => ['users.create', 'admin.*'],
'apply' => [
'headers' => [
'Authorization' => 'Bearer: {token}',
Expand Down
8 changes: 4 additions & 4 deletions config/apidoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@
/*
* Include these routes when generating documentation,
* even if they did not match the rules above.
* Note that the route must be referenced by name here.
* Note that the route must be referenced by name here (wildcards are supported).
*/
'include' => [
// 'users.index',
// 'users.index', 'healthcheck*'
],

/*
* Exclude these routes when generating documentation,
* even if they matched the rules above.
* Note that the route must be referenced by name here.
* Note that the route must be referenced by name here (wildcards are supported).
*/
'exclude' => [
// 'users.create',
// 'users.create', 'admin.*'
],

/*
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/RouteMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function shouldIncludeRoute(Route $route, array $routeRule, array $mustI
? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []))
: true;

return in_array($route->getName(), $mustIncludes)
return str_is($mustIncludes, $route->getName())
|| (str_is($routeRule['match']['domains'] ?? [], $route->getDomain())
&& str_is($routeRule['match']['prefixes'] ?? [], $route->uri())
&& $matchesVersion);
Expand Down
39 changes: 39 additions & 0 deletions tests/Unit/RouteMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,45 @@ public function testWillIncludeRouteIfListedExplicitlyForDingoRouter()
$this->assertCount(1, $oddRuleOut);
}

public function testWillIncludeRouteIfMatchForAnIncludePatternForLaravelRouter()
{
$this->registerLaravelRoutes();
$mustInclude = ['domain1-1', 'domain1-2'];
$includePattern = 'domain1-*';
$routeRules[0]['include'] = [$includePattern];

$routeRules[0]['match']['domains'] = ['domain1.*'];
$routeRules[0]['match']['prefixes'] = ['prefix1/*'];
$routes = $this->matcher->getRoutesToBeDocumented($routeRules);
$oddRuleOut = collect($routes)->filter(function ($route) use ($mustInclude) {
return in_array($route['route']->getName(), $mustInclude);
});
$this->assertCount(count($mustInclude), $oddRuleOut);
}

public function testWillIncludeRouteIfMatchForAnIncludePatternForDingoRouter()
{
$this->registerDingoRoutes();

$mustInclude = ['v2.domain1', 'v2.domain2'];
$includePattern = 'v2.domain*';
$routeRules = [
[
'match' => [
'domains' => ['domain1.*'],
'prefixes' => ['prefix1/*'],
'versions' => ['v1'],
],
'include' => [$includePattern],
],
];
$routes = $this->matcher->getDingoRoutesToBeDocumented($routeRules);
$oddRuleOut = collect($routes)->filter(function ($route) use ($mustInclude) {
return in_array($route['route']->getName(), $mustInclude);
});
$this->assertCount(count($mustInclude), $oddRuleOut);
}

public function testWillExcludeRouteIfListedExplicitlyForLaravelRouter()
{
$this->registerLaravelRoutes();
Expand Down

0 comments on commit 89ec6b2

Please sign in to comment.