Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dedoc Verison and Spatie Query Builder Version. #2

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"minimum-stability": "dev",
"require": {
"php": "^8.1",
"dedoc/scramble": "^0.9.0",
"spatie/laravel-query-builder": "^5.0"
"dedoc/scramble": "^0.11.0",
"spatie/laravel-query-builder": "^6.0"
},
"require-dev": {
"laravel/pint": "^v1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/AllowedFilterModesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function handle(Operation $operation, RouteInfo $routeInfo)

$values = $helper->inferValues($methodCall, $routeInfo);

$parameter = new Parameter(config(AllowedFilter::FilterModesQueryParamConfigKey), 'query');
$parameter = new Parameter(config(AllowedFilter::FilterModesQueryParamConfigKey)??"filter_mode", 'query');
Copy link
Member

@layerok layerok Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just exclude AllowedFilterModesExtension from scramble extensions (config/scramble.php).
That way you won't get any exceptions for reading non-existent config key. There is no need to add this change. Please, remove it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I was missing that. Will update on that. Thank you.


$objectType = new ObjectType;

Expand Down
13 changes: 8 additions & 5 deletions src/AllowedSortsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Dedoc\Scramble\Support\Generator\Parameter;
use Dedoc\Scramble\Support\Generator\Schema;
use Dedoc\Scramble\Support\Generator\Types\ArrayType;
use Dedoc\Scramble\Support\Generator\Types\ObjectType;
use Dedoc\Scramble\Support\Generator\Types\StringType;
use Dedoc\Scramble\Support\RouteInfo;

Expand Down Expand Up @@ -38,15 +39,17 @@ public function handle(Operation $operation, RouteInfo $routeInfo)
array_map(fn ($value) => '-'.$value, $values)
));

$objectType = new ObjectType();
foreach ($arrayType->items->enum as $value) {
$objectType->addProperty($value, new StringType());
}
$parameter = new Parameter(config($this->configKey), 'query');

$parameter->setSchema(Schema::fromType((new AnyOf)->setItems([
new StringType,
$arrayType,
])))->example($this->examples);
$parameter->setSchema(Schema::fromType($objectType))
->example($this->examples);

$halt = $this->runHooks($operation, $parameter);
if (! $halt) {
if (!$halt) {
$operation->addParameters([$parameter]);
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/InferHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,25 @@ public function inferValues(Node\Expr\MethodCall $methodCall, RouteInfo $routeIn
return [];
}

// ->allowedIncludes(['posts', 'posts.author'])
if ($methodCall->args[0]->value instanceof Node\Expr\Array_) {
return array_map(fn (Node\Expr\ArrayItem $item) => $item->value->value, $methodCall->args[0]->value->items);
return array_map(function (Node\Expr\ArrayItem $item) {

if ($item->value instanceof Node\Scalar\String_) {
return $item->value->value;
}
if ($item->value instanceof Node\Expr\StaticCall) {
// Check if the static call is AllowedSort::custom
if ($item->value->class instanceof Node\Name
&& $item->value->class->toString() === 'Spatie\QueryBuilder\AllowedSort'
&& $item->value->name instanceof Node\Identifier
&& $item->value->name->name === 'custom') {
$customSortName = $item->value->args[0]->value->value;
return $customSortName;
}
return $this->inferValueFromStaticCall($item->value);
}
return self::NOT_SUPPORTED_KEY;
}, $methodCall->args[0]->value->items);
}

// ->allowedIncludes('posts', 'posts.author')
Expand Down