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(
* 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);