Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat: opt-in validation-error detail + OpenAPI tag hygiene (#646)

Yudhi Armyndhariscb92aa43d82f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 27f54fe64..9d2b4efba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,8 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+
+- **Opt-in `VALIDATION_ERROR_DETAIL`** exposes field-level validation error messages on `400` responses (hidden by default in production, where a bad request otherwise returns a generic message so the DTO shape isn't reflected back). Set it to `true` to debug an SDK/integration against a production instance without flipping `NODE_ENV`, or `false` to force it off everywhere.
+
### Changed
+- **OpenAPI/Swagger tag hygiene.** Every controller tag is now declared in the API document (ten were used but undeclared), the three Integration Fabric controllers gained `@ApiTags`, and the tag casing is uniform — so `/api/docs` groups every endpoint under a described tag instead of leaving some ungrouped.
- **Graceful shutdown now drains on `SIGTERM`/`SIGINT`** (rolling deploys, `docker stop`, Ctrl+C), not just on the admin restart endpoint. On a termination signal the app flips readiness to `503` immediately so a load balancer/orchestrator stops routing, keeps serving in-flight requests for a bounded grace window, then tears down and exits deterministically. ⚠️ **Behavior change:** a `docker stop` / redeploy now takes up to the grace window (`SHUTDOWN_DELAY_MS`, default **3s** in production, **0** in dev) plus teardown instead of tearing down instantly, and the process now exits `0` on a clean signal. In Docker set `stop_grace_period` ≥ `SHUTDOWN_DELAY_MS` + your worst-case teardown (the bundled compose now sets `45s`); for Kubernetes set `terminationGracePeriodSeconds` accordingly. A second signal during the drain forces an immediate exit. The whatsapp-web.js engine no longer lets Puppeteer install its own signal handlers (which previously killed Chromium at signal time / `exit(130)` before the drain could run).
- **The bundled Docker Compose stack pins its `docker-socket-proxy` and `minio` images to explicit tags** (they were on `:latest`) for reproducible, non-drifting deploys, and a Dependabot `docker` ecosystem was added so base and stack images keep receiving update PRs. A Node `>=22` `engines` floor + `.nvmrc` were declared, and the transitive install-time Scarf telemetry (via `swagger-ui-dist`) is disabled.
diff --git a/src/config/bootstrap-security.spec.ts b/src/config/bootstrap-security.spec.ts
index bc678c353..d70506c31 100644
--- a/src/config/bootstrap-security.spec.ts
+++ b/src/config/bootstrap-security.spec.ts
@@ -1,6 +1,7 @@
import {
resolveCorsPolicy,
isSwaggerEnabled,
+ isValidationErrorDetailEnabled,
isUpgradeInsecureRequestsEnabled,
resolveBodyLimit,
assertNoDefaultSecretsInProduction,
@@ -82,6 +83,18 @@ describe('isSwaggerEnabled', () => {
});
});
+describe('isValidationErrorDetailEnabled', () => {
+ it('shows detail outside production but hides it in production by default (unchanged default)', () => {
+ expect(isValidationErrorDetailEnabled(undefined, 'development')).toBe(true);
+ expect(isValidationErrorDetailEnabled(undefined, 'production')).toBe(false);
+ expect(isValidationErrorDetailEnabled('', 'production')).toBe(false);
+ });
+ it('honors an explicit opt-in/out regardless of env', () => {
+ expect(isValidationErrorDetailEnabled('true', 'production')).toBe(true); // debug an SDK against prod
+ expect(isValidationErrorDetailEnabled('false', 'development')).toBe(false);
+ });
+});
+
describe('resolveBodyLimit', () => {
it('defaults to a media-aware 25mb', () => {
expect(resolveBodyLimit(undefined)).toBe('25mb');
diff --git a/src/config/bootstrap-security.ts b/src/config/bootstrap-security.ts
index 08f015ed4..87daaa130 100644
--- a/src/config/bootstrap-security.ts
+++ b/src/config/bootstrap-security.ts
@@ -44,6 +44,19 @@ export function isSwaggerEnabled(enableSwaggerEnv?: string, nodeEnv?: string): b
return nodeEnv !== 'production';
}
+/**
+ * Whether the global ValidationPipe should EXPOSE field-level validation error messages. Hidden by
+ * default in production (a 400 there returns a generic message so the DTO shape isn't reflected back)
+ * and shown outside production. `VALIDATION_ERROR_DETAIL=true` forces detail on — useful for debugging
+ * an SDK/integration against a production instance without flipping NODE_ENV — and `=false` forces it
+ * off everywhere. Mirrors isSwaggerEnabled's exact-string, production-default-off contract.
+ */
+export function isValidationErrorDetailEnabled(validationDetailEnv?: string, nodeEnv?: string): boolean {
+ if (validationDetailEnv === 'true') return true;
+ if (validationDetailEnv === 'false') return false;
+ return nodeEnv !== 'production';
+}
+
/**
* Whether to emit the CSP `upgrade-insecure-requests` directive (browsers auto-upgrade HTTP→HTTPS).
* An explicit CSP_UPGRADE_INSECURE_REQUESTS wins ('true'/'false'). When unset it keeps the legacy
diff --git a/src/config/swagger.config.ts b/src/config/swagger.config.ts
index c5c270f89..ce683d33c 100644
--- a/src/config/swagger.config.ts
+++ b/src/config/swagger.config.ts
@@ -29,6 +29,17 @@ export function createSwaggerConfig(): Omit<OpenAPIObject, 'paths'> {
.addTag('groups', 'Group management')
.addTag('labels', 'Label management (WhatsApp Business)')
.addTag('channels', 'Channel/Newsletter management')
+ .addTag('catalog', 'Product catalog (WhatsApp Business)')
+ .addTag('status', 'Status/Stories')
+ .addTag('statistics', 'Usage statistics')
+ .addTag('templates', 'Message templates')
+ .addTag('plugins', 'Plugin management')
+ .addTag('settings', 'Application settings')
+ .addTag('infrastructure', 'Infrastructure & datastore management')
+ .addTag('integration', 'Integration Fabric (provider webhooks & instances)')
+ .addTag('auth', 'API key management')
+ .addTag('audit', 'Audit log')
+ .addTag('metrics', 'Prometheus metrics')
.addTag('health', 'Health check endpoints')
.build()
);
diff --git a/src/main.ts b/src/main.ts
index acf0a1990..7c7947cae 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -15,6 +15,7 @@ import { registerUncaughtExceptionMonitor } from './config/process-error-monitor
import {
resolveCorsPolicy,
isSwaggerEnabled,
+ isValidationErrorDetailEnabled,
isUpgradeInsecureRequestsEnabled,
resolveBodyLimit,
assertNoDefaultSecretsInProduction,
@@ -209,7 +210,9 @@ async function bootstrap() {
transformOptions: {
enableImplicitConversion: true,
},
- disableErrorMessages: process.env.NODE_ENV === 'production', // Hide details in prod
+ // Hide field-level validation messages by default in production (so a 400 doesn't reflect the DTO
+ // shape back); opt in with VALIDATION_ERROR_DETAIL=true to debug an SDK/integration against prod.
+ disableErrorMessages: !isValidationErrorDetailEnabled(process.env.VALIDATION_ERROR_DETAIL, process.env.NODE_ENV),
}),
);
diff --git a/src/modules/catalog/catalog.controller.ts b/src/modules/catalog/catalog.controller.ts
index 521deb371..9d24548d3 100644
--- a/src/modules/catalog/catalog.controller.ts
+++ b/src/modules/catalog/catalog.controller.ts
@@ -5,7 +5,7 @@ import { SendProductDto, SendCatalogDto, ProductQueryDto } from './dto/send-prod
import { RequireRole } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
-@ApiTags('Catalog')
+@ApiTags('catalog')
@Controller('sessions/:sessionId')
export class CatalogController {
constructor(private readonly catalogService: CatalogService) {}
diff --git a/src/modules/integration/ingress.controller.ts b/src/modules/integration/ingress.controller.ts
index 797b8b7ca..37add8cc6 100644
--- a/src/modules/integration/ingress.controller.ts
+++ b/src/modules/integration/ingress.controller.ts
@@ -1,4 +1,5 @@
import { All, Controller, Param, Query, Req, Res, UseGuards } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
import type { Request, Response } from 'express';
import { Public } from '../auth/decorators/auth.decorators';
import { IngressService } from './ingress.service';
@@ -9,6 +10,7 @@ import { InstanceThrottlerGuard } from './instance-throttler.guard';
// The provider body is read as RAW bytes from req.rawBody (stashed by the json() verify callback in
// main.ts) — it is intentionally NOT DTO-bound, so the global ValidationPipe never 400s on the
// provider's unknown keys, and the exact signed bytes reach the HMAC verifier.
+@ApiTags('integration')
@Public()
@Controller('ingress')
export class IngressController {
diff --git a/src/modules/integration/integration-instance.controller.ts b/src/modules/integration/integration-instance.controller.ts
index 1b3b6ef84..ccb10e9f0 100644
--- a/src/modules/integration/integration-instance.controller.ts
+++ b/src/modules/integration/integration-instance.controller.ts
@@ -20,10 +20,12 @@ import { InstanceExistsError, PluginInstanceService } from './plugin-instance.se
import { PluginInstance } from './entities/plugin-instance.entity';
import { buildIngressUrls } from './ingress-url';
import { CreateInstanceDto, InstanceView, UpdateInstanceDto } from './dto/instance.dto';
+import { ApiTags } from '@nestjs/swagger';
// ADMIN-only provisioning surface for per-plugin instances (e.g. one Chatwoot account). Only plugins
// that declare an ingress route AND the webhook:ingress permission can have instances; everything
// else is rejected before touching persistence.
+@ApiTags('integration')
@Controller('integration/plugins/:pluginId/instances')
@RequireRole(ApiKeyRole.ADMIN)
export class IntegrationInstanceController {
diff --git a/src/modules/integration/redrive.controller.ts b/src/modules/integration/redrive.controller.ts
index 6ba2a0386..cb00a1bcf 100644
--- a/src/modules/integration/redrive.controller.ts
+++ b/src/modules/integration/redrive.controller.ts
@@ -1,4 +1,5 @@
import { Controller, Param, Post } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
import { RequireRole } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
import { RedriveService } from './redrive.service';
@@ -6,6 +7,7 @@ import { RedriveService } from './redrive.service';
// Re-dispatching DLQ'd inbound payloads can cause real downstream sends, so this operator action is
// ADMIN-gated — matching the sibling IntegrationInstanceController. (A bare API key, even VIEWER,
// must NOT be able to trigger it.)
+@ApiTags('integration')
@Controller('integration/instances')
@RequireRole(ApiKeyRole.ADMIN)
export class RedriveController {
diff --git a/src/modules/stats/stats.controller.ts b/src/modules/stats/stats.controller.ts
index b6532be40..2e60436a6 100644
--- a/src/modules/stats/stats.controller.ts
+++ b/src/modules/stats/stats.controller.ts
@@ -5,7 +5,7 @@ import { StatsQueryDto } from './dto/stats-query.dto';
import { RequireRole } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
-@ApiTags('Statistics')
+@ApiTags('statistics')
@Controller('stats')
export class StatsController {
constructor(private readonly statsService: StatsService) {}
diff --git a/src/modules/status/status.controller.ts b/src/modules/status/status.controller.ts
index 76598be6e..127514dba 100644
--- a/src/modules/status/status.controller.ts
+++ b/src/modules/status/status.controller.ts
@@ -6,7 +6,7 @@ import { SendImageStatusDto, SendVideoStatusDto } from './dto/send-media-status.
import { RequireRole } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
-@ApiTags('Status')
+@ApiTags('status')
@Controller('sessions/:sessionId/status')
export class StatusController {
constructor(private readonly statusService: StatusService) {}