From 8bf5e564075aeb7580a41267e1413cf3c9e2d8c3 Mon Sep 17 00:00:00 2001 From: tomirons Date: Wed, 6 Mar 2024 07:54:50 -0500 Subject: [PATCH] update route processor --- src/Processors/RouteProcessor.php | 40 ++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Processors/RouteProcessor.php b/src/Processors/RouteProcessor.php index 147ee02..90230c1 100644 --- a/src/Processors/RouteProcessor.php +++ b/src/Processors/RouteProcessor.php @@ -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']) { @@ -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();