0

I create @ApiProperty() in Dto like this

export class UpdateMeassageDto {

@ApiProperty()

message: {

    hash: string;


    created_at: Date;


    updated_at: Date;
}

}

Then it got an empty result like this

https://i.stack.imgur.com/kYGP5.jpg

2 Answers2

0

try to define a new type as:

export class Message{

    @ApiProperty()
    hash: string;

    @ApiProperty()
    created_at: Date;

    @ApiProperty()
    updated_at: Date;
}

and update your DTO as follow:

export class UpdateMessageDto {

    @ApiProperty()
    message: Message
}

Andrea Mugnai
  • 311
  • 2
  • 9
0

You can do it in the following way

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;
}

ApiProperty is needed for each property. You can use $ref to use one DTO in another DTO. It will be good to use also class-validator in the DTOs.

CyberEternal
  • 2,259
  • 2
  • 12
  • 31