Skip to content

Commit

Permalink
Merge pull request #779 from borNfreee/patch-2
Browse files Browse the repository at this point in the history
Fix incorrect docs for subresource operations
  • Loading branch information
soyuka authored Apr 4, 2019
2 parents 361a588 + 7100414 commit afae479
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ If you put the subresource on a relation that is to-many, you will retrieve a co

Last but not least, subresources can be nested, such that `/questions/42/answer/comments` will get the collection of comments for the answer to question 42.

You may want custom groups on subresources. Because a subresource is nothing more than a collection operation, you can set `normalization_context` or `denormalization_context` on that operation. To do so, you need to override `collectionOperations`. Based on the above operation, because we retrieve an answer, we need to alter its configuration:
You may want custom groups on subresources. Because a subresource is nothing more than a collection operation, you can set `normalization_context` or `denormalization_context` on that operation. To do so, you need to override `subresourceOperations`. Based on the above operation, because we retrieve an answer, we need to alter its configuration:

```php
<?php
Expand All @@ -387,7 +387,7 @@ namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
/**
* @ApiResource(collectionOperations={
* @ApiResource(subresourceOperations={
* "api_questions_answer_get_subresource"={
* "method"="GET",
* "normalization_context"={"groups"={"foobar"}}
Expand All @@ -405,7 +405,7 @@ Or using YAML:
```yaml
# api/config/api_platform/resources.yaml
App\Entity\Answer:
collectionOperations:
subresourceOperations:
api_questions_answer_get_subresource:
normalization_context: {groups: ['foobar']}
```
Expand All @@ -421,16 +421,16 @@ Or in XML:
xsi:schemaLocation="https://api-platform.com/schema/metadata
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
<resource class="App\Entity\Answer">
<collectionOperations>
<collectionOperation name="api_questions_answer_get_subresource">
<subresourceOperations>
<subresourceOperation name="api_questions_answer_get_subresource">
<attribute name="method">GET</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>foobar</attribute>
</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
</subresourceOperation>
</subresourceOperations>
</resource>
</resources>
```
Expand Down

0 comments on commit afae479

Please sign in to comment.