Skip to content

Commit

Permalink
We now only validate body, params, and query
Browse files Browse the repository at this point in the history
  • Loading branch information
iyobo committed May 1, 2021
1 parent 942cdc1 commit fa664d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/util/generateRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/util/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fa664d6

Please sign in to comment.