From bed9409732711b49cf26be63e6ebf89edb94a1f0 Mon Sep 17 00:00:00 2001 From: Roman Bensman Date: Thu, 2 Feb 2017 15:07:33 -0500 Subject: [PATCH] added possibility use collection query string and service merhod summary name --- src/Service.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/Service.php diff --git a/src/Service.php b/src/Service.php old mode 100644 new mode 100755 index 4aa1abb..5adf84d --- a/src/Service.php +++ b/src/Service.php @@ -47,9 +47,10 @@ public function toArray() protected function getTags() { + return [ $this->cleanEmptyValues([ - 'name' => $this->service->getName(), + 'name' => $this->service->getName() , 'description' => $this->service->getDescription() ]) ]; @@ -108,9 +109,12 @@ protected function getEntityOperationsData($route) protected function getCollectionOperationsData($route) { - $urlParameters = $this->getURLParametersNotRequired($route); + $urlParameters = $this->getURLParametersNotRequired($route); + $urlParameters = $this->getURLQueryParameters() ? array_merge($urlParameters,$this->getURLQueryParameters()) : $urlParameters; + unset($urlParameters[$this->service->routeIdentifierName]); $operations = $this->service->operations; + return $this->getOperationsData($operations, $urlParameters); } @@ -166,6 +170,30 @@ protected function getURLParameters($route, $required) return $templateParameters; } + protected function getURLQueryParameters() + { + // find all parameters in Swagger naming format + //preg_match_all('#{([\w\d_-]+)}#', $route, $parameterMatches); + $queryWhitelist = $this->service->getQueryWhitelist(); + if (count($queryWhitelist) > 0) { + $templateQueryParameters = []; + foreach ($queryWhitelist as $paramSegmentName) { + $templateQueryParameters[$paramSegmentName] = [ + 'in' => 'query', + 'name' => $paramSegmentName, + 'description' => 'URL parameter ' . $paramSegmentName, + 'dataType' => 'string', + 'required' => false, + 'minimum' => 0, + 'maximum' => 1, + 'defaultValue' => '' + ]; + } + return $templateQueryParameters; + } else return false; + + } + protected function getPostPatchPutBodyParameter() { return [ @@ -188,11 +216,16 @@ protected function getMethodFromOperation(Operation $operation) return strtolower($operation->getHttpMethod()); } + /* + * Added summary + */ protected function getPathOperation(Operation $operation, $parameters) { + return $this->cleanEmptyValues([ 'tags' => [$this->service->getName()], 'description' => $operation->getDescription(), + 'summary' => $operation->getSummary(), 'parameters' => $parameters, 'produces' => $this->service->getRequestAcceptTypes(), 'responses' => $this->getResponsesFromOperation($operation)