-
-
Notifications
You must be signed in to change notification settings - Fork 979
fix(symfony): support repeated global parameter classes #8451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
soyuka
merged 4 commits into
api-platform:4.3
from
nozarashi20:fix/global-default-parameters
Sep 5, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ce6805c
fix(symfony): support repeated global parameter classes
nozarashi20 ea1c304
fix(validator): default named parameter to query
soyuka 8f40672
test: move repeated params kernel to fixtures
soyuka 92888d8
test: drop redundant nullsafe calls
soyuka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use ApiPlatform\Metadata\HeaderParameter; | ||
| use Symfony\Component\Config\Loader\LoaderInterface; | ||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
|
||
| class RepeatedDefaultParametersAppKernel extends AppKernel | ||
| { | ||
| protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void | ||
| { | ||
| parent::configureContainer($container, $loader); | ||
|
|
||
| $loader->load(static function (ContainerBuilder $container): void { | ||
| if ($container->hasDefinition('phpunit_resource_name_collection')) { | ||
| $container->removeDefinition('phpunit_resource_name_collection'); | ||
| } | ||
|
|
||
| $container->loadFromExtension('api_platform', [ | ||
| 'defaults' => [ | ||
| 'parameters' => [ | ||
| 'api_token' => [ | ||
| 'class' => HeaderParameter::class, | ||
| 'key' => 'API-Token', | ||
| 'required' => true, | ||
| 'description' => 'API token', | ||
| ], | ||
| 'request_id' => [ | ||
| 'class' => HeaderParameter::class, | ||
| 'key' => 'Request-ID', | ||
| 'required' => false, | ||
| 'description' => 'Request correlation identifier', | ||
| ], | ||
| ], | ||
| ], | ||
| ]); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Tests\Functional; | ||
|
|
||
| use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; | ||
|
|
||
| final class RepeatedDefaultParametersTest extends ApiTestCase | ||
| { | ||
| protected static ?bool $alwaysBootKernel = false; | ||
|
|
||
| protected static function getKernelClass(): string | ||
| { | ||
| return \RepeatedDefaultParametersAppKernel::class; | ||
| } | ||
|
|
||
| public function testRepeatedDefaultParametersAppearTogetherInOpenApi(): void | ||
| { | ||
| $response = self::createClient()->request('GET', '/docs', [ | ||
| 'headers' => ['Accept' => 'application/vnd.openapi+json'], | ||
| ]); | ||
|
|
||
| $this->assertResponseIsSuccessful(); | ||
| $content = $response->toArray(); | ||
|
|
||
| foreach ($content['paths'] as $pathItem) { | ||
| foreach (['get', 'post', 'put', 'patch', 'delete'] as $method) { | ||
| if (!isset($pathItem[$method]['parameters'])) { | ||
| continue; | ||
| } | ||
|
|
||
| $parameters = []; | ||
| foreach ($pathItem[$method]['parameters'] as $parameter) { | ||
| if ('header' === $parameter['in']) { | ||
| $parameters[$parameter['name']] = $parameter; | ||
| } | ||
| } | ||
|
|
||
| if (!isset($parameters['API-Token'], $parameters['Request-ID'])) { | ||
| continue; | ||
| } | ||
|
|
||
| $this->assertSame('API-Token', $parameters['API-Token']['name']); | ||
| $this->assertSame('header', $parameters['API-Token']['in']); | ||
| $this->assertSame('API token', $parameters['API-Token']['description']); | ||
| $this->assertTrue($parameters['API-Token']['required']); | ||
| $this->assertSame('Request-ID', $parameters['Request-ID']['name']); | ||
| $this->assertSame('header', $parameters['Request-ID']['in']); | ||
| $this->assertSame('Request correlation identifier', $parameters['Request-ID']['description']); | ||
| $this->assertFalse($parameters['Request-ID']['required']); | ||
|
|
||
| return; | ||
| } | ||
| } | ||
|
|
||
| $this->fail('No OpenAPI operation contained both repeated default header parameters.'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a default to QueryParameter so this doesn't break existing usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What existing usage do you have in mind ? Named entries are new in this PR, and the existing class-keyed syntax still works as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right my bad I thought that it'd have failed but after checking Symfony config just ignores it