Skip to content
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

Fix incorrect docs for subresource operations #779

Merged
merged 3 commits into from
Apr 4, 2019
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
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a subresource is nothing more than a collection operation

This part needs to be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think this whole paragraph needs to be rewritten. I'll take care of it, if no one gets to it before me.


```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