feat(docs): implement comprehensive Chat and ChatId schemas for Swagger (#103)
* feat(docs): add ChatId schema definition to swagger.json * feat(docs): integrate ChatId and define base of Chat schema. * feat(docs): add response schema for chat listing
This commit is contained in:
parent
85dbb14b28
commit
c6c746afbc
3 changed files with 150 additions and 6 deletions
|
|
@ -348,8 +348,16 @@ const getContacts = async (req, res) => {
|
|||
* @throws {Error} If the operation fails, an error is thrown.
|
||||
*/
|
||||
const getChats = async (req, res) => {
|
||||
/*
|
||||
#swagger.summary = 'Get all current chats'
|
||||
/* #swagger.summary = 'Get all current chats'
|
||||
#swagger.description = 'Retrieve all chats for the given session ID.'
|
||||
#swagger.responses[200] = {
|
||||
description: 'Retrieved all chats.',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: { "$ref": "#/definitions/GetChatsResponse" }
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
try {
|
||||
const client = sessions.get(req.params.sessionId)
|
||||
|
|
@ -377,6 +385,7 @@ const getChats = async (req, res) => {
|
|||
const getChatsWithSearch = async (req, res) => {
|
||||
/*
|
||||
#swagger.summary = 'Get all current chats with optional search parameters'
|
||||
#swagger.description = 'Retrieve all chats for the given session ID with optional search parameters.'
|
||||
#swagger.requestBody = {
|
||||
required: true,
|
||||
schema: {
|
||||
|
|
@ -399,6 +408,14 @@ const getChatsWithSearch = async (req, res) => {
|
|||
}
|
||||
},
|
||||
}
|
||||
#swagger.responses[200] = {
|
||||
description: 'Retrieved all chats with search parameters.',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {"$ref": "#/definitions/GetChatsResponse"}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
try {
|
||||
const { searchOptions = {} } = req.body
|
||||
|
|
|
|||
22
swagger.js
22
swagger.js
|
|
@ -80,6 +80,28 @@ const doc = {
|
|||
GetSessionsResponse: {
|
||||
success: true,
|
||||
result: ['session1', 'session2']
|
||||
},
|
||||
ChatId: {
|
||||
server: 'c.us | g.us',
|
||||
user: '1234567890',
|
||||
_serialized: '1234567890@c.us',
|
||||
},
|
||||
Chat: {
|
||||
id: { $ref: '#/definitions/ChatId' },
|
||||
name: 'John Doe',
|
||||
isGroup: false,
|
||||
unreadCount: 0,
|
||||
timestamp: 1770140061,
|
||||
archived: false,
|
||||
pinned: false,
|
||||
isMuted: false,
|
||||
muteExpiration: 0,
|
||||
// Add other chat properties as needed after create definitions
|
||||
},
|
||||
GetChatsResponse: {
|
||||
success: true,
|
||||
chats: [ { $ref: '#/definitions/Chat' } ],
|
||||
error: 'error message if any',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
113
swagger.json
113
swagger.json
|
|
@ -1541,7 +1541,7 @@
|
|||
"Client"
|
||||
],
|
||||
"summary": "Get all current chats",
|
||||
"description": "",
|
||||
"description": "Retrieve all chats for the given session ID.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sessionId",
|
||||
|
|
@ -1556,7 +1556,14 @@
|
|||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
"description": "Retrieved all chats.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/GetChatsResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "Forbidden.",
|
||||
|
|
@ -1610,7 +1617,7 @@
|
|||
"Client"
|
||||
],
|
||||
"summary": "Get all current chats with optional search parameters",
|
||||
"description": "",
|
||||
"description": "Retrieve all chats for the given session ID with optional search parameters.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sessionId",
|
||||
|
|
@ -1625,7 +1632,14 @@
|
|||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
"description": "Retrieved all chats with search parameters.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/GetChatsResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "Forbidden.",
|
||||
|
|
@ -15071,6 +15085,97 @@
|
|||
"xml": {
|
||||
"name": "GetSessionsResponse"
|
||||
}
|
||||
},
|
||||
"ChatId": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"server": {
|
||||
"type": "string",
|
||||
"example": "c.us | g.us"
|
||||
},
|
||||
"user": {
|
||||
"type": "string",
|
||||
"example": "1234567890"
|
||||
},
|
||||
"_serialized": {
|
||||
"type": "string",
|
||||
"example": "1234567890@c.us"
|
||||
}
|
||||
},
|
||||
"xml": {
|
||||
"name": "ChatId"
|
||||
}
|
||||
},
|
||||
"Chat": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"xml": {
|
||||
"name": "chatid"
|
||||
},
|
||||
"$ref": "#/components/schemas/ChatId"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"example": "John Doe"
|
||||
},
|
||||
"isGroup": {
|
||||
"type": "boolean",
|
||||
"example": false
|
||||
},
|
||||
"unreadCount": {
|
||||
"type": "number",
|
||||
"example": 0
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "number",
|
||||
"example": 1770140061
|
||||
},
|
||||
"archived": {
|
||||
"type": "boolean",
|
||||
"example": false
|
||||
},
|
||||
"pinned": {
|
||||
"type": "boolean",
|
||||
"example": false
|
||||
},
|
||||
"isMuted": {
|
||||
"type": "boolean",
|
||||
"example": false
|
||||
},
|
||||
"muteExpiration": {
|
||||
"type": "number",
|
||||
"example": 0
|
||||
}
|
||||
},
|
||||
"xml": {
|
||||
"name": "Chat"
|
||||
}
|
||||
},
|
||||
"GetChatsResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean",
|
||||
"example": true
|
||||
},
|
||||
"chats": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"xml": {
|
||||
"name": "chat"
|
||||
},
|
||||
"$ref": "#/components/schemas/Chat"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"type": "string",
|
||||
"example": "error message if any"
|
||||
}
|
||||
},
|
||||
"xml": {
|
||||
"name": "GetChatsResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"securitySchemes": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue