refs #797 adds a anyof property to control 400 error message in addSubnet swagger doc
testing/og-dhcp-API/pipeline/head There was a failure building this commit Details

nginx_conf
Luis Gerardo Romero Garcia 2024-10-03 15:01:54 +02:00
parent ad7cd037bf
commit f43f309f1e
1 changed files with 18 additions and 55 deletions

View File

@ -203,6 +203,7 @@ class DhcpController
/** /**
* @OA\Get( * @OA\Get(
* path="/ogdhcp/v1/subnets", * path="/ogdhcp/v1/subnets",
* summary="Obtiene todas las subredes DHCP",
* @OA\Response( * @OA\Response(
* response=200, * response=200,
* description="Devuelve todas las subredes", * description="Devuelve todas las subredes",
@ -214,6 +215,8 @@ class DhcpController
* type="object", * type="object",
* @OA\Property(property="id", type="integer", example=1), * @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="subnet", type="string", example="192.168.1.0/24"), * @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\Property(property="pools", type="array",
* @OA\Items( * @OA\Items(
* type="object", * type="object",
@ -223,8 +226,10 @@ class DhcpController
* @OA\Property(property="reservations", type="array", * @OA\Property(property="reservations", type="array",
* @OA\Items( * @OA\Items(
* type="object", * 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")
* ) * )
* ) * )
* ) * )
@ -242,6 +247,7 @@ class DhcpController
* ) * )
* @Route("/ogdhcp/v1/subnets", methods={"GET"}) * @Route("/ogdhcp/v1/subnets", methods={"GET"})
*/ */
public function getSubnets(): JsonResponse public function getSubnets(): JsonResponse
{ {
try { try {
@ -308,6 +314,14 @@ public function getSubnets(): JsonResponse
* type="object", * type="object",
* @OA\Property(property="error", type="string", example="Error: La subred con el nombre 'subnetName' ya existe.") * @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"}) * @Route("/ogdhcp/v1/subnets", methods={"POST"})
@ -351,58 +365,7 @@ public function getSubnets(): JsonResponse
$subnetIdExists = array_reduce($subnets, function ($exists, $subnetElement) use ($subnetId) { $subnetIdExists = array_reduce($subnets, function ($exists, $subnetElement) use ($subnetId) {
return $exists || ($subnetElement['id'] === $subnetId); return $exists || ($subnetElement['id'] === $subnetId);
}, false); /** }, 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
if ($subnetNameExists) { if ($subnetNameExists) {
$responseError = "Error: La subred con el nombre '$subnetName' ya existe."; $responseError = "Error: La subred con el nombre '$subnetName' ya existe.";
return new JsonResponse(['error' => $responseError], 400); return new JsonResponse(['error' => $responseError], 400);