Skip to content

Commit

Permalink
fix(specs): add "all in" and "any in" filters
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzarbn committed Jun 21, 2022
1 parent f063f6d commit 4f57832
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/Drivers/Standard/ParamsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4f57832

Please sign in to comment.