Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(webhook): publish the redrive selection bounds in the schema

Yudhi Armyndharisa3454b1f2728
diff --git a/openapi.json b/openapi.json
index 0182bdce1..a0a3e2573 100644
--- a/openapi.json
+++ b/openapi.json
@@ -19658,15 +19658,19 @@
"example": [
"0a941dac-a965-45e7-b318-74ae8be134f0"
],
- "type": "array",
+ "maxItems": 500,
"items": {
- "type": "string"
- }
+ "type": "string",
+ "maxLength": 128
+ },
+ "type": "array"
},
"limit": {
"type": "number",
"description": "Max rows replayed by this call (1-500, default 100).",
- "example": 100
+ "example": 100,
+ "minimum": 1,
+ "maximum": 500
}
}
},
diff --git a/src/modules/webhook/dto/webhook.dto.spec.ts b/src/modules/webhook/dto/webhook.dto.spec.ts
index 30751ca24..4bb195ea7 100644
--- a/src/modules/webhook/dto/webhook.dto.spec.ts
+++ b/src/modules/webhook/dto/webhook.dto.spec.ts
@@ -1,6 +1,7 @@
+import { DECORATORS } from '@nestjs/swagger';
import { plainToInstance } from 'class-transformer';
import { validate, ValidationError } from 'class-validator';
-import { CreateWebhookDto, UpdateWebhookDto } from './webhook.dto';
+import { CreateWebhookDto, RedriveWebhookDeliveriesDto, UpdateWebhookDto } from './webhook.dto';
/** Regression locks: webhook `events[]` must be constrained to known types + '*'. */
function errorsFor<T extends object>(cls: new () => T, obj: object): Promise<ValidationError[]> {
@@ -217,3 +218,20 @@ describe('webhook DTO url validation', () => {
}
});
});
+
+// The validators cap the redrive selection; the schema has to say so, or a client generated from it
+// sends a list the server answers with a 400.
+describe('RedriveWebhookDeliveriesDto published schema', () => {
+ const published = (key: string): Record<string, unknown> | undefined =>
+ Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, RedriveWebhookDeliveriesDto.prototype, key) as
+ Record<string, unknown> | undefined;
+
+ it('publishes the bounds of the id list and the limit that the validators enforce', async () => {
+ expect(published('ids')).toMatchObject({ maxItems: 500, items: { type: 'string', maxLength: 128 } });
+ expect(published('limit')).toMatchObject({ minimum: 1, maximum: 500 });
+
+ const ids = Array.from({ length: 501 }, (_, i) => `id-${i}`);
+ expect((await errorsFor(RedriveWebhookDeliveriesDto, { ids })).some(e => e.property === 'ids')).toBe(true);
+ expect(await errorsFor(RedriveWebhookDeliveriesDto, { ids: ids.slice(0, 500), limit: 500 })).toHaveLength(0);
+ });
+});
diff --git a/src/modules/webhook/dto/webhook.dto.ts b/src/modules/webhook/dto/webhook.dto.ts
index e1c159931..6f1eb05e6 100644
--- a/src/modules/webhook/dto/webhook.dto.ts
+++ b/src/modules/webhook/dto/webhook.dto.ts
@@ -450,6 +450,8 @@ export class RedriveWebhookDeliveriesDto {
type: [String],
description: 'Only these failure rows (ids from `GET /webhooks/delivery-failures`).',
example: ['0a941dac-a965-45e7-b318-74ae8be134f0'],
+ maxItems: 500,
+ items: { type: 'string', maxLength: 128 },
})
@IsOptional()
@IsArray()
@@ -458,7 +460,12 @@ export class RedriveWebhookDeliveriesDto {
@MaxLength(128, { each: true })
ids?: string[];
- @ApiPropertyOptional({ description: 'Max rows replayed by this call (1-500, default 100).', example: 100 })
+ @ApiPropertyOptional({
+ description: 'Max rows replayed by this call (1-500, default 100).',
+ example: 100,
+ minimum: 1,
+ maximum: 500,
+ })
@IsOptional()
@IsInt()
@Min(1)