We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 // >> undefined
Joi strips non-enumerable properties of the object.
Unknown properties being allowed, the object should be returned unaffected. Own object properties should not be stripped from the returned value.
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.
The text was updated successfully, but these errors were encountered:
I don't have the chance to test it just now, but try adding .raw()
.raw()
From the source it looks like it should use the original object instead of a cloned and possibly-coerced one
Sorry, something went wrong.
Thanks. I’ll try this ; I’m not sure it will help my specific use-case as I rely on an extension to coerce an object to ORM model if needed though.
PR #1796 could solve this
de4d450
hueniverse
No branches or pull requests
Context
What are you trying to achieve or the steps to reproduce ?
Consider the following example code:
Which 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:
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:
The ORM-defined methods are stripped from the resulting value.
The text was updated successfully, but these errors were encountered: