Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 70 additions & 3 deletions src/controllers/sessionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
}

/**
Expand Down Expand Up @@ -466,4 +533,4 @@ module.exports = {
terminateAllSessions,
getSessions,
getPageScreenshot
}
}
5 changes: 3 additions & 2 deletions swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
60 changes: 56 additions & 4 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
}
}
Expand Down Expand Up @@ -15066,6 +15114,10 @@
"items": {
"type": "string"
}
},
"message": {
"type": "string",
"example": "Sessions retrieved successfully"
}
},
"xml": {
Expand Down