Careeroza
Documenting DTOs
@ApiProperty
src/products/dto/create-product.dto.ts
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsIn, IsInt, IsOptional, IsPositive, IsString, Length, Min } from 'class-validator';
export class CreateProductDto {
@ApiProperty({ example: 'boAt Airdopes 141', minLength: 3, maxLength: 120 })
@IsString() @Length(3, 120)
name: string;
@ApiPropertyOptional({ example: '42 hours playback, ENx noise cancellation' })
@IsOptional() @IsString()
description?: string;
@ApiProperty({ example: 1299, description: 'Price in rupees, GST included' })
@IsPositive()
price: number;
@ApiProperty({ example: 120, minimum: 0 })
@IsInt() @Min(0)
stock: number;
@ApiProperty({ enum: ['audio', 'mobiles', 'laptops', 'wearables', 'accessories'], example: 'audio' })
@IsIn(['audio', 'mobiles', 'laptops', 'wearables', 'accessories'])
category: string;
}
// update-product.dto.ts: import PartialType from @nestjs/swagger (not @nestjs/mapped-types)
// export class UpdateProductDto extends PartialType(CreateProductDto) {}