Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(api): publish the minimum length of a contact first name

Yudhi Armyndharis2770d73a2d16
diff --git a/src/modules/contact/dto/upsert-contact.dto.spec.ts b/src/modules/contact/dto/upsert-contact.dto.spec.ts
new file mode 100644
index 000000000..1f37b8796
--- /dev/null
+++ b/src/modules/contact/dto/upsert-contact.dto.spec.ts
@@ -0,0 +1,15 @@
+import { ADDRESSBOOK_NAME_MAX_LENGTH, UpsertContactDto } from './upsert-contact.dto';
+
+const property = (name: string) =>
+ Reflect.getMetadata('swagger/apiModelProperties', UpsertContactDto.prototype, name) as {
+ minLength?: number;
+ maxLength?: number;
+ };
+
+// The validator refuses an empty first name; the contract has to publish the same bound, or a
+// generated client accepts input the server then refuses.
+describe('UpsertContactDto contract', () => {
+ it('publishes the firstName length bounds the validator enforces', () => {
+ expect(property('firstName')).toMatchObject({ minLength: 1, maxLength: ADDRESSBOOK_NAME_MAX_LENGTH });
+ });
+});
diff --git a/src/modules/contact/dto/upsert-contact.dto.ts b/src/modules/contact/dto/upsert-contact.dto.ts
index f27342df0..180d34f0d 100644
--- a/src/modules/contact/dto/upsert-contact.dto.ts
+++ b/src/modules/contact/dto/upsert-contact.dto.ts
@@ -5,7 +5,7 @@ import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
export const ADDRESSBOOK_NAME_MAX_LENGTH = 100;
export class UpsertContactDto {
- @ApiProperty({ description: "The contact's first name.", maxLength: ADDRESSBOOK_NAME_MAX_LENGTH })
+ @ApiProperty({ description: "The contact's first name.", minLength: 1, maxLength: ADDRESSBOOK_NAME_MAX_LENGTH })
@IsString()
@MinLength(1)
@MaxLength(ADDRESSBOOK_NAME_MAX_LENGTH)