-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
featureNew functionality or improvementNew functionality or improvement
Milestone
Description
Context
- node version: 11.5.0
- joi version: 10.6.0
- environment (node, browser): node
- used with (hapi, standalone, ...): standalone
What are you trying to achieve or the steps to reproduce ?
Consider the following example code:
const joi = require('joi');
const obj = {foo: 'bar'};
Object.defineProperty(obj, 'test', { value: 42, enumerable: false });
joi.validate(obj, joi.object().keys({}).unknown()).value
// >> { foo: 'bar' }
joi.validate(obj, joi.object().keys({}).unknown()).value.test
// >> undefinedWhich result you had ?
Joi strips non-enumerable properties of the object.
What did you expect ?
Unknown properties being allowed, the object should be returned unaffected. Own object properties should not be stripped from the returned value.
Use-case
I do have a validator that takes an object, and validates that one of its values is an ORM model:
Joi.object().type(MyModel)This works fine. The ORM defines on the model a few methods, that are not enumerable, and these are kept at this point.
If, however, I try to validate one of the values of a model instance:
Joi.object().type(MyModel).keys({ something: Joi.string() }).unknown()The ORM-defined methods are stripped from the resulting value.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureNew functionality or improvementNew functionality or improvement