nestjs-typebox
Version:
This library provides helper utilities for writing and validating NestJS APIs using [TypeBox](https://github.com/sinclairzx81/typebox) as an alternative to class-validator/class-transformer. It also includes a patch for @nestjs/swagger allowing OpenAPI ge
18 lines (13 loc) • 467 B
text/typescript
import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common';
import { isTypeboxDto } from './util';
()
export class TypeboxValidationPipe implements PipeTransform {
public transform(value: unknown, metadata: ArgumentMetadata) {
const { metatype } = metadata;
if (!isTypeboxDto(metatype)) {
return value;
}
metatype.validate(metatype.beforeValidate(value));
return value;
}
}