From 6b442f773908f512574330fce977adea83861756 Mon Sep 17 00:00:00 2001 From: Qanah Date: Mon, 17 Sep 2018 19:40:28 +0300 Subject: [PATCH 1/2] queryParameters array from the docblock pass queryParameters array from the docblock --- .../ApiDoc/Generators/AbstractGenerator.php | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index 2f2a21c1..d6d577d3 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -85,7 +85,14 @@ public function processRoute($route, $bindings = [], $headers = [], $withRespons } if (! $response && $withResponse) { try { - $response = $this->getRouteResponse($route, $bindings, $headers); + // we have a queryParameters array from the docblock + $parameters = $this->getQueryParameters($routeDescription['tags']); + + if(!is_array($parameters)) { + $parameters = []; + } + + $response = $this->getRouteResponse($route, $bindings, $parameters, $headers); } catch (\Exception $e) { echo "Couldn't get response for route: ".implode(',', $this->getMethods($route)).$route->uri().']: '.$e->getMessage()."\n"; } @@ -205,7 +212,7 @@ protected function simplifyRules($rules) * * @return \Illuminate\Http\Response */ - protected function getRouteResponse($route, $bindings, $headers = []) + protected function getRouteResponse($route, $bindings, $parameters = [], $headers = []) { $uri = $this->addRouteModelBindings($route, $bindings); @@ -223,7 +230,33 @@ protected function getRouteResponse($route, $bindings, $headers = []) //Changes url with parameters like /users/{user} to /users/1 $uri = preg_replace('/{(.*?)}/', 1, $uri); // 1 is the default value for route parameters - return $this->callRoute(array_shift($methods), $uri, [], [], [], $headers); + return $this->callRoute(array_shift($methods), $uri, $parameters, [], [], $headers); + } + + /** + * Get the Query Parameters if available. + * + * @param array $tags + * + * @return array + */ + protected function getQueryParameters($tags) + { + $responseTags = array_filter($tags, function ($tag) { + if (! ($tag instanceof Tag)) { + return false; + } + + return $tag->getName() == 'queryParameters'; + }); + + if (empty($responseTags)) { + return []; + } + + $responseTag = \array_first($responseTags); + + return \json_decode($responseTag->getContent(), true); } /** From e3d172a4d9057ac08c65a0bfd6e65cb8b1655bb6 Mon Sep 17 00:00:00 2001 From: Qanah Date: Tue, 18 Sep 2018 12:18:15 +0300 Subject: [PATCH 2/2] Update AbstractGenerator.php --- src/Mpociot/ApiDoc/Generators/AbstractGenerator.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index d6d577d3..fba65190 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -87,11 +87,6 @@ public function processRoute($route, $bindings = [], $headers = [], $withRespons try { // we have a queryParameters array from the docblock $parameters = $this->getQueryParameters($routeDescription['tags']); - - if(!is_array($parameters)) { - $parameters = []; - } - $response = $this->getRouteResponse($route, $bindings, $parameters, $headers); } catch (\Exception $e) { echo "Couldn't get response for route: ".implode(',', $this->getMethods($route)).$route->uri().']: '.$e->getMessage()."\n"; @@ -256,7 +251,13 @@ protected function getQueryParameters($tags) $responseTag = \array_first($responseTags); - return \json_decode($responseTag->getContent(), true); + $parameters = \json_decode($responseTag->getContent(), true); + + if(! is_array($parameters)) { + $parameters = []; + } + + return $parameters; } /**