nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
68.21k stars 7.67k forks source link

I can't get Validation error messages from nested object #4415

Closed rrdlpl closed 4 years ago

rrdlpl commented 4 years ago

Bug Report

I am using the validation pipe and somehow I'm not able to get the validation error message when this validation fails.

Current behavior

I get the following response from my endpoint when I call it with an invalid payload.

{
    "statusCode": 400,
    "message": [],
    "error": "Bad Request"
}

Input Code

export class BookAppointmentDto {
  @IsDefined()
  @ApiProperty()
  @ValidateNested()
  @Type(() => ContactDetailsDto)
  public contactDetails: ContactDetailsDto;
  @IsDefined()
  @ApiProperty()
  public appointment: AppointmentSlotDto;
}

export class ContactDetailsDto implements ContactDetails {
  @IsString()
  @IsNotEmpty()
  @ApiProperty()
  public firstName: string;
  @IsString()
  @IsNotEmpty()
  @ApiProperty()
  public lastName: string;
  @IsString()
  @IsOptional()
  @ApiProperty()
  public name?: string;
  @IsEmail()
  @IsNotEmpty()
  @ApiProperty()
  public email: string;
  @IsString()
  @IsOptional()
  @ApiProperty()
  public phoneNumber?: string;
  @IsString()
  @IsOptional()
  @ApiProperty()
  public nationality?: string;
  @IsEnum(Visa)
  @IsOptional()
  @ApiProperty()
  public visa?: Visa;
  @IsString()
  @IsOptional()
  @ApiProperty()
  public birthday?: string;
  @IsEnum(OccupationStatus)
  @IsOptional()
  @ApiProperty()
  public employment?: OccupationStatus;
  @IsBoolean()
  @IsOptional()
  @ApiProperty()
  public englishSpeaker?: boolean;
  @IsString()
  @IsOptional()
  @ApiProperty()
  public interest?: Interest;
  @IsString()
  @IsOptional()
  @ApiProperty()
  public message?: string;
}

export class AppointmentSlotDto {
  @IsString()
  @IsNotEmpty()
  @ApiProperty()
  public start: string;
  @IsString()
  @IsNotEmpty()
  @ApiProperty()
  public end: string;
}

My Controller

@Post('/')
  public async bookAppointment(
    @Req() request: Request,
    @Body() payload: BookAppointmentDto
  ): Promise<any> {
     ...
}

Expected behavior

Environment

Nest version: 7.0.5

For Tooling issues:

kamilmysliwiec commented 4 years ago

We're tracking this here https://github.com/nestjs/nest/pull/4360

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.