Skip to content
Development
Agent

dto-generator

Agent for generating NestJS DTOs with validation

From plugin
f5-framework
24104 skills104 agents69 commands

Claude Code

> /plugin marketplace add Fujigo-Software/f5-framework-claude

Agent definition

dto-generator.md
name: nestjs-dto-generator
description: Agent for generating NestJS DTOs with validation
applies_to: nestjs
category: agent

NestJS DTO Generator Agent

Purpose

Generate complete DTO sets (Create, Update, Query, Response) with proper validation decorators and Swagger documentation.

Input Requirements

required:
  - entity_name: string        # e.g., "user"
  - fields: array              # Field definitions

optional:
  - module_name: string        # Module path (defaults to entity_name + 's')
  - swagger: boolean           # Add Swagger decorators (default: true)
  - validation_groups: boolean # Add validation groups (default: false)
  - response_dto: boolean      # Generate response DTO (default: true)
  - query_dto: boolean         # Generate query DTO (default: true)

Field Definition Schema

fields:
  - name: string               # Field name
    type: string               # TypeScript type
    required: boolean          # Is required in create DTO
    validators: array          # Validation decorators
    swagger:                   # Swagger metadata
      description: string
      example: any
    create: boolean            # Include in create DTO (default: true)
    update: boolean            # Include in update DTO (default: true)
    response: boolean          # Include in response DTO (default: true)
    query: boolean             # Include as query filter (default: false)

Generation Process

Step 1: Parse Field Definitions

interface FieldDefinition {
  name: string;
  type: string;
  required: boolean;
  validators: string[];
  swagger: {
    description: string;
    example: any;
  };
  create: boolean;
  update: boolean;
  response: boolean;
  query: boolean;
}

const fields: FieldDefinition[] = [
  {
    name: 'email',
    type: 'string',
    required: true,
    validators: ['IsEmail', 'IsNotEmpty'],
    swagger: {
      description: 'User email address',
      example: 'user@example.com',
    },
    create: true,
    update: true,
    response: true,
    query: true,
  },
  {
    name: 'name',
    type: 'string',
    required: true,
    validators: ['IsString', 'MinLength(2)', 'MaxLength(100)'],
    swagger: {
      description: 'User full name',
      example: 'John Doe',
    },
    create: true,
    update: true,
    response: true,
    query: false,
  },
  // ... more fields
];

Step 2: Generate Create DTO

// modules/{{module}}/dto/create-{{entity}}.dto.ts
import {
  IsString,
  IsNotEmpty,
  IsOptional,
  IsEmail,
  IsUUID,
  IsInt,
  IsNumber,
  IsBoolean,
  IsEnum,
  IsArray,
  IsDate,
  MinLength,
  MaxLength,
  Min,
  Max,
  ValidateNested,
  ArrayMinSize,
  ArrayMaxSize,
  Matches,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class Create{{Entity}}Dto {
{{#each createFields}}
  {{#if required}}
  @ApiProperty({
    description: '{{swagger.description}}',
    example: {{swagger.example}},
  })
  {{#each validators}}
  @{{this}}
  {{/each}}
  {{name}}: {{type}};
  {{else}}
  @ApiPropertyOptional({
    description: '{{swagger.description}}',
    example: {{swagger.example}},
  })
  @IsOptional()
  {{#each validators}}
  @{{this}}
  {{/each}}
  {{name}}?: {{type}};
  {{/if}}

{{/each}}
}

Step 3: Generate Update DTO

// modules/{{module}}/dto/update-{{entity}}.dto.ts
import { PartialType } from '@nestjs/swagger';
import { Create{{Entity}}Dto } from './create-{{entity}}.dto';

export class Update{{Entity}}Dto extends PartialType(Create{{Entity}}Dto) {}

// Or with custom fields
import { OmitType, PartialType } from '@nestjs/swagger';
import { Create{{Entity}}Dto } from './create-{{entity}}.dto';

export class Update{{Entity}}Dto extends PartialType(
  OmitType(Create{{Entity}}Dto, ['{{immutableField}}'] as const),
) {
  // Additional update-only fields
}

Step 4: Generate Query DTO

// modules/{{module}}/dto/query-{{entity}}.dto.ts
import { IsOptional, IsInt, IsString, IsEnum, Min, Max } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiPropertyOptional } from '@nestjs/swagger';

export class Query{{Entity}}Dto {
  @ApiPropertyOptional({ default: 1, minimum: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page?: number = 1;

  @ApiPropertyOptional({ default: 10, minimum: 1, maximum: 100 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(100)
  limit?: number = 10;

  @ApiPropertyOptional({ description: 'Search term' })
  @IsOptional()
  @IsString()
  search?: string;

  @ApiPropertyOptional({ enum: ['asc', 'desc'], default: 'desc' })
  @IsOptional()
  @IsEnum(['asc', 'desc'])
  sortOrder?: 'asc' | 'desc' = 'desc';

  @ApiPropertyOptional({ default: 'createdAt' })
  @IsOptional()
  @IsString()
  sortBy?: string = 'createdAt';

{{#each queryFields}}
  @ApiPropertyOptional({ description: '{{swagger.description}}' })
  @IsOptional()
  {{#each validators}}
  @{{this}}
  {{/each}}
  {{name}}?: {{type}};

{{/each}}
}

Step 5: Generate Response DTO

// modules/{{module}}/dto/{{entity}}-response.dto.ts
import { Expose, Type, Exclude } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

@Exclude()
export class {{Entity}}ResponseDto {
  @Expose()
  @ApiProperty({ description: 'Unique identifier' })
  id: string;

{{#each responseFields}}
  @Expose()
  {{#if required}}
  @ApiProperty({
    description: '{{swagger.description}}',
    example: {{swagger.example}},
  })
  {{else}}
  @ApiPropertyOptional({
    description: '{{swagger.description}}',
    example: {{swagger.example}},
  })
  {{/if}}
  {{#if isNested}}
  @Type(() => {{nestedType}}ResponseDto)
  {{/if}}
  {{name}}{{#unless required}}?{{/unless}}: {{type}};

{{/each}}
  @Expose()
  @ApiProperty({ description: 'Creation timestamp' })
  createdAt: Date;

  @Expose()
Read more
@fujigo-software
Ships withf5-framework

AI-Powered Development Framework for Claude Code

2434 skills104 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
24
Star history of Fujigo-Software/f5-framework-claude on GitHub, a chart by star-history.com

Other agents on f5-framework.

More agents from other plugins.

a11y-architect
Auto-invoked

a11y-architect

Agent

Accessibility Architect specializing in WCAG 2.2 compliance for Web and Native platforms. Use PROACTIVELY when designing UI…

ecc13d293k
@affaan-m@affaan-mInstall Agent
analyze-pass-impact

analyze-pass-impact

Agent

Analyzes how a specific topic affects a group of compiler passes. Used by the /plan-update skill to parallelize research across…

react2d252k
@facebook@facebookInstall Agent
orchestrator

orchestrator

Agent

- If the user makes a simple request (such as asking for the time) which you can fulfill by running a terminal command (such as…

codex2d135k
@openai@openaiInstall Agent
cavecrew-builder

cavecrew-builder

Agent

Surgical 1-2 file edit. Typo fixes, single-function rewrites, mechanical renames, comment removal, format-preserving tweaks. Hard…

caveman3d119k
@juliusbrussee@juliusbrusseeInstall Agent

Questions about dto-generator.

Which coding agents can use dto-generator?
dto-generator installs in Claude Code and Cursor: each loads subagents from .claude/agents, so copy the file there. Flowy's auto-invocation runs in Claude Code only.