Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/generator/dto-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ export class DtoGenerator {
if (schema.format === 'email') {
decorators.push('@IsEmail()');
}

if (schema.format === 'uuid') {
decorators.push('@IsUUID()');
}

if (schema.format === 'date') {
decorators.push('@IsDateString()');
}

if (schema.format === 'date-time') {
decorators.push('@IsDateTimeString()');
}

if (schema.enum) {
const enumName = this.getEnumName(name, schema.enum);
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/user.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ components:
example: "Doe"
minLength: 1
maxLength: 50
dateOfBirth:
type: string
format: date
description: User's date of birth
example: "2001-04-26"
age:
type: integer
description: User's age
Expand Down
3 changes: 3 additions & 0 deletions tests/generator/dto-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ describe('DtoGenerator', () => {
// Email validation
expect(result).toContain('@IsString()');
expect(result).toContain('@IsEmail()');
expect(result).toContain('@IsUUID()');
expect(result).toContain('@IsDateString()');
expect(result).toContain('@IsDateTimeString()');

// String length validation
expect(result).toContain('@MinLength(1)');
Expand Down