Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom uri variable for DTO doesn't work #6524

Open
NikDevPHP opened this issue Aug 20, 2024 · 5 comments
Open

Custom uri variable for DTO doesn't work #6524

NikDevPHP opened this issue Aug 20, 2024 · 5 comments

Comments

@NikDevPHP
Copy link

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": []
    },
@NikDevPHP
Copy link
Author

NikDevPHP commented Aug 21, 2024

image

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
cc9f6a5#diff-60bc22662b6ae1820b895aa95e88e86cb6e9bc227f03bb00d5589d494886eca3R73

@NikDevPHP
Copy link
Author

@soyuka
Copy link
Member

soyuka commented Aug 21, 2024

It's because it could not find identifiers? Context is reset for embed resources it's expected

@NikDevPHP
Copy link
Author

NikDevPHP commented Aug 21, 2024

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.

@soyuka
Copy link
Member

soyuka commented Aug 29, 2024

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

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

No branches or pull requests

2 participants