From 65e7378c6c9c760c7324359ad700c7b0897e5d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kau=C3=A3=20Q=2E?= <89699012+kaua-alves-queiros@users.noreply.github.com> Date: Wed, 27 Aug 2025 21:00:55 -0400 Subject: [PATCH 1/3] feat: The GetSessionsResponse now includes example string values for the result property --- swagger.js | 2 +- swagger.json | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/swagger.js b/swagger.js index c68bc63..ae36902 100644 --- a/swagger.js +++ b/swagger.js @@ -79,7 +79,7 @@ const doc = { }, GetSessionsResponse: { success: true, - result: [] + result: ['session1', 'session2'] } } } diff --git a/swagger.json b/swagger.json index d8053fc..dc7174c 100644 --- a/swagger.json +++ b/swagger.json @@ -14943,8 +14943,13 @@ }, "result": { "type": "array", - "example": [], - "items": {} + "example": [ + "session1", + "session2" + ], + "items": { + "type": "string" + } } }, "xml": { From ca4eea9a378ff764fdde91f3d4cb055d37be44d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kau=C3=A3=20Q=2E?= <89699012+kaua-alves-queiros@users.noreply.github.com> Date: Wed, 10 Sep 2025 20:44:02 -0400 Subject: [PATCH 2/3] feat(docs): unify response schema for the GetSessions endpoint - Adopted a single predictable schema (GetSessionsResponse) for all endpoint responses - Overrides the middleware's default documentation (403), ensuring consistent return types - Added 404 response for when no sessions are found - Added a success message in the response object - Updates swagger documentation for 200, 404, 403, and 500 using the same schema - Improves SDK consistency (nswag now generates only one response class) --- src/controllers/sessionController.js | 73 ++++++++++++++++++++++++++-- swagger.js | 5 +- swagger.json | 60 +++++++++++++++++++++-- 3 files changed, 129 insertions(+), 9 deletions(-) diff --git a/src/controllers/sessionController.js b/src/controllers/sessionController.js index ff0c40a..e53179a 100644 --- a/src/controllers/sessionController.js +++ b/src/controllers/sessionController.js @@ -397,12 +397,79 @@ const getSessions = async (req, res) => { description: "Retrieved all sessions.", content: { "application/json": { - schema: { "$ref": "#/definitions/GetSessionsResponse" } + schema: { "$ref": "#/definitions/GetSessionsResponse" }, + examples: { + "Success": { + success: true, + result: ["sessionId1", "sessionId2", "sessionId3"], + message: "Retrieved all sessions.", + } + } + } + } + } + + #swagger.responses[404] = { + description: "Not found.", + content: { + "application/json": { + schema: { "$ref": "#/definitions/GetSessionsResponse" }, + examples: { + "Bad request": { + value: { + success: false, + result: [], + message: "Sessions not found" + } + } + } + } + } + } + + #swagger.responses[403] = { + description: "Forbidden", + content: { + "application/json": { + schema: { "$ref": "#/definitions/GetSessionsResponse" }, + examples: { + "Forbidden": { + value: { + success: false, + result: [], + message: "Invalid API key" + } + } + } + } + } + } + + #swagger.responses[500] = { + description: "Internal Server Error.", + content: { + "application/json": { + schema: { "$ref": "#/definitions/GetSessionsResponse" }, + examples: { + "Internal Server Error": { + value: { + success: false, + result: [], + message: "Internal Server Error." + } + } + } } } } */ - return res.json({ success: true, result: Array.from(sessions.keys()) }) + + if(sessions.keys().length === 0) { + res.status(404) + return res.json({ success: false, result: [], message: 'Sessions not found' }) + } + + return res.json({ success: true, result: Array.from(sessions.keys()), message: 'Sessions retrieved successfully'}) } /** @@ -466,4 +533,4 @@ module.exports = { terminateAllSessions, getSessions, getPageScreenshot -} +} \ No newline at end of file diff --git a/swagger.js b/swagger.js index ae36902..cbab014 100644 --- a/swagger.js +++ b/swagger.js @@ -79,9 +79,10 @@ const doc = { }, GetSessionsResponse: { success: true, - result: ['session1', 'session2'] + result: ['session1', 'session2'], + message: 'Sessions retrieved successfully' } } } -swaggerAutogen(outputFile, endpointsFiles, doc) +swaggerAutogen(outputFile, endpointsFiles, doc) \ No newline at end of file diff --git a/swagger.json b/swagger.json index 4b7a9a6..81707da 100644 --- a/swagger.json +++ b/swagger.json @@ -120,26 +120,74 @@ "application/json": { "schema": { "$ref": "#/components/schemas/GetSessionsResponse" + }, + "examples": { + "Success": { + "success": true, + "result": [ + "sessionId1", + "sessionId2", + "sessionId3" + ], + "message": "Retrieved all sessions." + } } } } }, "403": { - "description": "Forbidden.", + "description": "Forbidden", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ForbiddenResponse" + "$ref": "#/components/schemas/GetSessionsResponse" + }, + "examples": { + "Forbidden": { + "value": { + "success": false, + "result": [], + "message": "Invalid API key" + } + } + } + } + } + }, + "404": { + "description": "Not found.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetSessionsResponse" + }, + "examples": { + "Bad request": { + "value": { + "success": false, + "result": [], + "message": "Sessions not found" + } + } } } } }, "500": { - "description": "Server failure.", + "description": "Internal Server Error.", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ErrorResponse" + "$ref": "#/components/schemas/GetSessionsResponse" + }, + "examples": { + "Internal Server Error": { + "value": { + "success": false, + "result": [], + "message": "Internal Server Error." + } + } } } } @@ -15066,6 +15114,10 @@ "items": { "type": "string" } + }, + "message": { + "type": "string", + "example": "Sessions retrieved successfully" } }, "xml": { From 211b340db600633a0f4675b68eb6ec71e887b2a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kau=C3=A3=20Q=2E?= <89699012+kaua-alves-queiros@users.noreply.github.com> Date: Wed, 10 Sep 2025 21:49:13 -0400 Subject: [PATCH 3/3] fix return not found check --- src/controllers/sessionController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/sessionController.js b/src/controllers/sessionController.js index e53179a..3673a79 100644 --- a/src/controllers/sessionController.js +++ b/src/controllers/sessionController.js @@ -464,7 +464,7 @@ const getSessions = async (req, res) => { } */ - if(sessions.keys().length === 0) { + if(sessions.size === 0) { res.status(404) return res.json({ success: false, result: [], message: 'Sessions not found' }) }