-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Context
Validating an object against my schema throws node.get or node.set is not a function when I expect keys to be stripped instead.
- node version: 10.16.0 and 12.8.1
- joi version: 16.1.4
- environment (node, browser): node
- used with (hapi, standalone, ...): hapi
- any other relevant information:
What are you trying to achieve or the steps to reproduce ?
I am trying to write a validation that strips out items that do not pass the set validation. See below for more details.
Create the following scenario
const Joi = require("@hapi/joi");
const A = Joi.object().keys({z: Joi.date().iso().required()})
const B = Joi.object().keys({a: Joi.array().min(1).items(A, Joi.any().strip()).required()});
const schema = Joi.object().keys({data: Joi.object().keys({b: Joi.array().items(B, Joi.any().strip()).min(1).required()}).required()});
const toValidate1 = {data: {b: [{a: []}, {a: [{x: new Date()}]}]}}
const toValidate2 = {data: {b: [{a: []}, {a: [{z: new Date()}]}]}}
const toValidate3 = {data: {b: [{a: []}, {a: [{x: new Date()}]}, {a: [{z: new Date()}]}]}}
Joi.assert(toValidate1, schema) // throws node.get is not defined
Joi.assert(toValidate2, schema) // ok
Joi.assert(toValidate3, schema) // throws node.get is not definedWhich result you had ?
Error thrown for cases 1 and 3.
Thrown:
TypeError: node.get is not a function
at internals.Shadow.set <path>/node_modules/@hapi/joi/lib/validator.js:700:29)
at Object.internals.finalize (<path>/node_modules/@hapi/joi/lib/validator.js:598:31)
at Object.exports.validate (<path>/node_modules/@hapi/joi/lib/validator.js:391:26)
at internals.Base.$_validate (<path>/node_modules/@hapi/joi/lib/base.js:747:26)
at Object.validate (<path>/node_modules/@hapi/joi/lib/types/array.js:315:45)
at Object.internals.rules (<path>/node_modules/@hapi/joi/lib/validator.js:443:33)
at Object.exports.validate (<path>/node_modules/@hapi/joi/lib/validator.js:395:22)
at internals.Base.$_validate (<path>/node_modules/@hapi/joi/lib/base.js:747:26)
at Object.validate (<path>/node_modules/@hapi/joi/lib/types/keys.js:107:45)
at Object.exports.validate (<path>/node_modules/@hapi/joi/lib/validator.js:369:26)
What did you expect ?
Expect the item to be stripped (if my usage is correct) otherwise an error from Joi explaining why the assertion failed.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect