Skip to content

Broken behavior processing operations with defined 'output' class #2803

Description

@Perf

Hello,
an exception is thrown when processing request by WriteListener.php.
At line 81 there is a call to get Iri from object of output class. But, obviously, it's not always possible, as the output class could be another object rather than ApiResource.

if ($hasOutput) {
    $request->attributes->set('_api_write_item_iri', $this->iriConverter->getIriFromItem($controllerResult));
}

Exception:

No item route associated with the type "Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationSuccessResponse" at /srv/api/vendor/api-platform/core/src/Bridge/Symfony/Routing/RouteNameResolver.php line 62

Here is a sample configuration of a custom operation:

    collectionOperations:
        confirmation:
            method: 'POST'
            path: '/users/confirmation'
            access_control: 'is_anonymous()'
            messenger: 'input'
            input: 'App\Entity\User\Input\UserConfirm'
            output: 'Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationSuccessResponse'

Some additional notes:
There was a related issue #2550 that was fixed with #2628.
It worked for a while... and seems to be was 'broken' with: 433ce07#diff-3bc4e0ec1a3570f4deb961f3652800a6
So, now $hasOutput gets true at line 77, because now $controllerResult is an instance of $outputMetadata['class']

$hasOutput = \array_key_exists('class', $outputMetadata) && null !== $outputMetadata['class'] && $controllerResult instanceof $outputMetadata['class'];

which it totally correct... but this leads to improper call of
$request->attributes->set('_api_write_item_iri', $this->iriConverter->getIriFromItem($controllerResult));

Imho, at line 80 it's necessary to add additional check, if object in $controllerResult is an "ApiResource" object.

Metadata

Metadata

Assignees

Labels

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions