Skip to content

Commit 12af1a4

Browse files
committed
add multiple response types
1 parent 42c5320 commit 12af1a4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final class PostController extends AbstractController
6262
#[Route('/post', methods: ['GET'])]
6363
public function getAll(#[Query] ?string $filter): PostCollection
6464
{
65-
return $this->repository->findAll();
65+
return $this->repository->findAll($filter);
6666
}
6767

6868
#[Route('/post/{id}', methods: ['GET'])]
@@ -120,6 +120,25 @@ public function update(#[Body] Json $body): Json
120120
}
121121
```
122122

123+
### Multiple response types
124+
125+
In case your method can return different response types you can use the `#[Outgoing]` attribute to
126+
define a response schema independent of the return type.
127+
128+
```php
129+
#[Route('/post', methods: ['POST'])]
130+
#[Outgoing(201, Message::class)]
131+
#[Outgoing(400, Error::class)]
132+
public function update(#[Body] Post $body): JsonResponse
133+
{
134+
if (empty($body->getTitle())) {
135+
return new JsonResponse(['error' => 'An error occurred'], 400);
136+
}
137+
138+
return new JsonResponse(['success' => true], 201);
139+
}
140+
```
141+
123142
## Generator
124143

125144
### SDK

0 commit comments

Comments
 (0)