application/json
in following format:title
- required, max length - 80 chars.
description
- optional, max length - 255 chars.querystring
and body
validation.@Data()
- set DTO for handling body
@Query()
- set DTO for handling querystring
@IsOptional()
- set field optional (by default, all fields are required)
@Const(value: any)
- field is valid if it is deeply equal to the passed value
@Deafault(value: any)
- default value for field, if it not exists
@Enum(enumrable: any[])
- data is valid if it is deeply equal to one of items in the array
@Nested()
- validate nested DTO class, otherwise field will be ignored
@Nested
should be applied on field, which type is DTO class.@MaxLength(maxLength: number)
- data to be valid should have length satisfying this rule
@MinLength(minLength: number)
- data to be valid should have length satisfying this rule
@Pattern(pattern: string | RegExp)
- data to be valid should match the regular expression
@Format(format: ValidatorFormat)
- data to be valid should match the format
@IsEmail()
- data to be valid should be email (Format
alias)
@IsUrl()
- data to be valid should be url (Format
alias)@Format
decorator available:@Maximum(maximum: number)
- data to be valid should be <=
maximum
@Minimum(minimum: number)
- data to be valid should be >=
minumum
@ExclusiveMaximum(exclusiveMaximum: number)
- data to be valid should be <
maximum@ExclusiveMinimum(exclusiveMinimum: number)
- data to be valid should be >
minimum
@MultipleOf(multipleOf: number)
- data to be valid should be a multiple of the multipleOf
@ArrayOf(targetClass: any)
- sets type of array items
@UniqueItems()
- array to be valid should have unique items
@MaxItems(maxItems: number)
- array to be valid should not have less items than the maxItems
@MinItems(minItems: number)
- array to be valid should not have more items than the minItems
@ArraoyOf
can be used only if array item type is another DTO class. As typescript does not provide reflection for complex types, type should be setted manually.@CustomValidation(validate: ValidateFunction, params: any = true)
- define custom validation function for field. Validate function can be async.@ArraoyOf
decorator for DTOs arrays.(extends)
for DTOs.TodoDTO
will inherit all properties from base class for both transformation and validation purposes.