Skip to content

Commit

Permalink
gracefully continue
Browse files Browse the repository at this point in the history
  • Loading branch information
tomirons committed Mar 6, 2024
1 parent 6bbc89c commit c924479
Showing 1 changed file with 57 additions and 52 deletions.
109 changes: 57 additions & 52 deletions src/Processors/RouteProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Routing\Route;
use Illuminate\Routing\Router;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;
Expand Down Expand Up @@ -54,80 +55,84 @@ public function process(array $output): array
*/
protected function processRoute(Route $route)
{
$methods = array_filter($route->methods(), fn ($value) => $value !== 'HEAD');
$middlewares = $route->gatherMiddleware();
try {
$methods = array_filter($route->methods(), fn ($value) => $value !== 'HEAD');
$middlewares = $route->gatherMiddleware();

foreach ($methods as $method) {
$includedMiddleware = false;
foreach ($methods as $method) {
$includedMiddleware = false;

foreach ($middlewares as $middleware) {
if (in_array($middleware, $this->config['include_middleware'])) {
$includedMiddleware = true;
foreach ($middlewares as $middleware) {
if (in_array($middleware, $this->config['include_middleware'])) {
$includedMiddleware = true;
}
}
}

if (empty($middlewares) || ! $includedMiddleware) {
continue;
}
if (empty($middlewares) || ! $includedMiddleware) {
continue;
}

$reflectionMethod = $this->getReflectionMethod($route->getAction());
$reflectionMethod = $this->getReflectionMethod($route->getAction());

if (! $reflectionMethod) {
continue;
}
if (! $reflectionMethod) {
continue;
}

$routeHeaders = $this->config['headers'];
$routeHeaders = $this->config['headers'];

if ($this->authentication && in_array($this->config['auth_middleware'], $middlewares)) {
$routeHeaders[] = $this->authentication->toArray();
}
if ($this->authentication && in_array($this->config['auth_middleware'], $middlewares)) {
$routeHeaders[] = $this->authentication->toArray();
}

$uri = Str::of($route->uri())
->after('/')
->replaceMatches('/{([[:alnum:]]+)}/', ':$1');
$uri = Str::of($route->uri())
->after('/')
->replaceMatches('/{([[:alnum:]]+)}/', ':$1');

// if (!$uri->toString()) {
// return [];
// }
// if (!$uri->toString()) {
// return [];
// }

if ($this->config['include_doc_comments']) {
$description = (new DocBlockProcessor)($reflectionMethod);
}
if ($this->config['include_doc_comments']) {
$description = (new DocBlockProcessor)($reflectionMethod);
}

$data = [
'name' => $route->uri(),
'request' => array_merge(
$this->processRequest(
$method,
$uri,
$this->config['enable_formdata'] ? (new FormDataProcessor)->process($reflectionMethod) : collect()
$data = [
'name' => $route->uri(),
'request' => array_merge(
$this->processRequest(
$method,
$uri,
$this->config['enable_formdata'] ? (new FormDataProcessor)->process($reflectionMethod) : collect()
),
['description' => $description ?? '']
),
['description' => $description ?? '']
),
'response' => [],
'response' => [],

'protocolProfileBehavior' => [
'disableBodyPruning' => $this->config['protocol_profile_behavior']['disable_body_pruning'] ?? false,
],
];
'protocolProfileBehavior' => [
'disableBodyPruning' => $this->config['protocol_profile_behavior']['disable_body_pruning'] ?? false,
],
];

if ($this->config['structured']) {
$routeNameSegments = (
if ($this->config['structured']) {
$routeNameSegments = (
$route->getName()
? Str::of($route->getName())->explode('.')
: Str::of($route->uri())->after('api/')->explode('/')
)->filter(fn ($value) => ! is_null($value) && $value !== '');
)->filter(fn ($value) => ! is_null($value) && $value !== '');

if (! $this->config['crud_folders']) {
if (in_array($routeNameSegments->last(), ['index', 'store', 'show', 'update', 'destroy'])) {
$routeNameSegments->forget($routeNameSegments->count() - 1);
if (! $this->config['crud_folders']) {
if (in_array($routeNameSegments->last(), ['index', 'store', 'show', 'update', 'destroy'])) {
$routeNameSegments->forget($routeNameSegments->count() - 1);
}
}
}

$this->buildTree($this->output, $routeNameSegments->all(), $data);
} else {
$this->output['item'][] = $data;
$this->buildTree($this->output, $routeNameSegments->all(), $data);
} else {
$this->output['item'][] = $data;
}
}
} catch (\Exception $e) {
Log::warning('Failed to process route: '.$route->uri());
}
}

Expand Down

0 comments on commit c924479

Please sign in to comment.