@@ -143,6 +143,13 @@ export class ValidationPipe implements PipeTransform<any> {
143143 if ( errors . length > 0 ) {
144144 throw await this . exceptionFactory ( errors ) ;
145145 }
146+
147+ if ( originalValue === undefined && originalEntity === '' ) {
148+ // Since SWC requires empty string for validation (to avoid an error),
149+ // a fallback is needed to revert to the original value (when undefined).
150+ // @see https://github.com/nestjs/nest/issues/14430
151+ return originalValue ;
152+ }
146153 if ( isPrimitive ) {
147154 // if the value is a primitive value and the validation process has been successfully completed
148155 // we have to revert the original value passed through the pipe
@@ -155,6 +162,7 @@ export class ValidationPipe implements PipeTransform<any> {
155162 // if the value was originally undefined or null, revert it back
156163 return originalValue ;
157164 }
165+
158166 // we check if the number of keys of the "validatorOptions" is higher than 1 (instead of 0)
159167 // because the "forbidUnknownValues" now fallbacks to "false" (in case it wasn't explicitly specified)
160168 const shouldTransformToPlain =
@@ -230,7 +238,7 @@ export class ValidationPipe implements PipeTransform<any> {
230238 ) {
231239 return { } as object ;
232240 }
233- // Builder like SWC require empty string to be returned instead of an empty object
241+ // SWC requires empty string to be returned instead of an empty object
234242 // when the value is nil and the metatype is not a class instance, but a plain object (enum, for example).
235243 // Otherwise, the error will be thrown.
236244 // @see https://github.com/nestjs/nest/issues/12680
0 commit comments