fix(serializer): honor readableLink false for array-backed relation getters#8256
Open
soyuka wants to merge 2 commits into
Open
fix(serializer): honor readableLink false for array-backed relation getters#8256soyuka wants to merge 2 commits into
soyuka wants to merge 2 commits into
Conversation
…etters When a property is exposed via an array-typed getter (e.g. `getExchangeApis(): array`) without phpstan/phpdoc-parser installed, PropertyInfo can only report `array<mixed>`. The to-many resource arm in AbstractItemNormalizer::getAttributeValue therefore missed the property and delegated to the inner serializer, which embedded the related resources even though the user set `readableLink: false`. When the user opts out of embedding and the runtime value is iterable, inspect the items: if any are resource objects, normalize the collection via normalizeCollectionOfRelations so IRIs are emitted. Fixes api-platform#8179
…ters Reproduces api-platform#8179 end-to-end: a Client resource exposes an array-backed getter `getExchangeApis(): array` with `readableLink: false` and the response must surface IRIs, not embedded objects. The companion to-one relation acts as a sanity case. The fixture has no `@return list<Api>` phpdoc on the getter on purpose, so PropertyInfo cannot refine the element type even with phpstan/phpdoc-parser installed — that is the exact path the production fix in a6ed7ac closes.
a6ed7ac to
6cb8079
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.
Summary
When a relation getter returns plain
array(no phpstan/phpdoc-parser to refine the generic type),PropertyInfoonly reportsarray<mixed>. The to-many resource arm ofAbstractItemNormalizer::getAttributeValuemisses the property and delegates to the inner serializer, which embeds the related resources even whenreadableLink: false. The fix inspects the runtime values: if any are resource objects and the user opted out of embedding, normalize the collection vianormalizeCollectionOfRelationsso IRIs are emitted.Reproduction
A resource property exposed via
public function getExchangeApis(): arraywith#[ApiProperty(readableLink: false)]still emitted embedded JSON-LD objects instead of IRI references.Test plan
readableLink: false.Fixes #8179