Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(auth): fix the keyPrefix length and nullable expiresAt in OpenAPI
Yudhi Armyndharisd5d380af1ccb
diff --git a/src/modules/auth/dto/api-key.dto.spec.ts b/src/modules/auth/dto/api-key.dto.spec.tsnew file mode 100644index 000000000..b4267c307--- /dev/null+++ b/src/modules/auth/dto/api-key.dto.spec.ts@@ -0,0 +1,32 @@+import 'reflect-metadata';+import { plainToInstance } from 'class-transformer';+import { validate } from 'class-validator';+import type { Repository } from 'typeorm';+import { ApiKeyResponseDto, UpdateApiKeyDto } from './api-key.dto';+import { AuthService } from '../auth.service';+import type { ApiKey } from '../entities/api-key.entity';+import type { ApiKeyUsageTracker } from '../api-key-usage-tracker.service';++const property = (dto: object, name: string) =>+ Reflect.getMetadata('swagger/apiModelProperties', dto, name) as { description?: string; nullable?: boolean };++describe('API key DTO contract', () => {+ it('describes keyPrefix with the length the service stores', async () => {+ const repository = { create: (row: ApiKey) => row, save: (row: ApiKey) => Promise.resolve(row) };+ const service = new AuthService(repository as unknown as Repository<ApiKey>, {} as ApiKeyUsageTracker, {} as never);+ const { apiKey } = await service.createApiKey({ name: 'probe' });++ expect(property(ApiKeyResponseDto.prototype, 'keyPrefix').description).toContain(+ `First ${apiKey.keyPrefix.length} characters`,+ );+ });++ it('declares null as the way to clear expiresAt, the only empty value validation accepts', async () => {+ expect(property(UpdateApiKeyDto.prototype, 'expiresAt').nullable).toBe(true);++ const errors = async (expiresAt: unknown) =>+ (await validate(plainToInstance(UpdateApiKeyDto, { expiresAt }))).map(error => error.property);+ expect(await errors(null)).toEqual([]);+ expect(await errors('')).toEqual(['expiresAt']);+ });+});diff --git a/src/modules/auth/dto/api-key.dto.ts b/src/modules/auth/dto/api-key.dto.tsindex d2266fd0e..193fb8e6e 100644--- a/src/modules/auth/dto/api-key.dto.ts+++ b/src/modules/auth/dto/api-key.dto.ts@@ -90,7 +90,7 @@ export class ApiKeyResponseDto {name!: string;@ApiProperty({- description: 'First 8 characters of the key (for identification)',+ description: 'First 12 characters of the key (for identification)',})keyPrefix!: string;@@ -181,8 +181,12 @@ export class UpdateApiKeyDto {@Validate(IsChatIdConstraint, { each: true })allowedChats?: string[];- @ApiPropertyOptional()+ @ApiPropertyOptional({+ type: String,+ nullable: true,+ description: 'Expiration date (ISO 8601); null clears it (an empty string is rejected)',+ })@IsOptional()@IsDateString()- expiresAt?: string;+ expiresAt?: string | null;}