Skip to content

Commit

Permalink
support Spatie Query Builder filters
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein4alaa committed Sep 13, 2024
1 parent 47d6439 commit 127221a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/Swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public function generateSwaggerJsonResponse()
"class" => $controller_path,
"description" => $controller_description
];

$params = $this->formatParams($validations, $route);

$this->spatieSchema($params, $method);

$apiRoutes[] = [
'prefix' => $prefix,
'method' => $method,
Expand All @@ -122,7 +127,7 @@ public function generateSwaggerJsonResponse()
'action' => $action,
'middleware' => $route->middleware(),
'validations' => $validations,
'params' => $this->formatParams($validations, $route),
'params' => $params,
'operation_id' => $operationId,
'has_schema' => $hasSchema,
'need_token' => $needToken
Expand Down Expand Up @@ -183,4 +188,48 @@ private function getVersion()
}
return $version;
}


private function spatieSchema(&$params, $method)
{
$spatie_query_builder = config('swagger.spatie_query_builder');
if ($method == 'GET|HEAD' && $spatie_query_builder) {
$params[] = [
"name" => "filter",
"in" => "query",
"description" => "Filter",
"required" => false,
"style" => "deepObject",
"explode" => true,
"schema" => [
"type" => "object",
"additionalProperties" => [
"type" => "string",
"description" => "The dynamic filtering"
]
]
];
$params[] = [
"name" => "sort",
"in" => "query",
"description" => "sort",
"required" => false,
"schema" => [
"nullable" => "true",
"type" => "string",
]
];
$params[] = [
"name" => "include",
"in" => "query",
"description" => "include",
"required" => false,
"schema" => [
"nullable" => "true",
"type" => "string",
]
];
}
}

}
10 changes: 10 additions & 0 deletions src/config/swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@
]
],

/*
|--------------------------------------------------------------------------
| Spatie Query Builder
|--------------------------------------------------------------------------
|
| Enable it if you using Spatie query builder package to add spatie filters in all GET routes.
|
*/
"spatie_query_builder" => false,


/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit 127221a

Please sign in to comment.