Skip to content

fix(jsonapi): keep flat custom params with flat page (#8216)#8217

Merged
soyuka merged 2 commits into
api-platform:4.3from
soyuka:fix/8216
Jun 1, 2026
Merged

fix(jsonapi): keep flat custom params with flat page (#8216)#8217
soyuka merged 2 commits into
api-platform:4.3from
soyuka:fix/8216

Conversation

@soyuka

@soyuka soyuka commented Jun 1, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #8216 — regression introduced in #8193.

JsonApiProvider was setting _api_filters from flat pagination params
(page, itemsPerPage, pagination, partial) even when no filter[...]
bracket was present. ReadProvider:63-65 short-circuits its raw query
fallback (RequestParser::parseRequestParams) whenever _api_filters is
non-null, so any flat custom filter (?city_id=3&order[distance]=asc)
combined with page=N was silently dropped.

Fix

Parse the raw query string in JsonApiProvider and merge it as a base
layer under the existing JSON:API transformations:

$queryString = RequestParser::getQueryString($request);
$rawParams = $queryString ? RequestParser::parseRequestParams($queryString) : [];
$filters = array_replace($rawParams, $filters);

JSON:API transformations (sortorder, filter[foo]foo, flat
pagination keys) still take precedence via array_replace.

Tests

  • Unit (JsonApiProviderTest::testProvidePreservesFlatCustomQueryParamsWithoutBracketFilter)
    asserts _api_filters contains city_id, order, and page after the
    provider runs.
  • Functional (JsonApiFlatPaginationTest::testFlatCustomParamWithFlatPagePreservesFilter)
    hits /dummies?name=foo&page=1 w/ Accept: application/vnd.api+json and
    asserts the SearchFilter is applied (totalItems === 5 out of 6 fixtures).
    Verified the functional test fails on the prior code (returns 6).

Test plan

  • vendor/bin/phpunit src/JsonApi/Tests/State/JsonApiProviderTest.php
  • vendor/bin/phpunit tests/Functional/JsonApiFlatPaginationTest.php
  • Confirmed functional test fails without the patch (asserts 6 === 5).

soyuka added 2 commits June 1, 2026 10:44
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.
@soyuka soyuka merged commit 37e3613 into api-platform:4.3 Jun 1, 2026
117 of 120 checks passed
@soyuka soyuka deleted the fix/8216 branch June 1, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant