@@ -143,6 +143,13 @@ export class ValidationPipe implements PipeTransform<any> {
143
143
if ( errors . length > 0 ) {
144
144
throw await this . exceptionFactory ( errors ) ;
145
145
}
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
+ }
146
153
if ( isPrimitive ) {
147
154
// if the value is a primitive value and the validation process has been successfully completed
148
155
// we have to revert the original value passed through the pipe
@@ -155,6 +162,7 @@ export class ValidationPipe implements PipeTransform<any> {
155
162
// if the value was originally undefined or null, revert it back
156
163
return originalValue ;
157
164
}
165
+
158
166
// we check if the number of keys of the "validatorOptions" is higher than 1 (instead of 0)
159
167
// because the "forbidUnknownValues" now fallbacks to "false" (in case it wasn't explicitly specified)
160
168
const shouldTransformToPlain =
@@ -230,7 +238,7 @@ export class ValidationPipe implements PipeTransform<any> {
230
238
) {
231
239
return { } as object ;
232
240
}
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
234
242
// when the value is nil and the metatype is not a class instance, but a plain object (enum, for example).
235
243
// Otherwise, the error will be thrown.
236
244
// @see https://github.com/nestjs/nest/issues/12680
0 commit comments