From f43f309f1e8fe96a1b7b4e5772eef90b66c301c0 Mon Sep 17 00:00:00 2001 From: lgromero Date: Thu, 3 Oct 2024 15:01:54 +0200 Subject: [PATCH] refs #797 adds a anyof property to control 400 error message in addSubnet swagger doc --- src/DhcpBundle/Controller/DhcpController.php | 73 +++++--------------- 1 file changed, 18 insertions(+), 55 deletions(-) diff --git a/src/DhcpBundle/Controller/DhcpController.php b/src/DhcpBundle/Controller/DhcpController.php index bfa3016..6a3604f 100644 --- a/src/DhcpBundle/Controller/DhcpController.php +++ b/src/DhcpBundle/Controller/DhcpController.php @@ -203,6 +203,7 @@ class DhcpController /** * @OA\Get( * path="/ogdhcp/v1/subnets", + * summary="Obtiene todas las subredes DHCP", * @OA\Response( * response=200, * description="Devuelve todas las subredes", @@ -214,6 +215,8 @@ class DhcpController * type="object", * @OA\Property(property="id", type="integer", example=1), * @OA\Property(property="subnet", type="string", example="192.168.1.0/24"), + * @OA\Property(property="next-server", type="string", example="192.168.1.1"), + * @OA\Property(property="boot-file-name", type="string", example="pxelinux.0"), * @OA\Property(property="pools", type="array", * @OA\Items( * type="object", @@ -223,8 +226,10 @@ class DhcpController * @OA\Property(property="reservations", type="array", * @OA\Items( * type="object", - * @OA\Property(property="ip-address", type="string", example="192.168.1.20"), - * @OA\Property(property="hw-address", type="string", example="00:0c:29:6b:5e:71") + * + * @OA\Property(property="ip-address", type="string", example="192.168.1.11"), + * @OA\Property(property="hw-address", type="string", example="00:0c:29:6b:5e:71"), + * @OA\Property(property="hostname", type="string", example="PC11") * ) * ) * ) @@ -241,7 +246,8 @@ class DhcpController * ) * ) * @Route("/ogdhcp/v1/subnets", methods={"GET"}) - */ + */ + public function getSubnets(): JsonResponse { try { @@ -308,6 +314,14 @@ public function getSubnets(): JsonResponse * type="object", * @OA\Property(property="error", type="string", example="Error: La subred con el nombre 'subnetName' ya existe.") * ) + * ), + * @OA\Response( + * response=400, + * description="Error occurred while adding the subnet", + * @OA\JsonContent( + * type="object", + * @OA\Property(property="error", type="string", example="Error: La subred con el ID 'subnetId' ya existe.") + * ) * ) * ) * @Route("/ogdhcp/v1/subnets", methods={"POST"}) @@ -351,58 +365,7 @@ public function getSubnets(): JsonResponse $subnetIdExists = array_reduce($subnets, function ($exists, $subnetElement) use ($subnetId) { return $exists || ($subnetElement['id'] === $subnetId); - }, false); /** - * @OA\Post( - * path="/ogdhcp/v1/subnets", - * summary="Add a new DHCP subnet", - * @OA\RequestBody( - * description="JSON payload to create a new subnet", - * required=true, - * @OA\JsonContent( - * type="object", - * @OA\Property(property="subnetId", type="integer", example=2), - * @OA\Property(property="mask", type="string", example="255.255.255.0"), - * @OA\Property(property="address", type="string", example="192.168.1.0"), - * @OA\Property(property="nextServer", type="string", example="192.168.1.1"), - * @OA\Property(property="bootFileName", type="string", example="pxelinux.0") - * ) - * ), - * @OA\Response( - * response=200, - * description="Subnet added successfully", - * @OA\JsonContent( - * type="object", - * @OA\Property(property="success", type="string", example="Subnet added successfully"), - * @OA\Property(property="message", type="object", - * @OA\Property(property="subnetId", type="integer", example=2), - * @OA\Property(property="subnet", type="string", example="192.168.1.0/24"), - * @OA\Property(property="nextServer", type="string", example="192.168.1.1"), - * @OA\Property(property="bootFileName", type="string", example="pxelinux.0"), - * @OA\Property(property="reservations", type="array", @OA\Items(type="object")) - * ) - * ) - * ), - * @OA\Response( - * response=400, - * description="Error occurred while adding the subnet", - * @OA\JsonContent( - * type="object", - * @OA\Property(property="error", type="string", example="Error: La subred con el nombre 'subnetName' ya existe.") - * ) - * ), - * @OA\Response( - * response=400, - * description="Error occurred while adding the subnet", - * @OA\JsonContent( - * type="object", - * @OA\Property(property="error", type="string", example="Error: La subred con el ID 'subnetId' ya existe.") - * ) - * ) - * ) - * @Route("/ogdhcp/v1/subnets", methods={"POST"}) - */ - - // Controlar las salidas para los diferentes casos + }, false); if ($subnetNameExists) { $responseError = "Error: La subred con el nombre '$subnetName' ya existe."; return new JsonResponse(['error' => $responseError], 400);