Skip to content

Commit

Permalink
docs(subresources): add yaml examples (#1788)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttskch authored Aug 10, 2023
1 parent c127a04 commit ec29ce6
Showing 1 changed file with 35 additions and 0 deletions.
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

0 comments on commit ec29ce6

Please sign in to comment.