Skip to content

dto-generator

Agent for generating NestJS DTOs with validation

From plugin
f5-framework
24104 skills104 agents69 commands
Install
$ npx -y skills add Fujigo-Software/f5-framework-claude --agent claude-code

How it fires

How this agent gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.

Context preview

The summary Claude sees to decide when to auto-load this agent.

Agent for generating NestJS DTOs with validation

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
Ships withf5-framework

AI-Powered Development Framework for Claude Code

Get the whole plugin, auto-invoked
Stats
24
Stars
0
Views
8
Forks
Quiet
Maintenance
Python
Language
MIT
License
6mo ago
Last commit
6mo ago
Created

Repo: Fujigo-Software/f5-framework-claude