Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supports validate nested DTO ✨ #18

Merged
merged 7 commits into from
Feb 11, 2022

Conversation

zhaoyiming0803
Copy link
Contributor

@zhaoyiming0803 zhaoyiming0803 commented Feb 10, 2022

Supports validate nested DTO:

import {
  IsString,
  IsNotEmpty,
  ValidateNested,
  IsNotEmptyObject,
} from 'class-validator';

class Args1 {
  // Each dto field must have a class validator 
  name: string;
}
export class CreateCityDto {
  @IsNotEmptyObject()
  @ValidateNested()
  args2: Args2;

  @IsNotEmptyObject()
  @ValidateNested()
  args1: Args1;
}

export class Args2 {
  // Each dto field must have a class validator 
  name: string;

  @ValidateNested()
  args3: Args3
}
 
class Args3 {
  // Each dto field must have a class validator
  name: string
  
  // There must be at least 2 class validators for a dto item with IsOptional
  @IsOptional()
  message: string
}

@zhaoyiming0803 zhaoyiming0803 added the enhancement New feature or request label Feb 11, 2022
@zhaoyiming0803 zhaoyiming0803 self-assigned this Feb 11, 2022
@zhaoyiming0803 zhaoyiming0803 merged commit 203c5a0 into master Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant