Skip to content

Commit ec29ce6

Browse files
authored
docs(subresources): add yaml examples (#1788)
1 parent c127a04 commit ec29ce6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

core/subresources.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class Question
8181
}
8282
```
8383

84+
```yaml
85+
# api/config/api_platform/resources.yaml
86+
resources:
87+
App\Entity\Answer: ~
88+
App\Entity\Question: ~
89+
```
90+
8491
```xml
8592
<?xml version="1.0" encoding="UTF-8" ?>
8693
<!-- api/config/api_platform/resources.xml -->
@@ -129,6 +136,21 @@ class Answer
129136
}
130137
```
131138

139+
```yaml
140+
# api/config/api_platform/resources.yaml
141+
resources:
142+
App\Entity\Answer:
143+
uriTemplate: /questions/{id}/answer
144+
uriVariable:
145+
id:
146+
fromClass: App\Entity\Question
147+
fromProperty: answer
148+
operations:
149+
ApiPlatform\Metadata\Get: ~
150+
151+
App\Entity\Question: ~
152+
```
153+
132154
```xml
133155
<resources xmlns="https://api-platform.com/schema/metadata/resources-3.0"
134156
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -173,6 +195,19 @@ If we had a `relatedQuestions` property on the `Answer` we could retrieve the co
173195
)]
174196
```
175197

198+
```yaml
199+
# api/config/api_platform/resources.yaml
200+
resources:
201+
App\Entity\Question:
202+
uriTemplate: /answers/{id}/related_questions.{_format}
203+
uriVariable:
204+
id:
205+
fromClass: App\Entity\Answer
206+
fromProperty: relatedQuestions
207+
operations:
208+
ApiPlatform\Metadata\GetCollection: ~
209+
```
210+
176211
```xml
177212
<resource class="App\Entity\Question" uriTemplate="/answers/{id}/related_questions.{_format}">
178213
<uriVariables>

0 commit comments

Comments
 (0)