-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Hello !
I found myself struggling to have a custom path for a subresource.
https://api-platform.com/docs/core/subresources/#using-custom-paths
First, it should be highlighted that the subresource annotation for a custom path need to be on the owning entity (which is logic by the way).
Second, and more importantly, the operation name in that case is not as described below :
Note that the operation name, here api_questions_answer_get_subresource, is the important keyword. It'll be automatically set to
$resources_$subresource(s)_get_subresource
. To find the correct operation name you may use bin/console debug:router.
The relevant code where "operation_name" is defined (https://github.com/api-platform/core/blob/master/src/Operation/Factory/SubresourceOperationFactory.php#L113)
$operation['operation_name'] = sprintf(
'%s_%s%s',
RouteNameGenerator::inflector($operation['property'], $operation['collection'] ?? false),
$operationName,
self::SUBRESOURCE_SUFFIX
);
Here the operation_name is more like $subresource(s)_get_subresource
without the $resource_
prefix.
Again, seems logi. As we are in the owning entity we don't need to define the root resource.
Right now I don't know if there is a way to get the right operation_name
with an command like debug:router
.
I could PR the documentation if I am correct.