Skip to content

Commit

Permalink
update route processor
Browse files Browse the repository at this point in the history
  • Loading branch information
tomirons committed Mar 6, 2024
1 parent de5e7f1 commit 8bf5e56
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/Processors/RouteProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,25 @@ protected function processRoute(Route $route)
// return [];
// }

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

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

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

if ($this->config['structured']) {
Expand Down Expand Up @@ -139,19 +150,26 @@ protected function processRequest(string $method, Stringable $uri, Collection $r
->all(),
],
])
->when($rules, function (Collection $collection, Collection $rules) {
->when($rules, function (Collection $collection, Collection $rules) use ($method) {
if ($rules->isEmpty()) {
return $collection;
}

$rules->transform(fn ($rule) => [
'key' => $rule['name'],
'value' => $this->config['formdata'][$rule['name']] ?? null,
'description' => $this->config['print_rules'] ? $this->parseRulesIntoHumanReadable($rule['name'], $rule['description']) : null,
]);

if ($method === 'GET') {
return $collection->put('url', [
'query' => $rules->map(fn ($value) => array_merge($value, ['disabled' => false]))
]);
}

return $collection->put('body', [
'mode' => 'urlencoded',
'urlencoded' => $rules->map(fn ($rule) => [
'key' => $rule['name'],
'value' => $this->config['formdata'][$rule['name']] ?? null,
'type' => 'text',
'description' => $this->config['print_rules'] ? $this->parseRulesIntoHumanReadable($rule['name'], $rule['description']) : null,
]),
'urlencoded' => $rules->map(fn ($value) => array_merge($value, ['type' => 'text'])),
]);
})
->all();
Expand Down

0 comments on commit 8bf5e56

Please sign in to comment.