Skip to content

Commit 4714e7b

Browse files
authored
fix(doc): parameter validation (#1952)
1 parent fce8eb0 commit 4714e7b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

core/filters.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,3 +1852,31 @@ class SearchFilterParameter
18521852
}
18531853
}
18541854
```
1855+
1856+
### Parameter validation
1857+
1858+
Parameter validation is automatic based on the configuration for example:
1859+
1860+
```php
1861+
<?php
1862+
use ApiPlatform\Metadata\GetCollection;
1863+
use ApiPlatform\Metadata\QueryParameter;
1864+
1865+
#[GetCollection(
1866+
uriTemplate: 'validate_parameters{._format}',
1867+
parameters: [
1868+
'enum' => new QueryParameter(schema: ['enum' => ['a', 'b'], 'uniqueItems' => true]),
1869+
'num' => new QueryParameter(schema: ['minimum' => 1, 'maximum' => 3]),
1870+
'exclusiveNum' => new QueryParameter(schema: ['exclusiveMinimum' => 1, 'exclusiveMaximum' => 3]),
1871+
'blank' => new QueryParameter(openApi: new OpenApiParameter(name: 'blank', in: 'query', allowEmptyValue: false)),
1872+
'length' => new QueryParameter(schema: ['maxLength' => 1, 'minLength' => 3]),
1873+
'array' => new QueryParameter(schema: ['minItems' => 2, 'maxItems' => 3]),
1874+
'multipleOf' => new QueryParameter(schema: ['multipleOf' => 2]),
1875+
'pattern' => new QueryParameter(schema: ['pattern' => '/\d/']),
1876+
'required' => new QueryParameter(required: true),
1877+
],
1878+
)]
1879+
class ValidateParameter {}
1880+
```
1881+
1882+
You can also use your own constraint by setting the `constraints` option on a Parameter. In that case we won't setup the automatic validation for you and it'll replace our defaults.

0 commit comments

Comments
 (0)