From 4f578320b64eb322607480357b8b14bdc4b5720f Mon Sep 17 00:00:00 2001 From: Aleksei Zarubin <12220926+alexzarbn@users.noreply.github.com> Date: Tue, 21 Jun 2022 17:29:22 +0400 Subject: [PATCH] fix(specs): add "all in" and "any in" filters --- src/Drivers/Standard/ParamsValidator.php | 19 +++++++++++++++---- .../RequestBody/Search/FiltersBuilder.php | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Drivers/Standard/ParamsValidator.php b/src/Drivers/Standard/ParamsValidator.php index 76563456..901af0f7 100644 --- a/src/Drivers/Standard/ParamsValidator.php +++ b/src/Drivers/Standard/ParamsValidator.php @@ -52,8 +52,15 @@ public function validateFilters(Request $request): void [ 'filters' => ['sometimes', 'array'], 'filters.*.type' => ['sometimes', 'in:and,or'], - 'filters.*.field' => ['required_with:filters', 'regex:/^[\w.\_\-\>]+$/', new WhitelistedField($this->filterableBy)], - 'filters.*.operator' => ['sometimes', 'in:<,<=,>,>=,=,!=,like,not like,ilike,not ilike,in,not in,all in,any in'], + 'filters.*.field' => [ + 'required_with:filters', + 'regex:/^[\w.\_\-\>]+$/', + new WhitelistedField($this->filterableBy), + ], + 'filters.*.operator' => [ + 'sometimes', + 'in:<,<=,>,>=,=,!=,like,not like,ilike,not ilike,in,not in,all in,any in', + ], 'filters.*.value' => ['present', 'nullable'], ] )->validate(); @@ -65,7 +72,11 @@ public function validateSort(Request $request): void $request->all(), [ 'sort' => ['sometimes', 'array'], - 'sort.*.field' => ['required_with:sort', 'regex:/^[\w.\_\-\>]+$/', new WhitelistedField($this->sortableBy)], + 'sort.*.field' => [ + 'required_with:sort', + 'regex:/^[\w.\_\-\>]+$/', + new WhitelistedField($this->sortableBy), + ], 'sort.*.direction' => ['sometimes', 'in:asc,desc'], ] )->validate(); @@ -78,7 +89,7 @@ public function validateSearch(Request $request): void [ 'search' => ['sometimes', 'array'], 'search.value' => ['string', 'nullable'], - 'search.case_sensitive' => ['bool'] + 'search.case_sensitive' => ['bool'], ] )->validate(); } diff --git a/src/Specs/Builders/Partials/RequestBody/Search/FiltersBuilder.php b/src/Specs/Builders/Partials/RequestBody/Search/FiltersBuilder.php index 39e54fae..07faf44b 100644 --- a/src/Specs/Builders/Partials/RequestBody/Search/FiltersBuilder.php +++ b/src/Specs/Builders/Partials/RequestBody/Search/FiltersBuilder.php @@ -29,7 +29,7 @@ public function build(): ?array ], 'operator' => [ 'type' => 'string', - 'enum' => ['<','<=','>','>=','=','!=','like','not like','ilike','not ilike','in','not in'], + 'enum' => ['<','<=','>','>=','=','!=','like','not like','ilike','not ilike','in','not in', 'all in', 'any in'], ], 'value' => [ 'type' => 'string',