-
Notifications
You must be signed in to change notification settings - Fork 23
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
IsOptional() not work #55
Comments
@summivar You should also consider that you are using the wrong file type in your dto, class-validator/class-transformer uses this too. If you don't find the problem, please create a repository to reproduce the problem and it will be fixed. |
@dmitriy-nz i have the same issue with the latest version. My code: /**
* appending files
*/
@Expose()
@Transform(({ value }) => {
return value !== undefined && !Array.isArray(value) ? [value] : value;
})
@IsFiles()
@HasMimeType(['image/jpg', 'image/png', 'application/json', 'text/plain', 'application/xml'])
@IsOptional()
appending?: FileHashStorage[]; Event if it's optional the mimetypes are validated as invalid. Same with "IsFiles". I think it only happens if you have an array of files. |
I have the same issue.
IsOptional doesn't work on an array of files. The user is forced to upload at least one file. Does someone has a solution please ? |
@summivar @julianpoemp @TidianeRolland Hi! Issue has been reproduced in fixed in the v1.9.9 version, please try it out |
@dmitriy-nz still not working for me with v1.9.9 @Expose()
@IsOptional()
@IsFiles()
appending?: FileHashStorage[]; appending should be optional, but I still get an error if no files appended. |
@julianpoemp can you share your ValidationPipe options? |
|
@julianpoemp if you are like me and testing the apis on postman make sure you uncheck the field in the postman in your case you need to uncheck appending. |
- Added test cases for `Exposed` decorated fields
Thank everyone for the feedback, your case has been reproduced, the issue was that when a property is decorated with |
@dmitriy-nz it's working, thank you! 🎉 |
export class EditDto {
@ApiProperty({ description: 'Имя услуги', example: 'Имя', required: false })
@IsString()
@IsOptional()
name: string;
@ApiProperty({ description: 'Описание услуги', example: 'Описание', required: false })
@IsString()
@IsOptional()
description: string;
@ApiProperty({
type: 'string',
format: 'binary',
description: 'Картинка услуги',
name: 'image',
required: false
})
@IsFile()
@MaxFileSize(1e7, { message: 'File size should not exceed 10MB' })
@HasMimeType(['image/jpeg', 'image/png'], { message: 'File should be a JPEG or PNG image' })
@IsOptional()
image?: Express.Multer.File;
}
return from server:
{
"statusCode": 400,
"message": "Validation error",
"errors": [
{
"field": "image",
"error": "File should be a JPEG or PNG image, File size should not exceed 10MB, Field "image" does not contain file"
}
]
}
I want to create "UpdateDTO" and don't know how to do this "IsFile" optional
The text was updated successfully, but these errors were encountered: