swagger: document health controller
This commit is contained in:
parent
02f442ab05
commit
b0a04f98a1
2 changed files with 68 additions and 11 deletions
|
|
@ -4,7 +4,7 @@ const { sessionFolderPath } = require('../config')
|
||||||
const { sendErrorResponse } = require('../utils')
|
const { sendErrorResponse } = require('../utils')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responds to ping request with 'pong'
|
* Responds to request with 'pong'
|
||||||
*
|
*
|
||||||
* @function ping
|
* @function ping
|
||||||
* @async
|
* @async
|
||||||
|
|
@ -16,16 +16,25 @@ const { sendErrorResponse } = require('../utils')
|
||||||
const ping = async (req, res) => {
|
const ping = async (req, res) => {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['Various']
|
#swagger.tags = ['Various']
|
||||||
*/
|
#swagger.summary = 'Health check'
|
||||||
try {
|
#swagger.description = 'Responds to request with "pong" message'
|
||||||
res.json({ success: true, message: 'pong' })
|
#swagger.responses[200] = {
|
||||||
} catch (error) {
|
description: "Response message",
|
||||||
sendErrorResponse(res, 500, error.message)
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
example: {
|
||||||
|
success: true,
|
||||||
|
message: "pong"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
res.json({ success: true, message: 'pong' })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example local callback function that generates a QR code and writes a log file
|
* Example local callback that generates a QR code and writes a log file
|
||||||
*
|
*
|
||||||
* @function localCallbackExample
|
* @function localCallbackExample
|
||||||
* @async
|
* @async
|
||||||
|
|
@ -39,6 +48,18 @@ const ping = async (req, res) => {
|
||||||
const localCallbackExample = async (req, res) => {
|
const localCallbackExample = async (req, res) => {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['Various']
|
#swagger.tags = ['Various']
|
||||||
|
#swagger.summary = 'Local callback'
|
||||||
|
#swagger.description = 'Used to generate a QR code and writes a log file. ONLY FOR DEVELOPMENT/TEST PURPOSES.'
|
||||||
|
#swagger.responses[200] = {
|
||||||
|
description: "Response message",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
example: {
|
||||||
|
success: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const { dataType, data } = req.body
|
const { dataType, data } = req.body
|
||||||
|
|
@ -47,6 +68,15 @@ const localCallbackExample = async (req, res) => {
|
||||||
await fsp.writeFile(`${sessionFolderPath}/message_log.txt`, `${JSON.stringify(req.body)}\r\n`, { flag: 'a+' })
|
await fsp.writeFile(`${sessionFolderPath}/message_log.txt`, `${JSON.stringify(req.body)}\r\n`, { flag: 'a+' })
|
||||||
res.json({ success: true })
|
res.json({ success: true })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
/* #swagger.responses[500] = {
|
||||||
|
description: "Server Failure.",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: { "$ref": "#/definitions/ErrorResponse" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
console.log(error)
|
console.log(error)
|
||||||
sendErrorResponse(res, 500, error.message)
|
sendErrorResponse(res, 500, error.message)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
swagger.json
35
swagger.json
|
|
@ -35,10 +35,19 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"Various"
|
"Various"
|
||||||
],
|
],
|
||||||
"description": "",
|
"summary": "Health check",
|
||||||
|
"description": "Responds to request with \"pong\" message",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK"
|
"description": "Response message",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"example": {
|
||||||
|
"success": true,
|
||||||
|
"message": "pong"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +57,8 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"Various"
|
"Various"
|
||||||
],
|
],
|
||||||
"description": "",
|
"summary": "Local callback",
|
||||||
|
"description": "Used to generate a QR code and writes a log file. ONLY FOR DEVELOPMENT/TEST PURPOSES.",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "x-api-key",
|
"name": "x-api-key",
|
||||||
|
|
@ -60,7 +70,14 @@
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK"
|
"description": "Response message",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"example": {
|
||||||
|
"success": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"403": {
|
"403": {
|
||||||
"description": "Forbidden.",
|
"description": "Forbidden.",
|
||||||
|
|
@ -71,6 +88,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Server Failure.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue