Skip to content

Commit

Permalink
add multiple response types
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Dec 31, 2024
1 parent 42c5320 commit 12af1a4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class PostController extends AbstractController
#[Route('/post', methods: ['GET'])]
public function getAll(#[Query] ?string $filter): PostCollection
{
return $this->repository->findAll();
return $this->repository->findAll($filter);
}

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

### Multiple response types

In case your method can return different response types you can use the `#[Outgoing]` attribute to
define a response schema independent of the return type.

```php
#[Route('/post', methods: ['POST'])]
#[Outgoing(201, Message::class)]
#[Outgoing(400, Error::class)]
public function update(#[Body] Post $body): JsonResponse
{
if (empty($body->getTitle())) {
return new JsonResponse(['error' => 'An error occurred'], 400);
}

return new JsonResponse(['success' => true], 201);
}
```

## Generator

### SDK
Expand Down

0 comments on commit 12af1a4

Please sign in to comment.