0
votes

API Platform version(s) affected: 2.5.6

Description
Following this documentation: https://api-platform.com/docs/core/subresources/#using-custom-paths

I try to override the path (and security, and requirements) of a subresource.

It works for the security, but not for path (and so requirements).

How to reproduce
Clone this repo and follow the very small README : https://github.com/bastoune/api-platform-issue-1581

Having this route with debug:router : api_organizations_users_get_subresource GET ANY ANY /v2/organizations/{id}/users.{_format} and this annotation :

 *      subresourceOperations={
 *          "api_organizations_users_get_subresource"={
 *              "method"="GET",
 *              "path"="/TEEEST/organizations/{organization_id}/users",
 *              "requirements"={"organization_id": StringHelper::UUIDv4Regex},
 *              "security"="is_granted('readOrganization', organization_id)"
 *          }
 *      }

The security works but not the rest.

If I remove the security, it doesn't work anyway.

1
I checked your User Entity and found that you have not put @ApiSubResource annotation on $organisations - Vipulw
@Vipulw, yes the SubResource is the User not the Organization - BastienSander
What I understand from subresource is that we can fetch OneToMany realtions of some Entity with that path by providing it's id. So, if you want to get all users of an organisation then you should add @ApiSubResource to $user in Organization Entity and do the subresource configuration there. - Vipulw
@ApiSubresource is well in the Organization->$user And, wherever (In User OR Organiztion) I put the subresource configuration, i get the same result. - BastienSander

1 Answers

3
votes

As mentioned here : https://github.com/api-platform/api-platform/issues/1581#issuecomment-662503549

There is a bug with the operation name:

Try with "users_get_subresource" as operation name (instead of "api_organizations_users_get_subresource"). api-platform/docs#1109

This PR was merge api-platform/docs#370 but this commit revert the changes api-platform/docs@b8304bc