Conversation
jannes-io
force-pushed
the
fix/strict-query-parameter-validation-pagination
branch
3 times, most recently
from
September 18, 2026 09:04
717ef41 to
7d8eb49
Compare
soyuka
reviewed
Sep 18, 2026
jannes-io
force-pushed
the
fix/strict-query-parameter-validation-pagination
branch
2 times, most recently
from
September 18, 2026 09:27
2be1393 to
4b18b36
Compare
jannes-io
force-pushed
the
fix/strict-query-parameter-validation-pagination
branch
2 times, most recently
from
September 18, 2026 10:08
4cce8d2 to
7bdefa3
Compare
Contributor
Author
|
Ok, just waiting for CI to be completed. The Mercure failure seems unrelated and happens on other PRs as well. |
jannes-io
force-pushed
the
fix/strict-query-parameter-validation-pagination
branch
from
September 18, 2026 10:22
7bdefa3 to
fd970f3
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Warning
This PR was partially generated using AI. The resulting code was checked by myself for potential issues.
When
strictQueryParameterValidationis enabled on aGetCollectionoperation, pagination query parameters (page,itemsPerPage,pagination,partial) were always rejected withParameter "X" not supported, even with no other configuration involved. There were actually two separate, compounding bugs:Parameter/Parameterssystem.ParameterProvider::provide()builds its whitelist from$operation->getParameters(), but pagination values are read directly from the request/context inState\Pagination\Pagination— completely bypassing that whitelist. The only place these names existed asParameter-like objects wasOpenApiFactory::getPaginationParameters(), which is purely for Swagger docs. So the docs showed them, but validation rejected them.api_platform.defaults.parameters(global default parameters) silently disabled an existing fallback.ParameterValidationResourceMetadataCollectionFactory::addFilterValidation()auto-whitelists filter-derived query keys, but only when0 === $parameters->count(). Since global default parameters are merged into every operation'sParametersbefore that check runs, declaring even one global default parameter (e.g. a customHeaderParameter) bumped every operation's count above zero and silently skipped this fallback everywhere — unrelated filter-based query keys started getting rejected too.Changes
src/State/Provider/ParameterProvider.php: inject the existingPaginationOptionsservice and whitelistpage/itemsPerPage/pagination/partialforCollectionOperationInterfaceoperations during strict validation, mirroring the exact conditionsOpenApiFactory::getPaginationParameters()already uses (so docs and validation agree, including with renamed pagination parameters via the global config). Also fixed a latent null-safety warning on the same line (foreachovergetParameters()when it'snull, which is the common case for a collection operation with no filters).src/Validator/Metadata/Resource/Factory/ParameterValidationResourceMetadataCollectionFactory.php: the0 === $parameters->count()guard now excludes parameters injected purely from globaldefaults.parameters, so declaring a global default parameter no longer disables filter-based whitelisting for every other operation.src/Symfony/Bundle/Resources/config/state/provider.php: wireapi_platform.pagination_optionsinto theParameterProviderservice.src/Laravel/ApiPlatformDeferredProvider.php: same wiring for Laravel'sParameterProviderregistration (already hadPaginationOptionsbound).Tests
src/State/Tests/ParameterProviderTest.php: unit tests covering pagination whitelisting, unknown-parameter rejection, item-operation scoping (pagination params aren't whitelisted on non-collection operations), renamed pagination parameters (e.g.itemsPerPage→_limitvia global config), and BC whenPaginationOptionsisn't injected.src/Validator/Tests/Metadata/Resource/Factory/ParameterValidationResourceMetadataCollectionFactoryTest.php(new): reproduces thedefaults.parameters-defeats-filter-whitelisting bug directly against the factory.tests/Functional/Parameters/StrictParametersCollectionTest.php+ new fixturetests/Fixtures/TestBundle/ApiResource/StrictParametersCollection.php: full HTTP-level reproduction of the exactParameter "page" not supportederror from the issue report, and confirmation that unknown parameters are still correctly rejected.All new tests fail against the code prior to this PR and pass after. Existing test suites (
src/State,src/Validator,tests/Functional/Parameters/StrictParametersTest,tests/Functional/DefaultParametersTest) pass unmodified, confirming no regression to OpenAPI doc generation or existing strict-validation behavior.