diff --git a/src/Debug/Controller/DebugController.php b/src/Debug/Controller/DebugController.php index dc8a1fc..f18f00d 100644 --- a/src/Debug/Controller/DebugController.php +++ b/src/Debug/Controller/DebugController.php @@ -21,15 +21,15 @@ use Yiisoft\Yii\Debug\Api\ServerSentEventsStream; use Yiisoft\Yii\Debug\Storage\StorageInterface; use Yiisoft\Yii\View\ViewRenderer; +use OpenApi\Attributes as OA; /** * Debug controller provides endpoints that expose information about requests processed that debugger collected. - * - * @OA\Tag( - * name="yii-debug-api", - * description="Yii Debug API" - * ) */ +#[OA\Tag( + name: "yii-debug-api", + description: "Yii Debug API" +)] final class DebugController { public function __construct( @@ -41,24 +41,22 @@ public function __construct( /** * List of requests processed. * - * @OA\Get( - * tags={"yii-debug-api"}, - * path="/debug/api", - * description="List of requests processed", - * - * @OA\Response( - * response="200", - * description="Success", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugSuccessResponse") - * } - * ) - * ) - * ) */ + #[OA\Get( + path: "/debug/api", + description: "List of requests processed", + tags: ["yii-debug-api"], + responses: [ + new OA\Response( + response: "200", + description: "Success", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugSuccessResponse") + ] + ) + ) + ])] public function index(): ResponseInterface { return $this->responseFactory->createResponse($this->collectorRepository->getSummary()); @@ -66,47 +64,41 @@ public function index(): ResponseInterface /** * Summary about a processed request identified by ID specified. - * - * @OA\Get( - * tags={"yii-debug-api"}, - * path="/debug/api/summary/{id}", - * description="Summary about a processed request identified by ID specified", - * - * @OA\Parameter( - * name="id", - * required=true, - * - * @OA\Schema(type="string"), - * in="path", - * parameter="id", - * description="Request ID for getting the summary" - * ), - * - * @OA\Response( - * response="200", - * description="Success", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugSuccessResponse") - * } - * ) - * ), - * - * @OA\Response( - * response="404", - * description="Not found", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugNotFoundResponse") - * } - * ) - * ) - * ) */ + #[OA\Get( + path: "/debug/api/summary/{id}", + description: "Summary about a processed request identified by ID specified", + tags: ["yii-debug-api"], + responses: [ + new OA\Response( + response: "200", + description: "Success", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugSuccessResponse") + ] + ) + ), + new OA\Response( + response: "404", + description: "Not found", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugNotFoundResponse") + ] + ) + ), + ], + parameters: [ + new OA\Parameter( + name: "id", + required: true, + in: "path", + parameter: "id", + description: "Request ID for getting the summary", + schema: new OA\Schema(type: "string") + ) + ])] public function summary(CurrentRoute $currentRoute): ResponseInterface { $data = $this->collectorRepository->getSummary($currentRoute->getArgument('id')); @@ -115,57 +107,49 @@ public function summary(CurrentRoute $currentRoute): ResponseInterface /** * Detail information about a processed request identified by ID. - * - * @OA\Get( - * tags={"yii-debug-api"}, - * path="/debug/api/view/{id}/?collector={collector}", - * description="Detail information about a processed request identified by ID", - * - * @OA\Parameter( - * name="id", - * required=true, - * - * @OA\Schema(type="string"), - * in="path", - * parameter="id", - * description="Request ID for getting the detail information" - * ), - * - * @OA\Parameter( - * name="collector", - * allowEmptyValue=true, - * - * @OA\Schema(type="string"), - * in="query", - * parameter="collector", - * description="Collector for getting the detail information" - * ), - * - * @OA\Response( - * response="200", - * description="Success", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugSuccessResponse") - * } - * ) - * ), - * - * @OA\Response( - * response="404", - * description="Not found", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugNotFoundResponse") - * } - * ) - * ) - * ) */ + #[OA\Get( + path: "/debug/api/view/{id}?collector={collector}", + description: "Detail information about a processed request identified by ID", + tags: ["yii-debug-api"], + responses: [ + new OA\Response( + response: "200", + description: "Success", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugSuccessResponse") + ] + ) + ), + new OA\Response( + response: "404", + description: "Not found", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugNotFoundResponse") + ] + ) + ), + ], + parameters: [ + new OA\Parameter( + name: "id", + required: true, + in: "path", + parameter: "id", + description: "Request ID for getting the summary", + schema: new OA\Schema(type: "string") + ), + new OA\Parameter( + name: "collector", + in: "query", + parameter: "collector", + description: "Collector for getting the detail information", + schema: new OA\Schema(type: "string"), + allowEmptyValue: true + ), + ])] public function view( CurrentRoute $currentRoute, ServerRequestInterface $serverRequest, @@ -194,60 +178,52 @@ public function view( /** * Dump information about a processed request identified by ID. * - * @OA\Get( - * tags={"yii-debug-api"}, - * path="/debug/api/dump/{id}/{collector}", - * description="Dump information about a processed request identified by ID", - * - * @OA\Parameter( - * name="id", - * required=true, - * - * @OA\Schema(type="string"), - * in="path", - * parameter="id", - * description="Request ID for getting the dump information" - * ), - * - * @OA\Parameter( - * name="collector", - * allowEmptyValue=true, - * required=false, - * - * @OA\Schema(type="string"), - * in="path", - * parameter="collector", - * description="Collector for getting the dump information" - * ), - * - * @OA\Response( - * response="200", - * description="Success", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugSuccessResponse") - * } - * ) - * ), - * - * @OA\Response( - * response="404", - * description="Not found", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugNotFoundResponse") - * } - * ) - * ) - * ) - * * @throws NotFoundException * @return ResponseInterface response. */ + #[OA\Get( + path: "/debug/api/dump/{id}?collector={collector}", + description: "Dump information about a processed request identified by ID", + tags: ["yii-debug-api"], + responses: [ + new OA\Response( + response: "200", + description: "Success", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugSuccessResponse") + ] + ) + ), + new OA\Response( + response: "404", + description: "Not found", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugNotFoundResponse") + ] + ) + ), + ], + parameters: [ + new OA\Parameter( + name: "id", + required: true, + in: "path", + parameter: "id", + description: "Request ID for getting the dump information", + schema: new OA\Schema(type: "string") + ), + new OA\Parameter( + name: "collector", + required: false, + in: "path", + parameter: "collector", + description: "Collector for getting the dump information", + schema: new OA\Schema(type: "string"), + allowEmptyValue: true + ), + ])] public function dump(CurrentRoute $currentRoute): ResponseInterface { $data = $this->collectorRepository->getDumpObject( @@ -268,58 +244,50 @@ public function dump(CurrentRoute $currentRoute): ResponseInterface /** * Object information about a processed request identified by ID. * - * @OA\Get( - * tags={"yii-debug-api"}, - * path="/debug/api/object/{id}/{objectId}", - * description="Object information about a processed request identified by ID", - * - * @OA\Parameter( - * name="id", - * required=true, - * - * @OA\Schema(type="string"), - * in="path", - * parameter="id", - * description="Request ID for getting the object information" - * ), - * - * @OA\Parameter( - * name="objectId", - * required=true, - * - * @OA\Schema(type="string"), - * in="path", - * parameter="objectId", - * description="ID for getting the object information" - * ), - * - * @OA\Response( - * response="200", - * description="Success", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugSuccessResponse") - * } - * ) - * ), - * - * @OA\Response( - * response="404", - * description="Not found", - * - * @OA\JsonContent( - * allOf={ - * - * @OA\Schema(ref="#/components/schemas/DebugNotFoundResponse") - * } - * ) - * ) - * ) - * * @return ResponseInterface response. */ + #[OA\Get( + path: "/debug/api/object/{id}/{objectId}", + description: "Object information about a processed request identified by ID", + tags: ["yii-debug-api"], + responses: [ + new OA\Response( + response: "200", + description: "Success", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugSuccessResponse") + ] + ) + ), + new OA\Response( + response: "404", + description: "Not found", + content: new OA\JsonContent( + allOf: [ + new OA\Schema(ref: "#/components/schemas/DebugNotFoundResponse") + ] + ) + ), + ], + parameters: [ + new OA\Parameter( + name: "id", + required: true, + in: "path", + parameter: "id", + description: "Request ID for getting the object information", + schema: new OA\Schema(type: "string") + ), + new OA\Parameter( + name: "objectId", + required: true, + in: "path", + parameter: "objectId", + description: "ID for getting the object information", + schema: new OA\Schema(type: "string") + ), + ])] public function object(CurrentRoute $currentRoute): ResponseInterface { $data = $this->collectorRepository->getObject( @@ -327,6 +295,10 @@ public function object(CurrentRoute $currentRoute): ResponseInterface $currentRoute->getArgument('objectId') ); + if(is_null($data)){ + throw new NotFoundException('Requested objectId doesn\'t exists.'); + } + return $this->responseFactory->createResponse([ 'class' => $data[0], 'value' => $data[1], diff --git a/src/Debug/Middleware/ResponseDataWrapper.php b/src/Debug/Middleware/ResponseDataWrapper.php index c7d07d8..b1a8eea 100644 --- a/src/Debug/Middleware/ResponseDataWrapper.php +++ b/src/Debug/Middleware/ResponseDataWrapper.php @@ -4,7 +4,6 @@ namespace Yiisoft\Yii\Debug\Api\Debug\Middleware; -use OpenApi\Annotations as OA; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; @@ -14,84 +13,33 @@ use Yiisoft\Http\Status; use Yiisoft\Router\CurrentRoute; use Yiisoft\Yii\Debug\Api\Debug\Exception\NotFoundException; +use OpenApi\Attributes as OA; -/** - * @OA\Schema(schema="DebugResponse", description="Yii Debug Api response") - * @OA\Schema( - * schema="DebugSuccessResponse", - * allOf={ - * @OA\Schema(ref="#/components/schemas/DebugResponse"), - * @OA\Schema( - * - * @OA\Property( - * description="ID", - * title="ID", - * property="id", - * format="string" - * ), - * @OA\Property( - * description="Data", - * title="Data", - * property="data", - * type="object", - * nullable=true - * ), - * @OA\Property( - * description="Error", - * title="Error", - * property="error", - * format="string", - * nullable=true, - * example=null - * ), - * @OA\Property( - * description="Success", - * title="Success", - * property="success", - * type="boolean", - * example=true - * ) - * ) - * } - * ) - * - * @OA\Schema( - * schema="DebugNotFoundResponse", - * allOf={ - * @OA\Schema(ref="#/components/schemas/DebugResponse"), - * @OA\Schema( - * - * @OA\Property( - * description="ID", - * title="ID", - * property="id", - * format="string" - * ), - * @OA\Property( - * description="Data", - * title="Data", - * property="data", - * type="object", - * nullable=true, - * example=null - * ), - * @OA\Property( - * description="Error", - * title="Error", - * property="error", - * format="string", - * ), - * @OA\Property( - * description="Success", - * title="Success", - * property="success", - * type="boolean", - * example=false - * ) - * ) - * } - * ) - */ +#[OA\Schema(schema: "DebugResponse", description: "Yii Debug Api response")] +#[OA\Schema( + schema: "DebugSuccessResponse", + allOf: [ + new OA\Schema(ref:"#/components/schemas/DebugResponse"), + new OA\Schema(properties: [ + new OA\Property(property: "id",title: "ID",description: "ID", format: "string"), + new OA\Property(property: "data",title: "Data",description: "Data", format: "object", nullable: true), + new OA\Property(property: "error",title: "Error",description: "Error", format: "string", nullable: true, example: null), + new OA\Property(property: "success",title: "Success",description: "Success", format: "boolean",example: true), + ]) + ] +)] +#[OA\Schema( + schema: "DebugNotFoundResponse", + allOf: [ + new OA\Schema(ref:"#/components/schemas/DebugResponse"), + new OA\Schema(properties: [ + new OA\Property(property: "id",title: "ID",description: "ID", format: "string"), + new OA\Property(property: "data",title: "Data",description: "Data", format: "object", nullable: true, example: null), + new OA\Property(property: "error",title: "Error",description: "Error", format: "string"), + new OA\Property(property: "success",title: "Success",description: "Success", format: "boolean",example: false), + ]) + ] +)] final class ResponseDataWrapper implements MiddlewareInterface { public function __construct(private DataResponseFactoryInterface $responseFactory, private CurrentRoute $currentRoute)