From fa664d668fa71602d0cd18906cc9964601f1922c Mon Sep 17 00:00:00 2001 From: iyobo Date: Sat, 1 May 2021 11:06:15 -0500 Subject: [PATCH] We now only validate body, params, and query --- src/util/generateRoutes.ts | 6 ++++-- src/util/tools.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/generateRoutes.ts b/src/util/generateRoutes.ts index da254a8..7b4a124 100644 --- a/src/util/generateRoutes.ts +++ b/src/util/generateRoutes.ts @@ -87,8 +87,10 @@ async function _determineArgument( //TODO: implement custom function capability here for arg injectors } - // validate if this is a class. If it is a class, validate it - if (values && isClass(type)) { + // validate if this is a class and if this is a body, params, or query injection + const shouldValidate = values && isClass(type) && ['body','params','query'].includes(injectSource) + + if (shouldValidate) { values = await plainToClass(type, values); const errors = await validate(values, options.validatorOptions); // TODO: wrap around this to trap runtime errors diff --git a/src/util/tools.ts b/src/util/tools.ts index 466cf72..a71b500 100644 --- a/src/util/tools.ts +++ b/src/util/tools.ts @@ -2,7 +2,7 @@ import {metadata} from '../index'; import {ValidationDecoratorOptions} from '../decorators'; export function isClass(type) { - return type?.prototype?.constructor; + return type?.prototype?.constructor && type?.prototype?.constructor?.name !== 'Object'; } interface AddArgumentProps {