Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(api): publish the storage-import request body as a schema

Yudhi Armyndharisf7c8b445d4f7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 426915a38..5bb52ffb9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- `POST /api/infra/storage/import` now publishes its request body as a schema instead of `{"type":"string"}`. A description-only `@ApiBody` has nothing to infer the DTO from, so the contract told every generated client the body was a bare string while the handler took an object — the only one of the document's 83 JSON request bodies in that state, and `openapi:check` passed on it because the snapshot was self-consistent, just wrong. A gate now rejects any JSON request body published as a bare primitive.
+
- Baileys group metadata now uses the phone-dialect twins the payload already carries (`ownerPn`, `participants[].phoneNumber`). Reading only the LID left `owner` and `participants[].id` as `<lid>@lid`, made `number` the LID digits presented as a phone number, and reported `isAdmin: false` for groups the account actually administers — ids that then failed to join against the `@c.us` the same session's contacts and message webhooks emit for the same person. It was only correct once the lid→phone mapping had been learned; the twin is available immediately. Where WhatsApp withholds the twin, as it does for non-contacts, the previous behaviour stands.
- On the Baileys engine, `isBlocked` on a contact read is now the account's real blocklist state rather than a literal `false`. Nothing derived it, while the same session's `/contacts/blocked` endpoint returned the real ids — so automation that skips blocked contacts before sending messaged people the account had explicitly blocked. A blocklist query that fails leaves the field at its default and logs a warning rather than failing the contact read or selling a transport failure as "nobody is blocked". `isMyContact` is unchanged: Baileys has no addressbook signal to derive it from, and inventing one would repeat the mistake.
diff --git a/openapi.json b/openapi.json
index db461cb4d..97cbadc3d 100644
--- a/openapi.json
+++ b/openapi.json
@@ -4055,7 +4055,7 @@
"content": {
"application/json": {
"schema": {
- "type": "string"
+ "$ref": "#/components/schemas/ImportStorageDto"
}
}
}
@@ -12772,6 +12772,18 @@
"download"
]
},
+ "ImportStorageDto": {
+ "type": "object",
+ "properties": {
+ "filePath": {
+ "type": "string",
+ "description": "Path to the tar.gz file to import (must be inside the data directory)"
+ }
+ },
+ "required": [
+ "filePath"
+ ]
+ },
"StorageImportResponseDto": {
"type": "object",
"properties": {
diff --git a/src/config/openapi-contract.spec.ts b/src/config/openapi-contract.spec.ts
index 9b971e348..47d645d2a 100644
--- a/src/config/openapi-contract.spec.ts
+++ b/src/config/openapi-contract.spec.ts
@@ -212,3 +212,38 @@ describe('both OpenAPI producers apply the same passes', () => {
}
});
});
+
+/**
+ * A request body must publish a SCHEMA, not a primitive.
+ *
+ * `@ApiBody({ description })` with no `type:` publishes `{"type":"string"}` — the decorator has no
+ * way to infer the DTO — so the published contract told every generated client the body was a bare
+ * string while the handler took an object. `openapi:check` passes on it happily: the snapshot is
+ * self-consistent, just wrong. One of the document's application/json bodies was in that state.
+ */
+describe('every JSON request body publishes an object schema', () => {
+ const jsonBodies = (): Array<{ op: string; schema: Record<string, unknown> }> => {
+ const out: Array<{ op: string; schema: Record<string, unknown> }> = [];
+ for (const [path, item] of Object.entries(snapshot().paths as unknown as Record<string, Record<string, unknown>>)) {
+ for (const [method, op] of Object.entries(item)) {
+ const body = (op as { requestBody?: { content?: Record<string, { schema?: Record<string, unknown> }> } })
+ .requestBody;
+ const schema = body?.content?.['application/json']?.schema;
+ if (schema) out.push({ op: `${method.toUpperCase()} ${path}`, schema });
+ }
+ }
+ return out;
+ };
+
+ // Guards the assertion below: an extractor that found nothing would pass it vacuously.
+ it('finds the document’s JSON request bodies', () => {
+ expect(jsonBodies().length).toBeGreaterThan(50);
+ });
+
+ it('publishes none of them as a bare primitive', () => {
+ const primitives = jsonBodies()
+ .filter(({ schema }) => !schema.$ref && !schema.properties && schema.type !== 'object')
+ .map(({ op, schema }) => `${op} -> ${JSON.stringify(schema)}`);
+ expect(primitives).toEqual([]);
+ });
+});
diff --git a/src/modules/infra/infra-storage.controller.ts b/src/modules/infra/infra-storage.controller.ts
index c5b2d3806..397b12082 100644
--- a/src/modules/infra/infra-storage.controller.ts
+++ b/src/modules/infra/infra-storage.controller.ts
@@ -191,7 +191,10 @@ export class InfraStorageController implements OnApplicationBootstrap {
@HttpCode(HttpStatus.OK)
@RequireRole(ApiKeyRole.ADMIN)
@ApiOperation({ summary: 'Import storage files from tar.gz' })
- @ApiBody({ description: 'Path to tar.gz file to import' })
+ // `type:` is required, not decoration: a description-only @ApiBody has nothing to infer the DTO
+ // from and publishes `{"type":"string"}`, telling every generated client the body is a bare
+ // string while the handler takes an object.
+ @ApiBody({ type: ImportStorageDto, description: 'Path to tar.gz file to import' })
@ApiResponse({ status: 200, description: 'Import result', type: StorageImportResponseDto })
async importStorage(
@Body() body: ImportStorageDto,