Joi: New option to allow unknown key but remove it by `validate`

Created on 29 Jun 2016  路  3Comments  路  Source: sideway/joi

Context

  • _node version_: 6.2.0
  • _joi version_: 8.0.1
  • _environment_ (node, browser): node
  • _used with_ (hapi, standalone, ...): standalone
  • _any other relevant information_:

    What are you trying to achieve or the steps to reproduce ?

I hope that joi provide a new option of unknown to allow unknown attributes but remove it in the result.

const schema = Joi.object({
  a: joi.string()
}).unknown()
schema.validate({a:'1', b: '1'}, (err, result) => {
  // result = {a: '1', b: '1'}
})

Which result you had ?

the function validate will leave the unknown attributes in the object.

What did you expect ?

A new option of unknown to allow unknown key but remove it in the result

feature

Most helpful comment

You can already do that with .options({ stripUnknown: true }). Be aware it propagates to children schemas in case you have objects or arrays inside.

All 3 comments

You can already do that with .options({ stripUnknown: true }). Be aware it propagates to children schemas in case you have objects or arrays inside.

@Marsup,

It works for me with this option, for instance I don't need the isolation in different hierarchy. Thank you very much. I will close this issue.

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Taxi4you picture Taxi4you  路  3Comments

builtbybrayne picture builtbybrayne  路  4Comments

JbIPS picture JbIPS  路  4Comments

farwayer picture farwayer  路  3Comments

REBELinBLUE picture REBELinBLUE  路  3Comments