core
core copied to clipboard
Custom uri variable for DTO doesn't work
API Platform version(s) affected: 3.3.11
Description
For 3.2.21 version it worked, what needs to be done to make it work for 3.3.11?
#[Get(
uriTemplate: '/notifications/unread_count/{type}',
uriVariables: [
'type' => 'system|non_system|all',
],
output: UnreadNotificationsCount::class,
provider: UnreadNotificationsCountProvider::class,
)]
final readonly class UnreadNotificationsCount
{
public function __construct(
public int $count,
) {
}
}
After update on v3.3.11 I get an error
"detail": "Unable to generate an IRI for the item of type \"App\\DTO\\Notification\\UnreadNotificationsCount\"",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/srv/app/vendor/api-platform/core/src/Symfony/Routing/IriConverter.php",
"line": 194,
"args": []
},
The root of the issue is that we get into the getIriFromResource method twice and the second time the context is an empty array
Due this commit https://github.com/api-platform/core/commit/cc9f6a518222598d20556fc1ec62b7c4be52bf52#diff-60bc22662b6ae1820b895aa95e88e86cb6e9bc227f03bb00d5589d494886eca3R73
@soyuka Hello, why don't we pass $context further here
https://github.com/api-platform/core/blob/v3.3.11/src/State/Processor/RespondProcessor.php#L115
It's because it could not find identifiers? Context is reset for embed resources it's expected
The identifier all in my case was found, if it had not been found we would have received an InvalidArgumentException here
https://github.com/api-platform/core/blob/v3.3.11/src/Symfony/Routing/IriConverter.php#L194
The root of the issue is that we get into the getIriFromResource method twice and the second time the context is an empty array after the reset occurred as you said for embed resources.
The identifiers extractor is supposed to find the uri variables from the $originalData at https://github.com/api-platform/core/blob/v3.3.11/src/State/Processor/RespondProcessor.php#L115
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.