Skip to content

Commit edea80a

Browse files
jbdelhommeaudunglas
authored andcommitted
Add XML and YAML DTOs config examples (#790)
* Add XML and YAML DTOs config examples * Update core/dto.md Co-Authored-By: jbdelhommeau <[email protected]> * Update dto.md
1 parent d7262fb commit edea80a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

core/dto.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ final class Book
2626
}
2727
```
2828

29+
Or using XML:
30+
31+
```xml
32+
<?xml version="1.0" encoding="UTF-8" ?>
33+
<!-- api/config/api_platform/resources.xml -->
34+
35+
<resources xmlns="https://api-platform.com/schema/metadata"
36+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
37+
xsi:schemaLocation="https://api-platform.com/schema/metadata
38+
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
39+
<resource class="App\Entity\Book">
40+
<attribute name="input">App\Dto\BookInput</attribute>
41+
<attribute name="output">App\Dto\BookOutput</attribute>
42+
</resource>
43+
</resources>
44+
```
45+
46+
Or using YAML:
47+
48+
```yaml
49+
# api/config/api_platform/resources.yaml
50+
resources:
51+
App\Entity\Book:
52+
attributes:
53+
input: App\Dto\BookInput
54+
output: App\Dto\BookOutput
55+
```
56+
2957
The `input` attribute is used during [the deserialization process](serialization.md), when transforming the user-provided data to a resource instance.
3058
Similarly, the `output` attribute is used during [the serialization process](serialization.md). This class represents how the `Book` resource will be represented in the `Response`.
3159

0 commit comments

Comments
 (0)