diff --git a/src/controllers/sessionController.js b/src/controllers/sessionController.js index ff0c40a..3673a79 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.size === 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": {