Skip to content

fix(jsonapi): denormalize sparse fieldset names with the name converter - #8861

Merged
soyuka merged 2 commits into
api-platform:5.0from
MikeFTV:fix/sparse-fieldset-name-converter
Nov 20, 2026
Merged

soyuka merged 2 commits into
api-platform:5.0from
MikeFTV:fix/sparse-fieldset-name-converter

Conversation

@MikeFTV

@MikeFTV MikeFTV commented Nov 19, 2026

Copy link
Copy Markdown
Contributor
Q A
Branch? 5.0
Tickets Part of #8860 (the name converter case)
License MIT
Doc PR n/a

With a name converter, SparseFieldsetParameterProvider compared the field names sent by the client (artist_credit) with the PHP property names (artistCredit), so every converted field was dropped from fields[TYPE]. It now denormalizes each requested field through api_platform.name_converter before matching it and adding it to the whitelist, as PropertyFilter does. The converter is an optional last constructor argument, so the change is backward compatible; the Symfony service passes it with ignoreOnInvalid(), like the other services that use it.

The functional test is tests/Functional/JsonApi/SparseFieldsetNameConverterTest.php. It uses a new fixture, SparseFieldsetNameConverted, and the test app's CustomConverter, which serializes nameConverted as name_converted:

$response = self::createClient()->request(
    'GET',
    '/sparse_fieldset_name_converted/1?fields[SparseFieldsetNameConverted]=title,name_converted',
    ['headers' => ['Accept' => 'application/vnd.api+json']],
);

$this->assertSame(
    ['title' => 'Title #1', 'name_converted' => 'Converted #1'],
    $response->toArray()['data']['attributes'],
);

Without the fix, name_converted is missing from the attributes and the test fails. With the fix, it passes. A unit test was also added to SparseFieldsetParameterProviderTest (testFieldsAreDenormalizedWithTheNameConverter), and PHPStan reports no errors on the provider.

The second case in the issue (stateOptions limiting the primary type to the entity's properties) is left out. Building the allowed properties from the resource class would also widen a properties list set explicitly on the parameter, so that change needs a maintainer decision first.

@soyuka
soyuka merged commit 824eaec into api-platform:5.0 Nov 20, 2026
114 of 115 checks passed
@MikeFTV

MikeFTV commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging, and for the comment cleanup. I'll keep comments out of tests next time.

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.

2 participants