Added OpenAPI docs using nelmioAPIDocBundle.
CI / Docker Lint (push) Successful in 21s

This commit is contained in:
2024-09-20 21:29:23 +02:00
parent 0cf6f231a3
commit bfcd04c701
18 changed files with 610 additions and 20 deletions
+41 -4
View File
@@ -7,16 +7,36 @@ use Doctrine\ORM\EntityManagerInterface;
use App\Repository\RoomCategoryRepository;
use App\Entity\RoomCategory;
use App\Entity\RoomCategoryPhoto;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Annotations\Property;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\Context\Normalizer\ObjectNormalizerContextBuilder;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpKernel\Exception\HttpException;
class RoomCategoryController extends AbstractController
{
#[Route('/api/room/category', name: 'app_room_AllCategories')]
/**
* Get All room categories.
*/
#[Route('/api/room/category', name: 'app_room_AllCategories', methods: ["GET"])]
#[OA\Tag(name: "Rooms")]
#[OA\Response(
response: 200,
description: 'Returns all room categories',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(
property: "results",
type: "array",
items: new OA\Items(ref: new Model(type: RoomCategory::class))
)
]
)
)]
public function getAll(RoomCategoryRepository $catRepo): Response
{
$catList = $catRepo->findAll();
@@ -24,7 +44,24 @@ class RoomCategoryController extends AbstractController
return $this->json(["results" => $catList]);
}
#[Route('/api/room/category/{id}', name: 'app_room_category')]
/**
* Get a room category by ID.
*/
#[Route('/api/room/category/{id}', name: 'app_room_category', methods: ["GET"])]
#[OA\Tag(name: "Rooms")]
#[OA\Response(
response: 200,
description: 'Returns a room category',
content: new OA\JsonContent(
type: 'object',
ref: new Model(type: RoomCategory::class),
)
)]
#[OA\Parameter(
name: 'id',
in: 'path',
description: 'RoomCategory ID',
)]
public function getById(RoomCategory $category): Response
{
return $this->json($category);