Skip to content

Commit 8dc8c8d

Browse files
committed
global parameters
1 parent 9e23105 commit 8dc8c8d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

core/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ api_platform:
380380
schemes: ~
381381
options: ~
382382
host: ~
383+
parameters: ~
383384

384385
# The URL generation strategy to use for IRIs
385386
url_generation_strategy: !php/const ApiPlatform\Metadata\UrlGeneratorInterface::ABS_PATH
@@ -810,6 +811,7 @@ return [
810811
'input' => null,
811812
'output' => null,
812813
'stateless' => null,
814+
'parameters' => null,
813815

814816
// The URL generation strategy to use for IRIs
815817
'url_generation_strategy' => UrlGeneratorInterface::ABS_PATH,

core/filters.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,54 @@ a new instance:
6868
> [!TIP] Always check the specific documentation for your persistence layer (Doctrine ORM, MongoDB
6969
> ODM, Laravel Eloquent) to see the exact namespace and available options for these filters.
7070
71+
### Global Default Parameters
72+
73+
Instead of repeating the same parameter configuration on every resource, you can define global
74+
default parameters that are automatically applied to all resources. This is done via the `defaults`
75+
key in your API Platform configuration.
76+
77+
Add a `parameters` map under `defaults` in your API Platform configuration. Each entry maps a
78+
fully-qualified parameter class name to its options.
79+
80+
```yaml
81+
# Symfony: api/config/packages/api_platform.yaml
82+
api_platform:
83+
defaults:
84+
parameters:
85+
ApiPlatform\Metadata\HeaderParameter:
86+
key: "API-Token"
87+
required: true
88+
description: "API authentication token"
89+
90+
ApiPlatform\Metadata\QueryParameter:
91+
key: "api_version"
92+
required: false
93+
description: "API version"
94+
```
95+
96+
```php
97+
<?php
98+
// Laravel: config/api-platform.php
99+
return [
100+
'defaults' => [
101+
'parameters' => [
102+
\ApiPlatform\Metadata\HeaderParameter::class => [
103+
'key' => 'API-Token',
104+
'required' => true,
105+
'description' => 'API authentication token',
106+
],
107+
\ApiPlatform\Metadata\QueryParameter::class => [
108+
'key' => 'api_version',
109+
'required' => false,
110+
'description' => 'API version',
111+
],
112+
],
113+
],
114+
];
115+
```
116+
117+
Every resource will automatically expose these parameters on all their operations.
118+
71119
You can declare a parameter on the resource class to make it available for all its operations:
72120

73121
```php

0 commit comments

Comments
 (0)