You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,7 +16,7 @@ It is also automatically documented as a `search` property for JSON-LD responses
16
16
17
17
## Parameters
18
18
19
-
You can declare parameters on a Resource or an Operation through the `parameters` property.
19
+
You can declare parameters on a Resource or an Operation through the `parameters` property.
20
20
21
21
```php
22
22
namespace App\ApiResource;
@@ -39,7 +39,7 @@ A Parameter can be linked to a filter, there are two types of filters:
39
39
40
40
### Alter the Operation via a parameter
41
41
42
-
A parameter can alter the current Operation context, to do so use a `ApiPlatform\State\ParameterProviderInterface`:
42
+
A parameter can alter the current Operation context, to do so use a `ApiPlatform\State\ParameterProviderInterface`:
43
43
44
44
```php
45
45
class GroupsParameterProvider implements ParameterProviderInterface {
@@ -64,7 +64,7 @@ class Book {
64
64
}
65
65
```
66
66
67
-
If you don't have autoconfiguration enabled, declare the parameter as a tagged service:
67
+
If you don't have autoconfiguration enabled, declare the parameter as a tagged service:
68
68
69
69
```yaml
70
70
services:
@@ -76,7 +76,7 @@ services:
76
76
77
77
### Call a filter
78
78
79
-
A Parameter can also call a filter and works on filters that impact the data persistence layer (Doctrine ORM, ODM and Eloquent filters are supported). Let's assume, that we have an Order filter declared:
79
+
A Parameter can also call a filter and works on filters that impact the data persistence layer (Doctrine ORM, ODM and Eloquent filters are supported). Let's assume, that we have an Order filter declared:
80
80
81
81
```yaml
82
82
# config/services.yaml
@@ -89,7 +89,7 @@ services:
89
89
tags: [ 'api_platform.filter' ]
90
90
```
91
91
92
-
We can use this filter specifying we want a query parameter with the `:property` placeholder:
92
+
We can use this filter specifying we want a query parameter with the `:property` placeholder:
93
93
94
94
```php
95
95
namespace App\ApiResource;
@@ -127,7 +127,7 @@ When you declare a parameter on top of a class, you need to specify it's key.
127
127
128
128
### The :property placeholder
129
129
130
-
When used on a Parameter, the `:property` placeholder allows to map automatically a parameter to the readable properties of your resource.
130
+
When used on a Parameter, the `:property` placeholder allows to map automatically a parameter to the readable properties of your resource.
131
131
132
132
```php
133
133
namespace App\ApiResource;
@@ -143,7 +143,7 @@ class Book {
143
143
}
144
144
```
145
145
146
-
This will declare a query parameter for each property (id, title and author) calling the SearchFilter.
146
+
This will declare a query parameter for each property (ID, title and author) calling the SearchFilter.
147
147
148
148
This is especially useful for sort filters where you'd like to use `?sort[name]=asc`:
149
149
@@ -161,7 +161,7 @@ class Book {
161
161
}
162
162
```
163
163
164
-
### Documentation
164
+
### Documentation
165
165
166
166
A parameter is quite close to its documentation and you can specify the JSON Schema and/or the OpenAPI documentation:
167
167
@@ -226,7 +226,7 @@ use ApiPlatform\Metadata\QueryParameter;
226
226
],
227
227
)]
228
228
class ValidateParameter {}
229
-
```
229
+
```
230
230
231
231
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.
232
232
@@ -299,7 +299,7 @@ final class SearchTextAndDateFilter implements FilterInterface
299
299
}
300
300
```
301
301
302
-
This can be used with parameters using attributes:
302
+
This can be used with parameters using attributes:
303
303
304
304
```php
305
305
namespace App\Entity;
@@ -2006,243 +2006,3 @@ The next filters are not related to how the data is fetched but rather to how th
Note that `property` is used to document the Hydra view. You can also specify an [OpenAPI Parameter](https://api-platform.com/docs/references/OpenApi/Model/Parameter/) if needed.
2027
-
2028
-
### Alter the Operation via a parameter
2029
-
2030
-
A parameter can alter the current Operation context, to do so use a `ApiPlatform\State\ParameterProviderInterface`:
2031
-
2032
-
```php
2033
-
class GroupsParameterProvider implements ParameterProviderInterface {
2034
-
public function provider(Parameter $parameter, array $uriVariables = [], array $context = []): HttpOperation
A Parameter can also call a filter and works on filters that impact the data persistence layer (Doctrine ORM and ODM filters are supported). Let's assume, that we have an Order filter declared:
2068
-
2069
-
```yaml
2070
-
# config/services.yaml
2071
-
services:
2072
-
offer.order_filter:
2073
-
parent: 'api_platform.doctrine.orm.order_filter'
2074
-
arguments:
2075
-
$properties: { id: ~, name: ~ }
2076
-
$orderParameterName: order
2077
-
tags: [ 'api_platform.filter' ]
2078
-
```
2079
-
2080
-
We can use this filter specifying we want a query parameter with the `:property` placeholder:
2081
-
2082
-
```php
2083
-
namespace App\ApiResource;
2084
-
2085
-
#[GetCollection(
2086
-
uriTemplate: 'orders',
2087
-
parameters: [
2088
-
'order[:property]' => new QueryParameter(filter: 'offer.order_filter'),
2089
-
]
2090
-
)
2091
-
class Offer {
2092
-
public string $id;
2093
-
public string $name;
2094
-
}
2095
-
```
2096
-
2097
-
### Decorate a Doctrine filter
2098
-
2099
-
A filter that implements the `ApiPlatform\Doctrine\Common\Filter\PropertyAwareFilterInterface` interface can be decorated:
2100
-
2101
-
```php
2102
-
namespace App\Doctrine\Filter;
2103
-
2104
-
use ApiPlatform\Doctrine\Common\Filter\PropertyAwareFilterInterface;
2105
-
use ApiPlatform\Doctrine\Orm\Filter\FilterInterface;
2106
-
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
2107
-
use ApiPlatform\Metadata\Operation;
2108
-
use Doctrine\ORM\QueryBuilder;
2109
-
use Symfony\Component\DependencyInjection\Attribute\Autowire;
2110
-
2111
-
final class SearchTextAndDateFilter implements FilterInterface
'num' => new QueryParameter(schema: ['minimum' => 1, 'maximum' => 3]),
2215
-
'exclusiveNum' => new QueryParameter(schema: ['exclusiveMinimum' => 1, 'exclusiveMaximum' => 3]),
2216
-
'blank' => new QueryParameter(openApi: new OpenApiParameter(name: 'blank', in: 'query', allowEmptyValue: false)),
2217
-
'length' => new QueryParameter(schema: ['maxLength' => 1, 'minLength' => 3]),
2218
-
'array' => new QueryParameter(schema: ['minItems' => 2, 'maxItems' => 3]),
2219
-
'multipleOf' => new QueryParameter(schema: ['multipleOf' => 2]),
2220
-
'pattern' => new QueryParameter(schema: ['pattern' => '/\d/']),
2221
-
'required' => new QueryParameter(required: true),
2222
-
],
2223
-
)]
2224
-
class ValidateParameter {}
2225
-
```
2226
-
2227
-
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.
2228
-
2229
-
2230
-
### Parameter security
2231
-
2232
-
Parameters may have security checks:
2233
-
2234
-
``` php
2235
-
<?php
2236
-
use ApiPlatform\Metadata\GetCollection;
2237
-
use ApiPlatform\Metadata\HeaderParameter;
2238
-
use ApiPlatform\Metadata\QueryParameter;
2239
-
2240
-
#[GetCollection(
2241
-
uriTemplate: 'security_parameters{._format}',
2242
-
parameters: [
2243
-
'sensitive' => new QueryParameter(security: 'is_granted("ROLE_ADMIN")'),
2244
-
'auth' => new HeaderParameter(security: '"secretKey" == auth[0]'),
0 commit comments