Skip to content

Doc. how to change the path of a subresource #370

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

Merged
merged 2 commits into from
Dec 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,31 @@ Note that the operation name, here `api_questions_answer_get_subresource`, is th
It'll be automatically set to `$resources_$subresource(s)_get_subresource`. To find the correct operation name you
may use `bin/console debug:router`.

### Control the depth of subresources
### Control the Path of Subresources

You can control the path of subresources with the `path` option of the `subresourceOperations` parameter:

```php
<?php
// src/AppBundle/Entity/Question.php

/**
* @ORM\Entity()
* @ApiResource(
* subresourceOperations={
* "answer_get_subresource"= {
* "method"="GET",
* "path"="/questions/{id}/all-answers",
* },
* },
* )
*/
class Question
{
}
```

### Control the Depth of Subresources

You can control depth of subresources with the parameter `maxDepth`. For example, if `Answer` entity also have subresource such as `comments`and you don't want the route `api/questions/{id}/answers/{id}/comments` to be generated. You can do this by adding the parameter maxDepth in ApiSubresource annotation or yml/xml file configuration.

Expand Down