Here is a way to achieve it:
import { ApiProperty, getSchemaPath } from '@nestjs/swagger';
export class MessageDto {
@ApiProperty({
type: 'string',
example: 'hx1231',
})
hash: string;
@ApiProperty({
type: 'date',
example: '2021-08-04T19:39:00.829Z',
})
created_at: Date;
@ApiProperty({
type: 'string',
format: 'date-time',
example: '2021-08-04T19:39:00.829Z',
})
updated_at: Date;
}
export class UpdateMessageDto {
@ApiProperty({
type: 'array',
items: { $ref: getSchemaPath(MessageDto) },
})
message: MessageDto;
}
Each property requires an ApiProperty. The use of $ref allows for the reuse of one DTO within another DTO. Additionally, consider integrating class-validator into the DTOs for enhanced functionality.