Skip to content

docs(subresources): add yaml examples #1788

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 1 commit into from
Aug 10, 2023
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
35 changes: 35 additions & 0 deletions core/subresources.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ class Question
}
```

```yaml
# api/config/api_platform/resources.yaml
resources:
App\Entity\Answer: ~
App\Entity\Question: ~
```

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<!-- api/config/api_platform/resources.xml -->
Expand Down Expand Up @@ -129,6 +136,21 @@ class Answer
}
```

```yaml
# api/config/api_platform/resources.yaml
resources:
App\Entity\Answer:
uriTemplate: /questions/{id}/answer
uriVariable:
id:
fromClass: App\Entity\Question
fromProperty: answer
operations:
ApiPlatform\Metadata\Get: ~

App\Entity\Question: ~
```

```xml
<resources xmlns="https://api-platform.com/schema/metadata/resources-3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down Expand Up @@ -173,6 +195,19 @@ If we had a `relatedQuestions` property on the `Answer` we could retrieve the co
)]
```

```yaml
# api/config/api_platform/resources.yaml
resources:
App\Entity\Question:
uriTemplate: /answers/{id}/related_questions.{_format}
uriVariable:
id:
fromClass: App\Entity\Answer
fromProperty: relatedQuestions
operations:
ApiPlatform\Metadata\GetCollection: ~
```

```xml
<resource class="App\Entity\Question" uriTemplate="/answers/{id}/related_questions.{_format}">
<uriVariables>
Expand Down