Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(openapi): declare the 400 on the remaining label routes

Yudhi Armyndharisd78fc334bc29
diff --git a/src/modules/label/label.controller.spec.ts b/src/modules/label/label.controller.spec.ts
index f8afa54d5..ccc5da135 100644
--- a/src/modules/label/label.controller.spec.ts
+++ b/src/modules/label/label.controller.spec.ts
@@ -30,3 +30,24 @@ describe('LabelController - GET :labelId/chats for a chat-restricted key', () =>
);
});
});
+
+// Every label route reaches the engine through EngineRegistry.require(), which answers 400 for a
+// session with no live engine; clients generated from the OpenAPI contract need it declared.
+describe('LabelController OpenAPI error responses', () => {
+ it.each([
+ 'findAll',
+ 'findOne',
+ 'getChatsByLabel',
+ 'upsertLabel',
+ 'deleteLabel',
+ 'getChatLabels',
+ 'addLabelToChat',
+ 'removeLabelFromChat',
+ ])('%s declares 400', method => {
+ const responses = Reflect.getMetadata(
+ 'swagger/apiResponse',
+ Object.getOwnPropertyDescriptor(LabelController.prototype, method)!.value as object,
+ ) as Record<string, unknown>;
+ expect(Object.keys(responses)).toContain('400');
+ });
+});
diff --git a/src/modules/label/label.controller.ts b/src/modules/label/label.controller.ts
index 32211b4ac..3d069f711 100644
--- a/src/modules/label/label.controller.ts
+++ b/src/modules/label/label.controller.ts
@@ -48,6 +48,7 @@ export class LabelController {
@ApiParam({ name: 'sessionId', description: 'Session ID' })
@ApiParam({ name: 'labelId', description: 'Label ID' })
@ApiResponse({ status: 200, description: 'Label details', type: LabelDto })
+ @ApiResponse({ status: 400, description: 'Session not started' })
@ApiResponse({ status: 404, description: 'Label not found' })
@ApiResponse({ status: 409, description: ENGINE_NOT_READY_409 })
@ApiResponse({ status: 501, description: ENGINE_NOT_SUPPORTED_501 })
@@ -161,6 +162,7 @@ export class LabelController {
@ApiParam({ name: 'sessionId', description: 'Session ID' })
@ApiParam({ name: 'chatId', description: 'Chat ID' })
@ApiResponse({ status: 200, description: 'List of labels for the chat', type: [LabelDto] })
+ @ApiResponse({ status: 400, description: 'Session not started' })
@ApiResponse({ status: 409, description: ENGINE_NOT_READY_409 })
@ApiResponse({ status: 501, description: ENGINE_NOT_SUPPORTED_501 })
@ApiResponse({
@@ -190,6 +192,7 @@ export class LabelController {
},
})
@ApiResponse({ status: 200, description: 'Label added to chat', type: LabelAckResponseDto })
+ @ApiResponse({ status: 400, description: 'Session not started, or validation failed' })
@ApiResponse({
status: 404,
description:
@@ -224,6 +227,7 @@ export class LabelController {
@ApiParam({ name: 'chatId', description: 'Chat ID' })
@ApiParam({ name: 'labelId', description: 'Label ID to remove' })
@ApiResponse({ status: 200, description: 'Label removed from chat', type: LabelAckResponseDto })
+ @ApiResponse({ status: 400, description: 'Session not started' })
@ApiResponse({
status: 404,
description: 'The chat does not exist on this session, so nothing was written (whatsapp-web.js)',