diff --git a/core/subresources.md b/core/subresources.md index fc5f2bd96ff..e60ce6f196c 100644 --- a/core/subresources.md +++ b/core/subresources.md @@ -140,7 +140,7 @@ use ApiPlatform\Core\Annotation\ApiResource; /** * @ApiResource(subresourceOperations={ - * "api_questions_answer_get_subresource"={ + * "answer_get"={ * "method"="GET", * "normalization_context"={"groups"={"foobar"}} * } @@ -158,7 +158,7 @@ Or using YAML: # api/config/api_platform/resources.yaml App\Entity\Answer: subresourceOperations: - api_questions_answer_get_subresource: + answer_get: method: 'GET' normalization_context: {groups: ['foobar']} ``` @@ -175,7 +175,7 @@ Or in XML: https://api-platform.com/schema/metadata/metadata-2.0.xsd"> - + GET @@ -191,9 +191,12 @@ Or in XML: In the previous examples, the `method` attribute is mandatory, because the operation name doesn't match a supported HTTP method. -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`. +Note that the operation name, here `answer_get`, is the important keyword. +It's a shortcut name for the operation id: `api_$resources_$subresource(s)_get_subresource`. +If you want to customize a nested operation (`question/{id}/answer/question`), the operation name will match the nesting order (`answer_question_get`) + +You may find the correct operation name by using `bin/console debug:router`, +then remove the prefix `api_$resources` and the suffix `_subresource`. ## Using Custom Paths @@ -207,7 +210,7 @@ You can control the path of subresources with the `path` option of the `subresou * ... * @ApiResource( * subresourceOperations={ - * "api_questions_answer_get_subresource"={ + * "answer_get"={ * "method"="GET", * "path"="/questions/{id}/all-answers" * }, @@ -231,7 +234,7 @@ The `subresourceOperations` attribute also allows you to add an access control o * ... * @ApiResource( * subresourceOperations={ - * "api_questions_answer_get_subresource"= { + * "answer_get"= { * "security"="has_role('ROLE_AUTHENTICATED')" * } * }