Merge pull request #11028 from nestjs/chore/forbid-unknown-values-validation-pipe

chore(common): set forbid unknown values to false by default
This commit is contained in:
Kamil Mysliwiec
2023-02-03 12:01:45 +01:00
committed by GitHub
2 changed files with 6 additions and 4 deletions

View File

@@ -66,8 +66,10 @@ export class ValidationPipe implements PipeTransform<any> {
...validatorOptions
} = options;
// @see https://github.com/nestjs/nest/issues/10683#issuecomment-1413690508
this.validatorOptions = { forbidUnknownValues: false, ...validatorOptions };
this.isTransformEnabled = !!transform;
this.validatorOptions = validatorOptions;
this.transformOptions = transformOptions;
this.isDetailedOutputDisabled = disableErrorMessages;
this.validateCustomDecorators = validateCustomDecorators || false;

View File

@@ -384,7 +384,7 @@ describe('ValidationPipe', () => {
});
describe('otherwise', () => {
it('should not reject', async () => {
target = new ValidationPipe({ forbidUnknownValues: false });
target = new ValidationPipe();
const testObj = [
{ prop1: 'value1', prop2: 'value2', prop3: 'value3' },
];
@@ -447,7 +447,7 @@ describe('ValidationPipe', () => {
target = new ValidationPipe({ expectedType: TestModel });
const testObj = { prop1: 'value1', prop2: 'value2' };
expect(await target.transform(testObj, m)).to.equal(testObj);
expect(await target.transform(testObj, m)).to.deep.equal(testObj);
});
it('should validate against the expected type if presented and metatype is primitive type', async () => {
@@ -460,7 +460,7 @@ describe('ValidationPipe', () => {
target = new ValidationPipe({ expectedType: TestModel });
const testObj = { prop1: 'value1', prop2: 'value2' };
expect(await target.transform(testObj, m)).to.equal(testObj);
expect(await target.transform(testObj, m)).to.deep.equal(testObj);
});
});
});