fix(jsonapi): keep flat custom params with flat page (#8216)#8217
Merged
Conversation
PR api-platform#8193 set `_api_filters` from flat pagination params even when no `filter[...]` bracket was present. `ReadProvider` then skipped its raw query fallback (`parseRequestParams`), silently dropping flat custom filter params like `?city_id=3&order[distance]=asc&page=1`. Parse the raw query string in `JsonApiProvider` and merge it as a base layer; JSON:API transformations still win via `array_replace`. fixes api-platform#8216
Use the documented `_api_query_parameters` request attribute as the source of truth for raw query parsing. ParameterProvider already populates it before JsonApiProvider runs (see ReadListener), and users can pre-populate it from a custom listener to replace the default parsing. Falls back to `RequestParser::parseRequestParams` when the attribute is unset (GraphQL, Laravel, or any setup without ParameterProvider) and writes the parsed result back so downstream code sees the same shape.
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.
Summary
Fixes #8216 — regression introduced in #8193.
JsonApiProviderwas setting_api_filtersfrom flat pagination params(
page,itemsPerPage,pagination,partial) even when nofilter[...]bracket was present.
ReadProvider:63-65short-circuits its raw queryfallback (
RequestParser::parseRequestParams) whenever_api_filtersisnon-null, so any flat custom filter (
?city_id=3&order[distance]=asc)combined with
page=Nwas silently dropped.Fix
Parse the raw query string in
JsonApiProviderand merge it as a baselayer under the existing JSON:API transformations:
JSON:API transformations (
sort→order,filter[foo]→foo, flatpagination keys) still take precedence via
array_replace.Tests
JsonApiProviderTest::testProvidePreservesFlatCustomQueryParamsWithoutBracketFilter)asserts
_api_filterscontainscity_id,order, andpageafter theprovider runs.
JsonApiFlatPaginationTest::testFlatCustomParamWithFlatPagePreservesFilter)hits
/dummies?name=foo&page=1w/Accept: application/vnd.api+jsonandasserts the SearchFilter is applied (
totalItems === 5out of 6 fixtures).Verified the functional test fails on the prior code (returns 6).
Test plan
vendor/bin/phpunit src/JsonApi/Tests/State/JsonApiProviderTest.phpvendor/bin/phpunit tests/Functional/JsonApiFlatPaginationTest.php