Skip to content

Commit 0f070a4

Browse files
Nathansoyuka
authored andcommitted
fix(laravel): eloquent filters
1 parent 179d32c commit 0f070a4

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/Laravel/Metadata/ParameterValidationResourceMetadataCollectionFactory.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
7272
private function addSchemaValidation(Parameter $parameter): Parameter
7373
{
7474
$schema = $parameter->getSchema();
75-
$required = $parameter->getRequired() ?? false;
75+
$required = $parameter->getRequired();
7676
$openApi = $parameter->getOpenApi();
7777

7878
// When it's an array of openapi parameters take the first one as it's probably just a variant of the query parameter,
@@ -81,13 +81,12 @@ private function addSchemaValidation(Parameter $parameter): Parameter
8181
$openApi = $openApi[0];
8282
}
8383
$assertions = [];
84-
85-
if ($required && true !== ($allowEmptyValue = $openApi?->getAllowEmptyValue())) {
84+
$allowEmptyValue = $openApi?->getAllowEmptyValue();
85+
if ($required || (false === $required && false === $allowEmptyValue)) {
8686
$assertions[] = 'required';
8787
}
8888

89-
if (true === ($allowEmptyValue ?? $openApi?->getAllowEmptyValue())) {
90-
$assertions[] = 'required';
89+
if (true === $allowEmptyValue) {
9190
$assertions[] = 'nullable';
9291
}
9392

@@ -107,8 +106,8 @@ private function addSchemaValidation(Parameter $parameter): Parameter
107106
$assertions[] = 'lte:'.$schema['maximum'];
108107
}
109108

110-
if (isset($schema['regexPattern'])) {
111-
$assertions[] = 'regex:'.$schema['regexPattern'];
109+
if (isset($schema['pattern'])) {
110+
$assertions[] = 'regex:'.$schema['pattern'];
112111
}
113112

114113
$minLength = isset($schema['minLength']);

src/Laravel/workbench/app/Models/Book.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
]
4949
)]
5050
#[QueryParameter(key: 'isbn', schema: ['minimum' => '9783877138395', 'maximum' => '9793877138395'], filter: PartialSearchFilter::class)]
51-
#[QueryParameter(key: 'name', schema: ['regexPattern' => '/^a/'], filter: PartialSearchFilter::class)]
52-
#[QueryParameter(key: 'author', openApi: new Parameter(name: 'author', in: 'query', allowEmptyValue: true), filter: EqualsFilter::class, required: true)]
51+
#[QueryParameter(key: 'name', schema: ['pattern' => '/^a/'], filter: PartialSearchFilter::class)]
52+
#[QueryParameter(key: 'author', openApi: new Parameter(name: 'author', in: 'query', allowEmptyValue: false), filter: EqualsFilter::class, required: true)]
5353
#[QueryParameter(key: 'publicationDate', filter: DateFilter::class, property: 'publication_date')]
5454
#[QueryParameter(key: 'publicationDateWithNulls', filter: DateFilter::class, property: 'publication_date', filterContext: ['include_nulls' => true])]
5555
#[QueryParameter(key: 'isbn_range', filter: RangeFilter::class, property: 'isbn')]

0 commit comments

Comments
 (0)