fix(serializer): warn when readableLink false cannot be honored on untyped collections#8256
Closed
soyuka wants to merge 1 commit into
Closed
Conversation
a6ed7ac to
6cb8079
Compare
…typed collections When a property is annotated readableLink: false but its element type cannot be resolved (e.g. `getFoos(): array` without `@return list<X>` phpdoc and without `#[ApiProperty(nativeType: ...)]`), the to-many resource arm in AbstractItemNormalizer::getAttributeValue cannot match and the inner serializer embeds the related objects — silently ignoring the user's intent. Rather than peeking at runtime values (which would silently rescue misconfiguration and diverge runtime from declared type), trigger a deprecation in dev pointing the user to declare the element type. The canonical to-many arm already honors readableLink: false correctly when the element type is declared. Refs api-platform#8179
6cb8079 to
a72054f
Compare
Member
Author
|
Closing without merge. The runtime-peek approach was rejected (silently rescues misconfiguration), and a deprecation warning was deemed unnecessary noise on top of clear docs. #8179 closed as a configuration concern — see api-platform/docs#2289 for user guidance. |
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
#8179 turned out to be a config issue, not a framework bug. When a property is annotated
readableLink: falsebut its element type cannot be resolved (e.g.getFoos(): arraywithout@return list<X>phpdoc and without#[ApiProperty(nativeType: ...)]),PropertyInforeportsarray<mixed>. The to-many resource arm inAbstractItemNormalizer::getAttributeValuecannot match, so the inner serializer embeds related objects — silently ignoring the user's intent.Rather than peek runtime values to recover the resource class (which would silently rescue misconfiguration and diverge runtime from declared type), this PR triggers a deprecation in dev pointing the user to declare the element type. The canonical to-many arm already honors
readableLink: falsecorrectly when the element type is statically declarable.Remedies for users
@return list<\App\ApiResource\Api>on the getter (requiresphpstan/phpdoc-parser).#[ApiProperty(nativeType: Type::list(Type::object(Api::class)))].Collection<int, Api>property.Test plan
4.3, proving the canonical path always worked).readableLink: falseIRI (sanity).Companion
Docs PR: api-platform/docs#2289
Refs #8179