-
Notifications
You must be signed in to change notification settings - Fork 837
Closed
Labels
type: questionQuestions about the usage of the library.Questions about the usage of the library.
Description
Hi,
Validation for array of custom objects does not seem to work.
Versions:
class-transformer0.2.3
class-validator: 0.9.1
My objects:
questions.ts
export class QuestionsDto {
@IsNotEmpty()
@IsString()
applicationId: string;
@IsArray()
@ValidateNested({each: true})
@Type(() => QuestionDto)
@ArrayMinSize(1)
questions: QuestionDto[];
}
question.ts
export class QuestionDto {
private static ALLOWED_QUESTION_TYPES = ['mcq', 'text', 'date'];
@IsNotEmpty()
@IsString()
@IsIn(QuestionDto.ALLOWED_QUESTION_TYPES)
type: string;
@IsNotEmpty()
@IsString()
designation: string;
@IsNotEmpty()
@IsString()
reason: string;
@IsOptional()
@IsArray()
extraContent: string[];
}
Use case:
const q = {
applicationId: 'aaa',
questions: ['aaa']
}
const errors = validate(QuestionsDto, q)
console.log(errors.length) // 0
Thanks by advance :)
joseym and aqelkp
Metadata
Metadata
Assignees
Labels
type: questionQuestions about the usage of the library.Questions about the usage of the library.